Variant Price Surcharge: Storefront and Price Calculation
Price calculation of Variant Price Surcharge in storefront and cart: parent price source, rule prices, gross/net, currency. Strikethrough prices are dropped and quantity tiers of the variant have no effect (single unit price).
Storefront and Price Calculation
The plugin does not change any prices in the database. It calculates the variant price at runtime when a product is loaded in a sales channel, and again during cart calculation.
Where the calculation happens
| Place | Trigger | Effect |
|---|---|---|
| Product display in the sales channel | Event sales_channel.product.loaded |
The variant's calculated price (calculatedPrice) is replaced |
| Cart and checkout | Cart processor with priority 1000 | The price definition and price of the product line item are replaced |
In the admin (Admin API) the variant's price stays unchanged because no sales channel event is triggered there.
Calculation steps
- The plugin checks whether the product is a variant. Products without a parent product are skipped.
- It reads the three custom fields of the variant and, if needed, applies inheritance from the parent product.
- It determines the parent product's price (see below). If it is 0 or missing, the variant's price stays unchanged.
- It calculates (parent price + surcharge) x (percentage / 100), sets negative results to 0 and rounds according to the plugin settings.
- It calculates taxes and totals with Shopware's
QuantityPriceCalculatorand the product's tax rules.
Parent product price
- First the parent product's advanced prices (rule prices) are checked. The plugin goes through the customer's active rules in order of rule priority, takes the tier with the lowest quantity for the first matching rule and uses its price if it is greater than 0.
- If no rule price matches, the parent product's standard price applies.
- The price is read in the sales channel's currency. If it is missing there, the default currency price is used and converted with the currency factor.
- If the context uses gross prices, the gross price is used, with net prices the net price.
The fixed surcharge is added to this price unchanged. It is not converted between currencies and counts as a gross or net amount depending on the tax state, even though the field name contains "(EUR)".
Strikethrough price, reference price and quantity tiers
The plugin replaces the variant's entire calculated price with a newly calculated price that has no list (strikethrough) price and no reference price. An existing strikethrough or reference price of the variant is therefore dropped for adjusted variants, both in the product display and in the cart. Check this in the storefront if you work with such price information.
For adjusted variants a single unit price always applies, which the plugin calculates from the lowest tier of the matching rule price (or the standard price) of the parent product. Quantity tiers in the variant's own prices have no effect there, and a higher quantity in the cart does not lower the unit price. The product's tier list (calculatedPrices) and the cheapest price of a variant group are not modified by the plugin, but the adjustment does not apply to them.
Behaviour in special cases
| Situation | Behaviour |
|---|---|
| Parent product not found | Price stays unchanged, an error (product display) or a warning (cart) is written to the log |
| Variant without tax ID | The price is not adjusted in the product display |
| Enabled but no valid values | Price stays unchanged |
| Calculation result negative | Price is 0.00 |
| Percentage 0 | Price is 0.00 (0 is a valid value) |
| Invalid or infinite numbers | Values are ignored or the calculation yields 0 |