1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Spryker Commerce OS. |
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
declare(strict_types = 1); |
9
|
|
|
|
10
|
|
|
namespace Pyz\Zed\Calculation; |
11
|
|
|
|
12
|
|
|
use Spryker\Zed\Calculation\CalculationDependencyProvider as SprykerCalculationDependencyProvider; |
13
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\CanceledTotalCalculationPlugin; |
14
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\DiscountAmountAggregatorForGenericAmountPlugin; |
15
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\DiscountTotalCalculatorPlugin; |
16
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\ExpenseTotalCalculatorPlugin; |
17
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\GrandTotalCalculatorPlugin; |
18
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\InitialGrandTotalCalculatorPlugin; |
19
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\ItemDiscountAmountFullAggregatorPlugin; |
20
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\ItemProductOptionPriceAggregatorPlugin; |
21
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\ItemSubtotalAggregatorPlugin; |
22
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\NetTotalCalculatorPlugin; |
23
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\OrderTaxTotalCalculationPlugin; |
24
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\PriceCalculatorPlugin; |
25
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\PriceToPayAggregatorPlugin; |
26
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\RefundableAmountCalculatorPlugin; |
27
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\RefundTotalCalculatorPlugin; |
28
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\RemoveAllCalculatedDiscountsCalculatorPlugin; |
29
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\RemoveCanceledAmountCalculatorPlugin; |
30
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\RemoveTotalsCalculatorPlugin; |
31
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\SubtotalCalculatorPlugin; |
32
|
|
|
use Spryker\Zed\Calculation\Communication\Plugin\Calculator\TaxTotalCalculatorPlugin; |
33
|
|
|
use Spryker\Zed\DiscountCalculationConnector\Communication\Plugin\Calculation\DiscountCalculationPlugin; |
34
|
|
|
use Spryker\Zed\DiscountPromotion\Communication\Plugin\Calculation\RemovePromotionItemsCalculatorPlugin; |
35
|
|
|
use Spryker\Zed\Kernel\Container; |
36
|
|
|
use Spryker\Zed\Payment\Communication\Plugin\Calculation\PaymentCalculatorPlugin; |
37
|
|
|
use Spryker\Zed\PersistentCart\Communication\Plugin\Calculation\QuoteSaveQuotePostRecalculateStrategyPlugin; |
38
|
|
|
use Spryker\Zed\ProductBundle\Communication\Plugin\Calculation\CalculateBundlePricesPlugin; |
39
|
|
|
use Spryker\Zed\ProductOption\Communication\Plugin\Calculation\ProductOptionTaxRateCalculatorPlugin; |
40
|
|
|
use Spryker\Zed\SalesOrderThreshold\Communication\Plugin\Calculation\AddSalesOrderThresholdExpenseCalculatorPlugin; |
41
|
|
|
use Spryker\Zed\SalesOrderThreshold\Communication\Plugin\Calculation\RemoveSalesOrderThresholdExpenseCalculatorPlugin; |
42
|
|
|
use Spryker\Zed\Shipment\Communication\Plugin\Calculation\FilterObsoleteShipmentExpensesCalculatorPlugin; |
43
|
|
|
use Spryker\Zed\Shipment\Communication\Plugin\Calculation\ShipmentTaxRateCalculatorPlugin; |
44
|
|
|
use Spryker\Zed\Shipment\Communication\Plugin\Calculation\ShipmentTotalCalculatorPlugin; |
45
|
|
|
use Spryker\Zed\TaxApp\Communication\Plugin\Calculation\TaxAppCalculationPlugin; |
46
|
|
|
use Spryker\Zed\TaxProductConnector\Communication\Plugin\Calculation\ProductItemTaxRateCalculatorPlugin; |
47
|
|
|
|
48
|
|
|
class CalculationDependencyProvider extends SprykerCalculationDependencyProvider |
49
|
|
|
{ |
50
|
|
|
/** |
51
|
|
|
* This calculator stack working with quote object which happens to be processed in cart/checkout |
52
|
|
|
* |
53
|
|
|
* You can view calculated values in: http://{domain.tld}/calculation/debug. For this to work you must have items in cart. |
54
|
|
|
* |
55
|
|
|
* RemoveTotalsCalculatorPlugin - Reset TotalsTransfer object |
56
|
|
|
* |
57
|
|
|
* RemoveAllCalculatedDiscountsCalculatorPlugin - Reset CalculateDiscounts for: |
58
|
|
|
* - Item.calculatedDiscounts |
59
|
|
|
* - Item.productOption.calculatedDiscounts |
60
|
|
|
* - Expense.calculatedDiscounts |
61
|
|
|
* |
62
|
|
|
* RemoveCanceledAmountCalculatorPlugin - Reset item canceled amount for: |
63
|
|
|
* - Item.canceledAmount |
64
|
|
|
* |
65
|
|
|
* PriceCalculatorPlugin - Calculates price based on tax mode, tax mode is set in this calculator based on CalculationConstants::TAX_MODE configuration key. |
66
|
|
|
* - Item.unitPrice |
67
|
|
|
* - Item.sumPrice |
68
|
|
|
* - Item.productOption.unitPrice |
69
|
|
|
* - Item.productOption.sumPrice |
70
|
|
|
* - Expense.unitPrice |
71
|
|
|
* - Expense.sumPrice |
72
|
|
|
* When "gross" mode: |
73
|
|
|
* - Item.sumGrossPrice |
74
|
|
|
* - Item.productOption.sumGrossPrice |
75
|
|
|
* - Expense.sumGrossPrice |
76
|
|
|
* When "Net" mode: |
77
|
|
|
* - Item.sumNetPrice |
78
|
|
|
* - Item.productOption.sumNetPrice |
79
|
|
|
* - Expense.sumNetPrice |
80
|
|
|
* |
81
|
|
|
* ItemProductOptionPriceAggregatorPlugin - Item option price sum total |
82
|
|
|
* - Item.unitProductOptionAggregation |
83
|
|
|
* - Item.sumProductOptionAggregation |
84
|
|
|
* |
85
|
|
|
* ItemSubtotalAggregatorPlugin - Total price amount (item + options + item expenses) |
86
|
|
|
* - Item.unitSubtotal |
87
|
|
|
* - Item.sumSubtotal |
88
|
|
|
* |
89
|
|
|
* SubtotalCalculatorPlugin - Sum of item sumAggregation |
90
|
|
|
* - Total.subtotal |
91
|
|
|
* |
92
|
|
|
* DiscountCalculationPlugin - Discount bundle calculator, runs cart/order rules/applies voucher codes. |
93
|
|
|
* - Item.calculatedDiscounts[].unitGrossAmount |
94
|
|
|
* - Item.productOptions.calculatedDiscounts[].unitGrossAmount |
95
|
|
|
* - Expense.calculatedDiscounts[].unitGrossAmount |
96
|
|
|
* |
97
|
|
|
* DiscountAmountAggregatorForGenericAmountPlugin - Sums all discounts for corresponding object |
98
|
|
|
* - Item.unitDiscountAmountAggregation |
99
|
|
|
* - Item.sumDiscountAmountAggregation |
100
|
|
|
* - Item.productOptions.unitDiscountAmountAggregation |
101
|
|
|
* - Item.productOptions.sumDiscountAmountAggregation |
102
|
|
|
* - Expense.unitDiscountAmountAggregation |
103
|
|
|
* - Expense.sumDiscountAmountAggregation |
104
|
|
|
* |
105
|
|
|
* - Item.calculatedDiscounts[].sumGrossAmount |
106
|
|
|
* - Item.productOptions.calculatedDiscounts[].sumGrossAmount |
107
|
|
|
* - Expense.calculatedDiscounts[].sumGrossAmount |
108
|
|
|
* |
109
|
|
|
* ItemDiscountAmountFullAggregatorPlugin - Sums item all discounts with additions (option and item expense discounts) |
110
|
|
|
* - Item.unitDiscountAmountFullAggregation |
111
|
|
|
* - Item.sumDiscountAmountFullAggregation |
112
|
|
|
* |
113
|
|
|
* PriceToPayAggregatorPlugin - Final price customer have to pay after discounts |
114
|
|
|
* - Item.unitPriceToPayAggregation |
115
|
|
|
* - Item.sumPriceToPayAggregation |
116
|
|
|
* - Expense.unitPriceToPayAggregation |
117
|
|
|
* - Expense.sumPriceToPayAggregation |
118
|
|
|
* |
119
|
|
|
* TaxRateAverageAggregatorPlugin - average tax rate for item, used when recalculating canceled amount when refunded |
120
|
|
|
* - Item.taxRateAverageAggregation |
121
|
|
|
* |
122
|
|
|
* TaxAppCalculationPlugin - Calculate tax using external tax application. Replaces all tax calculation plugins above. |
123
|
|
|
* Replaced tax calculation plugins should be moved to {@link \Spryker\Zed\TaxApp\TaxAppDependencyProvider::getFallbackQuoteCalculationPlugins} method. |
124
|
|
|
* Replaced tax calculation plugin stack should include all plugins which were present between extracted tax-related plugins. |
125
|
|
|
* |
126
|
|
|
* ProductItemTaxRateCalculatorPlugin - Sets tax rate to item based on shipping address |
127
|
|
|
* - Item.taxRate |
128
|
|
|
* |
129
|
|
|
* ProductOptionTaxRateCalculatorPlugin - Sets tax rate to expense based on shipping address |
130
|
|
|
* - Item.productOptions[].taxRate |
131
|
|
|
* |
132
|
|
|
* ShipmentTaxRateCalculatorPlugin - Sets tax rate to expense based on shipping address |
133
|
|
|
* - Expense.taxRate |
134
|
|
|
* |
135
|
|
|
* TaxAmountCalculatorPlugin - Calculates tax amount based on tax mode after discounts |
136
|
|
|
* - Item.unitTaxAmount |
137
|
|
|
* - Item.sumTaxAmount |
138
|
|
|
* - Item.productOptions[].unitTaxAmount |
139
|
|
|
* - Item.productOptions[].sumTaxAmount |
140
|
|
|
* - Expense.unitTaxAmount |
141
|
|
|
* - Expense.sumTaxAmount |
142
|
|
|
* |
143
|
|
|
* ItemTaxAmountFullAggregatorPlugin - Calculate for all item additions |
144
|
|
|
* - Item.unitTaxAmountFullAggregation |
145
|
|
|
* - Item.sumTaxAmountFullAggregation |
146
|
|
|
* |
147
|
|
|
* TaxRateAverageAggregatorPlugin - Calculate tax rate average aggregation used when recalculating taxable amount after refund |
148
|
|
|
* - Item.taxRateAverageAggregation |
149
|
|
|
* |
150
|
|
|
* RefundableAmountCalculatorPlugin - Calculate refundable for each item and expenses |
151
|
|
|
* - Item.refundableAmount |
152
|
|
|
* - Expense.refundableAmount |
153
|
|
|
* |
154
|
|
|
* CalculateBundlePricesPlugin - Calculate bundle item total, from bundled items |
155
|
|
|
* - BundledItem.unitPrice |
156
|
|
|
* - BundledItem.sumPrice |
157
|
|
|
* - BundledItem.unitGrossPrice |
158
|
|
|
* - BundledItem.sumGrossPrice |
159
|
|
|
* - BundledItem.unitNetPrice |
160
|
|
|
* - BundledItem.sumNetPrice |
161
|
|
|
* – BundledItem.unitTaxAmountFullAggregation |
162
|
|
|
* - BundledItem.sumTaxAmountFullAggregation |
163
|
|
|
* - BundledItem.unitTaxAmountAggregation |
164
|
|
|
* - BundledItem.sumTaxAmountAggregation |
165
|
|
|
* |
166
|
|
|
* ExpenseTotalCalculatorPlugin - Calculate order expenses total |
167
|
|
|
* - Totals.expenseTotal |
168
|
|
|
* |
169
|
|
|
* DiscountTotalCalculatorPlugin - Calculate discount total |
170
|
|
|
* - Totals.discountTotal |
171
|
|
|
* |
172
|
|
|
* RefundTotalCalculatorPlugin - Calculate refund total |
173
|
|
|
* - Totals.refundTotal |
174
|
|
|
* |
175
|
|
|
* GrandTotalCalculatorPlugin - Calculate grand total |
176
|
|
|
* - Totals.grandTotal |
177
|
|
|
* |
178
|
|
|
* TaxTotalCalculatorPlugin - Total tax amount |
179
|
|
|
* - Totals.taxTotal.amount |
180
|
|
|
* |
181
|
|
|
* NetTotalCalculatorPlugin - Calculate total amount before taxes |
182
|
|
|
* - Totals.netTotal |
183
|
|
|
* |
184
|
|
|
* @param \Spryker\Zed\Kernel\Container $container |
185
|
|
|
* |
186
|
|
|
* @return array<\Spryker\Zed\CalculationExtension\Dependency\Plugin\CalculationPluginInterface> |
187
|
|
|
*/ |
188
|
|
|
protected function getQuoteCalculatorPluginStack(Container $container): array // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter |
189
|
|
|
{ |
190
|
|
|
/** @var array<\Spryker\Zed\Calculation\Dependency\Plugin\CalculationPluginInterface> $pluginStack */ |
191
|
|
|
$pluginStack = [ |
192
|
|
|
new RemoveTotalsCalculatorPlugin(), |
193
|
|
|
new RemoveAllCalculatedDiscountsCalculatorPlugin(), |
194
|
|
|
new RemovePromotionItemsCalculatorPlugin(), |
195
|
|
|
new RemoveCanceledAmountCalculatorPlugin(), |
196
|
|
|
new RemoveSalesOrderThresholdExpenseCalculatorPlugin(), #SalesOrderThresholdFeature |
197
|
|
|
new FilterObsoleteShipmentExpensesCalculatorPlugin(), |
198
|
|
|
|
199
|
|
|
new PriceCalculatorPlugin(), |
200
|
|
|
new ItemProductOptionPriceAggregatorPlugin(), |
201
|
|
|
new ItemSubtotalAggregatorPlugin(), |
202
|
|
|
|
203
|
|
|
new SubtotalCalculatorPlugin(), |
204
|
|
|
new AddSalesOrderThresholdExpenseCalculatorPlugin(), #SalesOrderThresholdFeature |
205
|
|
|
|
206
|
|
|
new ProductItemTaxRateCalculatorPlugin(), |
207
|
|
|
new ProductOptionTaxRateCalculatorPlugin(), |
208
|
|
|
new ShipmentTaxRateCalculatorPlugin(), |
209
|
|
|
|
210
|
|
|
new InitialGrandTotalCalculatorPlugin(), |
211
|
|
|
new DiscountCalculationPlugin(), |
212
|
|
|
new DiscountAmountAggregatorForGenericAmountPlugin(), |
213
|
|
|
new ItemDiscountAmountFullAggregatorPlugin(), |
214
|
|
|
|
215
|
|
|
new TaxAppCalculationPlugin(), |
216
|
|
|
|
217
|
|
|
new PriceToPayAggregatorPlugin(), |
218
|
|
|
|
219
|
|
|
new RefundableAmountCalculatorPlugin(), |
220
|
|
|
|
221
|
|
|
new CalculateBundlePricesPlugin(), |
222
|
|
|
|
223
|
|
|
new ShipmentTotalCalculatorPlugin(), |
224
|
|
|
new ExpenseTotalCalculatorPlugin(), |
225
|
|
|
new DiscountTotalCalculatorPlugin(), |
226
|
|
|
new RefundTotalCalculatorPlugin(), |
227
|
|
|
new TaxTotalCalculatorPlugin(), |
228
|
|
|
new GrandTotalCalculatorPlugin(), |
229
|
|
|
new NetTotalCalculatorPlugin(), |
230
|
|
|
|
231
|
|
|
new PaymentCalculatorPlugin(), |
232
|
|
|
]; |
233
|
|
|
|
234
|
|
|
return $pluginStack; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* This calculator plugin stack working with order object which happens to be created after order is placed |
239
|
|
|
* |
240
|
|
|
* @param \Spryker\Zed\Kernel\Container $container |
241
|
|
|
* |
242
|
|
|
* @return array<\Spryker\Zed\CalculationExtension\Dependency\Plugin\CalculationPluginInterface> |
243
|
|
|
*/ |
244
|
|
|
protected function getOrderCalculatorPluginStack(Container $container): array // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter |
245
|
|
|
{ |
246
|
|
|
return [ |
247
|
|
|
|
248
|
|
|
new PriceCalculatorPlugin(), |
249
|
|
|
new ItemProductOptionPriceAggregatorPlugin(), |
250
|
|
|
new ItemSubtotalAggregatorPlugin(), |
251
|
|
|
|
252
|
|
|
new SubtotalCalculatorPlugin(), |
253
|
|
|
|
254
|
|
|
new DiscountCalculationPlugin(), |
255
|
|
|
|
256
|
|
|
new DiscountAmountAggregatorForGenericAmountPlugin(), |
257
|
|
|
new ItemDiscountAmountFullAggregatorPlugin(), |
258
|
|
|
|
259
|
|
|
new TaxAppCalculationPlugin(), |
260
|
|
|
|
261
|
|
|
new PriceToPayAggregatorPlugin(), |
262
|
|
|
|
263
|
|
|
new RefundableAmountCalculatorPlugin(), |
264
|
|
|
|
265
|
|
|
new ExpenseTotalCalculatorPlugin(), |
266
|
|
|
new DiscountTotalCalculatorPlugin(), |
267
|
|
|
new RefundTotalCalculatorPlugin(), |
268
|
|
|
new CanceledTotalCalculationPlugin(), |
269
|
|
|
new OrderTaxTotalCalculationPlugin(), |
270
|
|
|
|
271
|
|
|
new GrandTotalCalculatorPlugin(), |
272
|
|
|
new NetTotalCalculatorPlugin(), |
273
|
|
|
]; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* @return array<\Spryker\Zed\CalculationExtension\Dependency\Plugin\QuotePostRecalculatePluginStrategyInterface> |
278
|
|
|
*/ |
279
|
|
|
protected function getQuotePostRecalculatePlugins(): array |
280
|
|
|
{ |
281
|
|
|
return [ |
282
|
|
|
new QuoteSaveQuotePostRecalculateStrategyPlugin(), |
283
|
|
|
]; |
284
|
|
|
} |
285
|
|
|
} |
286
|
|
|
|