Markus Michalski FAQ

Variant Price Surcharge: Technical Details

Technical details of Variant Price Surcharge: storefront and cart flow, plugin structure, services and tags, logging, error code, plus notes on extensibility, permissions and snippets.

Deutsche Version

Back to overview

Technical Details

Flow

graph TD
    A["Product loaded in sales channel"] --> B["ProductSubscriber"]
    B --> C["SurchargeConfigReader"]
    C --> D["ParentPriceResolver"]
    D --> E["VariantPriceCalculator"]
    E --> F["QuantityPriceCalculator"]
    F --> G["calculatedPrice of the variant"]
    H["Cart is calculated"] --> I["VariantPriceProcessor"]
    I --> C
    I --> D
    I --> E
    I --> F
    F --> J["Price of the line item"]

Plugin structure

Class Purpose
MmdVariantPriceSurcharge Plugin class. On uninstall without "keep user data" it deletes the custom field set and system configuration.
Migration1705200000CreateCustomFields Creates the custom field set and the three fields
Subscriber\ProductSubscriber Listens to sales_channel.product.loaded and replaces the calculated price of variants
Core\Checkout\Cart\VariantPriceProcessor Cart processor, service tag shopware.cart.processor, priority 1000
Service\SurchargeConfigReader Reads and validates the custom fields, decides on inheritance
Service\SurchargeConfig Immutable value object of percentage and surcharge
Service\ParentPriceResolver Loads the parent product with its advanced prices, determines its price, caches per request
Service\VariantPriceCalculator Calculation, value ranges, rounding settings from the system configuration
Exception\ParentProductNotFoundException HTTP 404, error code MMD_VARIANT_PRICE_SURCHARGE__PARENT_NOT_FOUND

Details

Extensibility, permissions, snippets