Skip to content

Commit dfecce9

Browse files
authored
Merge branch 'development' into fix-7761
2 parents ceca227 + 05b2d9d commit dfecce9

File tree

4 files changed

+92
-37
lines changed

4 files changed

+92
-37
lines changed

app/components/orders/order-summary.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,46 @@ export default class OrderSummary extends Component.extend(FormMixin) {
1818
);
1919
}
2020

21+
@computed('data.tickets', '[email protected]', 'data.discountCode')
22+
get orderAmountInput() {
23+
const discountCodeId = this.data.discountCode?.get('id');
24+
const input = {
25+
'discount-code' : discountCodeId,
26+
'tickets' : this.data.tickets.toArray().map(ticket => ({
27+
id : ticket.id,
28+
quantity : ticket.get('attendees.length'),
29+
price : ticket.price
30+
}))
31+
};
32+
return input;
33+
}
34+
2135
async didInsertElement() {
22-
const discountCode = await this.data.discountCode;
23-
const tickets = await this.data.tickets;
24-
tickets.forEach(ticket => {
25-
ticket.set('discount', 0);
26-
});
27-
if (discountCode) {
28-
const discountCodeTickets = await discountCode.get('tickets');
29-
const discountType = discountCode.get('type');
30-
const discountValue = discountCode.get('value');
31-
tickets.forEach(ticket => {
32-
if (discountCodeTickets.includes(ticket)) {
33-
const ticketPrice = ticket.get('price');
34-
if (discountType === 'amount') {
35-
ticket.set('discount', Math.min(ticketPrice, discountValue));
36-
} else {
37-
ticket.set('discount', ticketPrice * (discountValue / 100));
36+
try {
37+
const discountCode = await this.data.discountCode;
38+
const tickets = await this.data.tickets;
39+
const ticketInput = this.orderAmountInput;
40+
const ticketAmount = await this.loader.post('/orders/calculate-amount', ticketInput);
41+
this.set('total', ticketAmount.sub_total);
42+
this.set('grandTotal', ticketAmount.total);
43+
if (discountCode) {
44+
tickets.forEach(ticket => {
45+
const mappedTicket = ticketAmount.tickets.find(o => {
46+
return ticket.id === o.id.toString();
47+
});
48+
ticket.set('subTotal', mappedTicket.sub_total);
49+
if (mappedTicket.discount) {
50+
ticket.set('discountedTicketTax', mappedTicket.discounted_tax);
51+
ticket.set('discountedTicketPrice', mappedTicket.price - mappedTicket.discount.amount);
3852
}
39-
}
40-
});
53+
});
54+
}
55+
} catch (e) {
56+
console.error('Error while setting order amount', e);
57+
this.notify.error(this.l10n.t('An unexpected error has occurred.'),
58+
{
59+
id: 'orde_sum_err'
60+
});
4161
}
4262
}
4363
}

app/components/public/ticket-list.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,21 @@ export default Component.extend(FormMixin, {
163163
if (this.currentEventIdentifier === discountCodeEvent.identifier) {
164164
this.order.set('discountCode', discountCode);
165165
const tickets = await discountCode.tickets;
166+
const ticketInput = {
167+
'discount-code' : discountCode.id,
168+
'tickets' : tickets.toArray().map(ticket => ({
169+
id : ticket.id,
170+
quantity : 1,
171+
price : ticket.price
172+
}))
173+
};
174+
const ticketAmount = await this.loader.post('/orders/calculate-amount', ticketInput);
166175
tickets.forEach(ticket => {
167-
const discount = discountCode.type === 'amount' ? Math.min(ticket.price, discountCode.value) : ticket.price * (discountCode.value / 100);
168-
ticket.set('discount', discount);
176+
const discountedTicket = ticketAmount.tickets.find(o => {
177+
return ticket.id === o.id.toString();
178+
});
179+
ticket.set('discountedTicketTax', discountedTicket.discounted_tax);
180+
ticket.set('discount', discountedTicket.discount.amount);
169181
this.discountedTickets.addObject(ticket);
170182
this.set('invalidPromotionalCode', false);
171183
});

app/templates/components/orders/order-summary.hbs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@
6565
{{/if}}
6666
</th>
6767
<th class="four wide">{{t 'Price'}}</th>
68-
{{#if this.data.discountCode}}
69-
<th class="ui aligned two wide">{{t 'Discount'}}</th>
70-
{{/if}}
7168
<th class="three wide">{{t 'Quantity'}}</th>
7269
<th class="ui aligned four wide">{{t 'Subtotal'}}</th>
7370
{{/if}}
@@ -101,40 +98,55 @@
10198
</div>
10299
</td>
103100
<td>
104-
<Orders::TicketPrice
105-
@ticket={{ticket}}
106-
@currency={{this.eventCurrency}}
107-
@amount={{ticket.price}} />
101+
<div class="{{if ticket.discountedTicketPrice 'strike text'}}">
102+
<Orders::TicketPrice
103+
@ticket={{ticket}}
104+
@currency={{this.eventCurrency}}
105+
@amount={{ticket.price}} />
106+
</div>
107+
{{#if ticket.discountedTicketPrice}}
108+
<CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.discountedTicketPrice}}/>
109+
{{/if}}
108110
<p>
109111
{{#if this.event.tax.isTaxIncludedInPrice}}
110-
<small class="ui gray-text small">
112+
<small class="ui gray-text small {{if ticket.discountedTicketTax 'strike text'}}">
111113
{{t 'includes'}} <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.includedTaxAmount}}/>
112114
</small>
113115
{{else}}
114116
{{#if (gt (sub ticket.ticketPriceWithTax ticket.price) 0)}}
115-
<small class="ui gray-text small">
117+
<small class="ui gray-text small {{if ticket.discountedTicketTax 'strike text'}}">
116118
+ <CurrencyAmount @currency={{this.eventCurrency}} @amount={{sub ticket.ticketPriceWithTax ticket.price}}/>
117119
</small>
118120
{{/if}}
119121
{{/if}}
120-
{{#if this.event.tax.name}}
122+
{{#if ticket.discountedTicketTax}}
123+
{{#if this.event.tax.isTaxIncludedInPrice}}
124+
<small class="ui gray-text small">
125+
<br>{{t 'includes'}} <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.discountedTicketTax}}/>
126+
</small>
127+
{{else}}
128+
{{#if (gt (sub ticket.ticketPriceWithTax ticket.price) 0)}}
129+
<small class="ui gray-text small">
130+
<br>+ <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.discountedTicketTax}}/>
131+
</small>
132+
{{/if}}
133+
{{/if}}
134+
{{/if}}
135+
{{#if (and this.event.tax.name (not-eq ticket.type 'free'))}}
121136
<span>
122137
<small class="ui gray-text tiny aligned right">({{this.event.tax.name}})</small>
123138
</span>
124139
{{/if}}
125140
</p>
126141
</td>
127-
{{#if this.data.discountCode}}
128-
<td>{{currency-symbol this.eventCurrency}} {{format-money ticket.discount}}</td>
129-
{{/if}}
130142
<td>
131143
{{tickets.length}}
132144
</td>
133145
<td>
134146
<Orders::TicketPrice
135147
@ticket={{ticket}}
136148
@currency={{this.eventCurrency}}
137-
@amount={{mult (sub ticket.price ticket.discount) tickets.length}} />
149+
@amount={{ticket.subTotal}} />
138150
</td>
139151
{{/if}}
140152
</tr>
@@ -166,7 +178,7 @@
166178
</tr>
167179
{{/if}}
168180
<tr><td>{{t 'Grand Total'}}</td>
169-
<td><CurrencyAmount @currency={{this.eventCurrency}} @amount={{this.data.amount}}/></td>
181+
<td><CurrencyAmount @currency={{this.eventCurrency}} @amount={{this.grandTotal}}/></td>
170182
</tr>
171183
</tbody>
172184
</table>

app/templates/components/public/ticket-list.hbs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,25 @@
6565
{{#if (and this.taxInfo (not-eq ticket.type 'free'))}}
6666
<p>
6767
{{#if this.taxInfo.isTaxIncludedInPrice}}
68-
<small class="ui gray-text small">
68+
<small class="ui gray-text small {{if ticket.discountedTicketTax 'strike text'}}">
6969
{{t 'includes'}} <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.includedTaxAmount}}/>
7070
</small>
7171
{{else}}
72-
<small class="ui gray-text small">
72+
<small class="ui gray-text small {{if ticket.discountedTicketTax 'strike text'}}">
7373
+ <CurrencyAmount @currency={{this.eventCurrency}} @amount={{sub ticket.ticketPriceWithTax ticket.price}}/>
7474
</small>
7575
{{/if}}
76+
{{#if ticket.discountedTicketTax}}
77+
{{#if this.taxInfo.isTaxIncludedInPrice}}
78+
<small class="ui gray-text small">
79+
<br>{{t 'includes'}} <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.discountedTicketTax}}/>
80+
</small>
81+
{{else}}
82+
<small class="ui gray-text small">
83+
<br>+ <CurrencyAmount @currency={{this.eventCurrency}} @amount={{ticket.discountedTicketTax}}/>
84+
</small>
85+
{{/if}}
86+
{{/if}}
7687
<span>
7788
<small class="ui gray-text tiny aligned right">({{this.taxInfo.name}})</small>
7889
</span>

0 commit comments

Comments
 (0)