Calculator plugins
Edit on GitHubCalculator plugins are registered in the CalculationDependencyProvider::getQuoteCalculatorPluginStack()
for QuoteTransfer
and CalculationDependencyProvider::getOrderCalculatorPluginStack()
. In later versions of the Calculation module 4.00 and above, plugins are registered in CalculationDependencyProvider::getQuoteCalculatorPluginStack()
for OrderTransfer.
This method can be extended on the project level and the plugin stack can be updated with your own plugins.
Each calculator must implement CalculatorPluginInterface
.
<?php
interface CalculationPluginInterface
{
/**
* @api
*
* @param /Generated/Shared/Transfer/CalculableObjectTransfer $calculableObjectTransfer
*
* @return void
*/
public function recalculate(CalculableObjectTransfer $calculableObjectTransfer);
}
-
RemoveTotalsCalculatorPlugin
—resets quote totals, sets TotalsTransfer empty. -
RemoveAllCalculatedDiscountsCalculatorPlugin
—resets every CalculatedDiscountTransfer. -
ItemGrossAmountsCalculatorPlugin
—calculates sumGrossPrice for each ItemTransfer.ItemTransfer::sumGrossPrice = ItemTransfer::unitGrossPrice * ItemTransfer::quantity
-
ProductOptionGrossSumCalculatorPlugin
—calculatesunitGrossPriceWithProductOptions
,sumGrossPriceWithProductOptions
forItemTransfer
andsumGrossPrice
forProductOptionTransfer
.ProductOptionTransfer::sumGrossPrice
=ProductOptionTransfer::unitGrossPrice
*ProductOptionTransfer::quantity
ItemTransfer::unitGrossPriceWithProductOptions
=sum(ProductOptionTransfer::unitGrossPrice)
+ItemTransfer::unitGrossPrice
ItemTransfer::sumGrossPriceWithProductOptions
=sum(ProductOptionTransfer::sumGrossPrice)
+ItemTransfer:sumGrossPrice
-
SubtotalTotalsCalculatorPlugin
sums each of thesumGrossPriceWithProductOptions
items.TotalsTransfer::subtotal = sum(ItemTransfer::sumGrossPriceWithProductOptions)
. -
ExpensesGrossSumAmountCalculatorPlugin
—calculatessumGrossPrice
for each item.ExpenseTransfer::sumGrossPrice = ExpenseTransfer::unitGrossPrice * ExpenseTransfer::quantity
-
ExpenseTotalsCalculatorPlugin
—calculates expenseTotal in TotalsTransfer.TotalsTransfer::expenseTotal = sum(ExpenseTransfer::sumGrossPrice)
-
DiscountCalculatorPlugin
—applies discounts to currentQuoteTransfer
for each discountable item with propertycalculatedDiscounts
; gets discounts filled. AlsovoucherDiscounts
andcartRuleDiscounts
are populated with additional used discount data for order level.Discount CalculationDiscount calculation is a separate topic and is explained here Discount.
-
SumGrossCalculatedDiscountAmountCalculatorPlugin
—calculates and setsItemTransfer
amounts after discounts tosumGrossPriceWithProductOptionAndDiscountAmounts
andunitGrossPriceWithProductOptionAndDiscountAmounts
; sets expense amounts after discounts tounitGrossPriceWithDiscounts
andsumGrossPriceWithDiscounts
.ItemTransfer::unitGrossPriceWithProductOptionAndDiscountAmounts
=ItemTransfer::unitGrossPriceWithProductOptions
-(sum(ItemTransfer:calculatedDiscounts::unitGrossPrice)
+sum(ProductOptionTransfer::calculatedDiscounts::unitGrossPrice))
ItemTransfer::sumGrossPriceWithProductOptionAndDiscountAmounts
=ItemTransfer::sumGrossPriceWithProductOptions
-(sum(ItemTransfer:calculatedDiscounts::sumGrossPrice)
+sum(ProductOptionTransfer::calculatedDiscounts::sumGrossPrice))
-
DiscountTotalsCalculatorPlugin
—сalculates total for discounts used and sets it tototalDiscount
inTotalsTransfer
. Sum all discountable itemCalculatedDiscountTransfer
gross amounts:TotalsTransfer:discountTotal
+=sum(ItemTransfer::CalculateDiscountTransfer::sumGrossAmount
+ItemTransfer::ProductOptionTransfer::CalculateDiscountTransfer::sumGrossAmount
+ExpenseTransfer::sumGrossAmount)
GrandTotalTotalsCalculatorPlugin
calculatesgrandTotal
inTotalsTransfer
.TotalsTransfer:grandTotal
=TotalsTransfer::subtotal
+TotalsTransfer:expenseTotal
-
GrandTotalWithDiscountsCalculatorPlugin
—calculatesGrandTotal
after discounts inTotalsTransfer
.TotalsTransfer:grandTotal = TotalsTransfer::subtotal + TotalsTransfer:expenseTotal - TotalsTransfer::discountTotal
-
TaxTotalsCalculatorPlugin
—calculatestaxTotal
andtaxRate
used fromTotalTransfer::grandTotal
, sets it inTotalsTransfer::TaxTotalsTransfer
.TaxableItems = ItemTransfer, ProductOptionTransfer, ExpenseTransfer. TaxTotalsTransfer::taxRate = sum(TaxableItems) / TaxableItems TaxTotalsTransfer::taxAmount = round((TotalsTransfer::grandTotal * TaxTotalsTransfer::taxRate) / TaxTotalsTransfer::taxRate / 100)
Thank you!
For submitting the form