Calculator Plugins
Calculator plugins are registered in the CalculationDependencyProvider::getQuoteCalculatorPluginStack() for QuoteTransfer and CalculationDependencyProvider::getOrderCalculatorPluginStack() or in later versions of the Calculation module 4.00 and above 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
ProductOptionTransfer::sumGrossPrice = ProductOptionTransfer::unitGrossPrice * ProductOptionTransfer::quantity
ItemTransfer::unitGrossPriceWithProductOptions = sum(ProductOptionTransfer::unitGrossPrice) + ItemTransfer::unitGrossPrice
ItemTransfer::sumGrossPriceWithProductOptions = sum(ProductOptionTransfer::sumGrossPrice) + ItemTransfer:sumGrossPrice
TotalsTransfer::subtotal = sum(ItemTransfer::sumGrossPriceWithProductOptions)
ExpenseTransfer::sumGrossPrice = ExpenseTransfer::unitGrossPrice * ExpenseTransfer::quantity
TotalsTransfer::expenseTotal = sum(ExpenseTransfer::sumGrossPrice)
Discount Calculation
Discount calculation is a separate topic and is explained here Discount.
ItemTransfer::unitGrossPriceWithProductOptionAndDiscountAmounts = ItemTransfer::unitGrossPriceWithProductOptions - (sum(ItemTransfer:calculatedDiscounts::unitGrossPrice) + sum(ProductOptionTransfer::calculatedDiscounts::unitGrossPrice))
ItemTransfer::sumGrossPriceWithProductOptionAndDiscountAmounts = ItemTransfer::sumGrossPriceWithProductOptions - (sum(ItemTransfer:calculatedDiscounts::sumGrossPrice) + sum(ProductOptionTransfer::calculatedDiscounts::sumGrossPrice))
TotalsTransfer:discountTotal += sum(ItemTransfer::CalculateDiscountTransfer::sumGrossAmount +
ItemTransfer::ProductOptionTransfer::CalculateDiscountTransfer::sumGrossAmount + ExpenseTransfer::sumGrossAmount)
GrandTotalTotalsCalculatorPlugin - Calculates grandTotal in TotalsTransfer.
TotalsTransfer:grandTotal = TotalsTransfer::subtotal + TotalsTransfer:expenseTotal
TotalsTransfer:grandTotal = TotalsTransfer::subtotal + TotalsTransfer:expenseTotal - TotalsTransfer::discountTotal
TaxableItems = ItemTransfer, ProductOptionTransfer, ExpenseTransfer. TaxTotalsTransfer::taxRate = sum(TaxableItems) / TaxableItems TaxTotalsTransfer::taxAmount = round((TotalsTransfer::grandTotal * TaxTotalsTransfer::taxRate) / TaxTotalsTransfer::taxRate / 100)
See also: