Skip to content

Commit

Permalink
Add user orders route
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSkrobis committed Feb 6, 2018
1 parent 2fa66ec commit 9525722
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 69 deletions.
15 changes: 10 additions & 5 deletions app/components/order-item/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<p>
z dnia {{moment-format model.createdAt 'DD-MM-YYYY HH:mm'}}<br>
Status: {{model.status}}<br>
{{#unless isUser}}
Klient: {{user.firstName}} {{user.lastName}}<br>
Adres: {{user.addressLine1}}, {{user.addressLine2}}
{{/unless}}
</p>
{{/text.subhead}}
{{paper-divider}}
Expand All @@ -16,11 +18,14 @@
{{/card.title}}
{{#paper-list}}

{{#link-to "admin.orders.edit" model.id}}
{{#paper-button data-test-categories-new-link raised=true primary=true}}
Edytuj
{{/paper-button}}
{{/link-to}}
{{#unless isUser}}
{{#link-to "admin.orders.edit" model.id}}
{{#paper-button data-test-categories-new-link raised=true primary=true}}
Edytuj
{{/paper-button}}
{{/link-to}}
{{/unless}}

{{#paper-subheader}}Produkty{{/paper-subheader}}
{{#each model.orderLines as |line|}}
{{#paper-item class="md-3-line"}}
Expand Down
4 changes: 0 additions & 4 deletions app/components/payment-page/component.js

This file was deleted.

1 change: 0 additions & 1 deletion app/components/payment-page/template.hbs

This file was deleted.

34 changes: 18 additions & 16 deletions app/components/shopping-cart/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,24 @@ export default Component.extend({
},

saveTransferOrder() {
let order = this.get('model.firstObject');
order.setProperties({
discount: this.get('discount'),
total: this.get('totalWithShipping'),
courier: this.get('selectedShippingOption'),
priceAfterDiscount: this.get('totalWithShippingAfterDiscount'),
status: 'Niezrealizowane',
paymentMethod: 'transfer'
});
order
.save()
.then(() => {
this.get('router').transitionTo('users.edit');
})
.catch(err => {
});
this.get('shoppingCart').saveTransferOrder();
// let order = this.get('model.firstObject');
// order.setProperties({
// discount: this.get('discount'),
// total: this.get('totalWithShipping'),
// courier: this.get('selectedShippingOption'),
// priceAfterDiscount: this.get('totalWithShippingAfterDiscount'),
// status: 'Niezrealizowane',
// paymentMethod: 'transfer'
// });
// order
// .save()
// .then(() => {
// _this.set('order', _this.getCartOrder(_this.get('currentUser.user.id')));
// this.get('router').transitionTo('users.edit');
// })
// .catch(err => {
// });
},

savePayUOrder() {
Expand Down
4 changes: 1 addition & 3 deletions app/components/shopping-cart/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
{{/paper-radio-group}}
<h4> Suma: {{totalWithShipping}} zł </h4>
<h3> Do zapłaty (ze znizką): {{totalWithShippingAfterDiscount}} zł </h3>
{{#paper-button raised=true disabled=orderCorrect onClick=(action 'savePayUOrder')}}
Przejdź do strony płatności (PayU) {{/paper-button}}
{{#paper-button raised=true disabled=orderCorrect onClick=(action 'saveTransferOrder')}}
Złóz zamówienie z obowiązkiem zapłaty przelewem {{/paper-button}}
{{else}}
{{!-- <p>Twój koszyk jest pusty!</p> --}}

{{/if}}
2 changes: 1 addition & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ApplicationRouter.map(function() {
this.route('users', function() {
this.route('edit');
this.route('new');
this.route('orders', { path: '/:user_id/orders' });
});
this.route('messages', function() {
this.route('new', { path: '/new' });
Expand All @@ -46,7 +47,6 @@ ApplicationRouter.map(function() {
this.route('new', { path: '/:message_id/new' });
});
});
this.route('payment');
this.route('preferred-products', { path: 'preferred-products/:user_id/' });
});

Expand Down
8 changes: 0 additions & 8 deletions app/routes/payment.js

This file was deleted.

16 changes: 16 additions & 0 deletions app/routes/users/orders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Ember from 'ember';

export default Ember.Route.extend({
model(params) {
let userId = params.user_id;
return this.store.query('order', {
reload: true,
filter: {
notCart: {
userId
}
},
include: 'order-lines.product'
});
}
});
22 changes: 22 additions & 0 deletions app/services/shopping-cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
export default Service.extend({
currentUser: service(),
store: service(),
router: service(),
inCartCount() {
let orderLinesLength = this.get('order.firstObject.orderLines.content.length');
if (orderLinesLength) {
Expand Down Expand Up @@ -52,6 +53,27 @@ export default Service.extend({
this.set('order', this.getCartOrder(this.get('currentUser.user.id')));
},

saveTransferOrder() {
let _this = this;
let order = this.get('order.firstObject');
order.setProperties({
discount: this.get('discount'),
total: this.get('totalWithShipping'),
courier: this.get('selectedShippingOption'),
priceAfterDiscount: this.get('totalWithShippingAfterDiscount'),
status: 'Niezrealizowane',
paymentMethod: 'transfer'
});
order
.save()
.then(() => {
_this.set('order', _this.getCartOrder(_this.get('currentUser.user.id')));
_this.get('router').transitionTo('users.edit');
})
.catch(err => {
});
},

addOrderLine(product, count, size) {
let _this = this;
this.get('store').createRecord('orderLine', {
Expand Down
5 changes: 5 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
@import "language-select";
@import "product-show";

.body-main {
margin-left: 10px;
margin-right: 10px
}

#user-greeting {
font-size: 14px
}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/admin/orders/index.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{outlet}}
{{!-- {{outlet}} --}}
<h1>Zamówienia</h1>
{{#each model as |order|}}
{{order-item model=order}}
Expand Down
6 changes: 4 additions & 2 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
{{/unless}}
{{/if}}
{{#paper-button}}
{{link-to 'Wyślij wiadomość' 'messages.new'}}
{{link-to 'Kontakt' 'messages.new'}}
{{/paper-button}}
{{!-- {{language-select}} --}}
{{/paper-toolbar-tools}}
{{/paper-toolbar}}

{{application-toast}}
{{outlet}}
<div class="body-main">
{{outlet}}
</div>
16 changes: 14 additions & 2 deletions app/templates/messages/new.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
<h1>{{t 'product.newPageHeader'}}</h1>
{{message-box model=model}}
{{message-box model=model}}

<h2>
Dane kontaktowe
</h2>
<p>
<b>BSC</b><br>
Adres: Mateusz Skrobiś<br>
ul. Krzywa 3/14<br>
43-402 Bielsko-Biała<br>
NIP: <b>420459131234</b><br>
REGON: <b>31321412423</b><br>
Konto bankowe: <b> MSBC 10 2394 2913 9313 0149 4342 0234</b><br>
</p>
23 changes: 13 additions & 10 deletions app/templates/users/edit.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{{outlet}}
{{#link-to "preference-form" model.id}}
{{#paper-button raised=true primary=true}} Formularz preferencji {{/paper-button}}
{{/link-to}}
{{#unless model.isAdmin}}
{{#link-to "preference-form" model.id}}
{{#paper-button raised=true primary=true}} Formularz preferencji {{/paper-button}}
{{/link-to}}

{{#if model.userHasPreferences}}
{{#link-to 'preferred-products' model.id}}
{{#paper-button raised=true primary=true}} Polecane produkty {{/paper-button}}
{{/link-to}}
{{/if}}

{{#if model.userHasPreferences}}
{{#unless model.isAdmin}}
{{#link-to 'preferred-products' model.id}}
{{#paper-button raised=true primary=true}} Polecane produkty {{/paper-button}}
{{#link-to 'users.orders' model.id}}
{{#paper-button raised=true primary=true}} Twoje zamówienia {{/paper-button}}
{{/link-to}}
{{/unless}}
{{/if}}
{{/unless}}

<h1>Twoje dane</h1>

Expand Down
9 changes: 9 additions & 0 deletions app/templates/users/orders.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{#link-to 'users.edit'}}
{{#paper-button raised=true primary=true}}Wróć {{/paper-button}}
{{/link-to}}

<h1>Twoje zamówienia</h1>

{{#each model as |order|}}
{{order-item model=order isUser=true}}
{{/each}}
16 changes: 0 additions & 16 deletions tests/integration/components/user-form/component-test.js

This file was deleted.

0 comments on commit 9525722

Please sign in to comment.