Sales 5.0

The latest version of this module can be found here Sales

Getting Totals for Order

Spryker does not store order grand total or subtotal amounts; all amounts are stored before calculation, order items store single item gross amounts, discounts store single item discount amount.

To get the discount total there is a facade method SalesFacade::getOrderTotalsByIdSalesOrder() for order level which will return OrderTransfer with aggregated grandTotal, subtotals, expenses, discounts and another is item level SalesFacade:getOrderItemTotalsByIdSalesOrderItem() which returns ItemTransfer single item amounts.

Order Aggregator

As there are no totals stored, those amounts should be retrieved (aggregated) from different places of the system. Like discount module, product option module, sales module etc. This aggregation is provided by specialized plugins. Each plugin has to implemented. OrderTotalsAggregatePluginInterface and work with OrderTransfer data object. Plugins are registered in the Sales module’s SalesDependencyProvider::getItemAmountAggregationPlugins() and SalesDependencyProvider::getOrderAmountAggregationPlugins() method.

There is already list of plugins implemented.

Expense total aggregator plugin (order level)

Aggregates expense total amount; reads data from sales_expense and stores it into TotalsTransfer:expenseTotal.

Order expenses with discounts aggregator plugin (order level)

Aggregates expense amounts after discounts and stores it into ExpenseTransfer:unitGrossPriceWithDiscounts and ExpenseTransfer:sumGrossPriceWithDiscounts.

Order expense tax amount aggregator plugin (order level)

Aggregates tax amount and store into ExpenseTransfer::unitTaxAmount and ExpenseTransfer::sumTaxAmount.

Order expense tax with discounts aggregator plugin (order level)

Aggregates tax amount after discounts and stores it into ExpenseTransfer::unitTaxAmountWithDiscounts and ExpenseTransfer::sumTaxAmountWithDiscounts.

Item gross price aggregator plugin (item level)

Aggregates item gross price amount into ItemTransfer::unitGrossPrice and ItemTransfer::sumGrossPrice.

Product options gross price aggregator plugin (item level)

Aggregates item gross price with product options into ItemTransfer::unitGrossPriceWithProductOptions, ItemTransfer::sumGrossPriceWithProductOptions and set ItemTransfer::refundableAmounts.

Subtotal order aggregator plugin (order level)

Aggregates subtotal by adding all ItemTransfer::sumGrossPrice.

Subtotal with product options aggregator plugin (order level)

Aggregates subtotal by adding all ItemTransfer::sumGrossPriceWithProductOptions.

Item discounts order aggregator plugin (item level)

Aggregates discounts from sales_discount table; stores them into unitGrossPriceWithDiscounts, sumGrossPriceWithDiscounts for all discountable items.

Product option discounts aggregator plugin (item level)

Aggregates discounts for items with product options from sales_discount table into ItemTransfer::unitGrossPriceWithProductOptionAndDiscountAmounts, ItemTransfer::sumGrossPriceWithProductOptionAndDiscountAmounts, ItemTransfer:refundableAmount.

Discount total amount aggregator plugin (order level)

Aggregates total discount amount used for current order; stores it in TotalTransfer:discountTotal.

Discount total amount with product options aggregator plugin (order level)

Aggregates total discount amount with product option discounts and stores it into TotalTransfer:discountTotal.

Order discount aggregator plugin (order level)

Aggregates all discounts used in current order and stores it into OrderTransfer::calculatedDiscounts.

Order discounts with product options aggregator plugin (order level)

Aggregates all discounts with product options used in current order and stores it into OrderTransfer::calculatedDiscounts.

Grand total aggregator plugin (order level)

Aggregates order grandTotal by calculating TotalTransfer::grandTotal = TotalTransfer::subTotal + TotalTransfer::expenseTotal

Order grand total with discounts aggregator plugin (order level)

Aggregates order grandTotal by calculating TotalTransfer::grandTotal = TotalTransfer::subTotal + TotalTransfer::expenseTotal - TotalsTransfer:discountTotal

 

Item tax amount aggregator plugin (item level)

Calculates tax rate for each and stores it into ItemTransfer::unitTaxAmount, ItemTransfer::sumTaxAmount.

Item tax with discounts aggregator plugin (item level)

Calculates tax rate for items with product options ItemTransfer::unitTaxAmountWithDiscounts, ItemTransfer::sumTaxAmountWithDiscounts.

Items with product options and discounts tax aggregator plugin (item level)

Calculates tax rate for items with product options and after discounts and stores it into ItemTransfer::unitTaxAmountWithProductOptionAndDiscountAmounts, ItemTransfer::sumTaxAmountWithProductOptionAndDiscountAmounts.

Order tax amount with product options and discounts aggregator plugin (order level)

Stores tax rate and tax amount from grandTotal into TaxTotalTransfer::taxRate, TaxTotalTransfer::amount.