{% sw_extends '@Storefront/storefront/page/checkout/summary.html.twig' %} {# Injects milestone discount rows and a "✓ Free" shipping label into the checkout summary sidebar on /checkout/cart, /checkout/confirm, and order pages. We override page_checkout_summary_inner (a block directly in summary.html.twig) rather than blocks inside sw_include'd sub-templates, which are not reliably overridable across sw_include boundaries. Data source: page.extensions.ucMilestoneInfo Set by: StorefrontPageSubscriber::onStorefrontRender() BEFORE stripping. Falls through to {{ parent() }} when no milestone info is present. CROSS-PLUGIN NOTE: SellopsPostPurchaseUpsell (installed separately, NOT part of this plugin) overrides this SAME block in this SAME file to show its own discount row. Twig block inheritance only lets ONE override actually execute per render — whichever plugin's template ends up "outer" in the chain (not something either plugin controls) decides, and it normally would NEVER see the other plugin's row at all. So this block also scans for that other plugin's own `sellops_upsell_discount` line items (its real line item type — must stay exactly as-is to match) and renders that row too — regardless of which plugin's override happens to "win" the chain on a given install, the customer always sees BOTH discounts (if both happen to be active on the same order), never just one silently dropped. #} {% block page_checkout_summary_inner %} {%- set info = page.extensions.ucMilestoneInfo ?? null -%} {# page.cart is available on cart + confirm pages; page.order on success pages #} {%- set pageCart = page.cart ?? page.order -%} {# ── Other plugin's discount detection (cross-plugin, see note above) ── #} {%- set otherPluginDiscountTotal = 0 -%} {%- set otherPluginDiscountPercent = null -%} {% for li in pageCart.lineItems %} {% if li.type == 'sellops_upsell_discount' and li.price is not null %} {% set otherPluginDiscountTotal = otherPluginDiscountTotal + li.price.totalPrice %} {% if otherPluginDiscountPercent is null %} {% set otherPluginDiscountPercent = li.payload.sellopsUpsellDiscountPercent ?? null %} {% endif %} {% endif %} {% endfor %} {% if (info and (info.discountItems|length > 0 or info.freeShippingApplied)) or otherPluginDiscountTotal != 0 %} {# ── Subtotal row (product-only, stripped items excluded) ── #} {% set productSubtotal = 0 %} {% for item in pageCart.lineItems %} {% if item.type == 'product' and item.price is not null %} {% set productSubtotal = productSubtotal + item.price.totalPrice %} {% endif %} {% endfor %}
{{ 'checkout.summaryPositionPrice'|trans|sw_sanitize }}
{{ productSubtotal|currency }}
{# ── Milestone discount rows ── #} {# discountItems are normalised {label, totalPrice} arrays — works for both #} {# cart LineItem objects and order OrderLineItemEntity objects. #} {% if info %} {% for item in info.discountItems %}
★ {{ item.label|sw_sanitize }}
{{ item.totalPrice|currency }}
{% endfor %} {% endif %} {# ── Other plugin's discount row (cross-plugin, see note above) ── #} {% if otherPluginDiscountTotal != 0 %}
★ {{ 'sellops-ultimate-cart.checkout.specialOfferDiscount'|trans }}{% if otherPluginDiscountPercent %} ({{ otherPluginDiscountPercent }}%){% endif %}
{{ otherPluginDiscountTotal|currency }}
{% endif %} {# ── Shipping row ── #} {% for delivery in pageCart.deliveries %}
{{ 'checkout.summaryShipping'|trans|sw_sanitize }}
{% if info and info.freeShippingApplied %}
{{ 'sellops-ultimate-cart.orderSummary.freeShipping'|trans }}
{% else %}
{% set deliveryPrice = delivery.shippingCosts.totalPrice ?? 0 %} {% if deliveryPrice < 0 %}−{% endif %} {{ deliveryPrice|abs|currency }}
{% endif %} {% endfor %} {# ── Tax / total rows — delegate to native sub-templates ── #} {% set displayRounded = context.totalRounding.interval != 0.01 or context.totalRounding.decimals != context.itemRounding.decimals %} {% set decimals = context.totalRounding.decimals %} {% set total = pageCart.price.totalPrice %} {% if displayRounded %} {% set decimals = context.itemRounding.decimals %} {% set total = pageCart.price.rawTotal %} {% endif %} {% if pageCart.price.taxStatus == 'gross' %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-total.html.twig' with { total: total, decimals: decimals } %} {% if displayRounded %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-total-rounded.html.twig' with { summary: pageCart, decimals: context.totalRounding.decimals } %} {% endif %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-net.html.twig' with { summary: pageCart } %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-tax.html.twig' with { summary: pageCart } %} {% else %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-net.html.twig' with { summary: pageCart } %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-tax.html.twig' with { summary: pageCart } %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-total.html.twig' with { total: total, decimals: decimals } %} {% if displayRounded %} {% sw_include '@Storefront/storefront/page/checkout/summary/summary-total-rounded.html.twig' with { summary: pageCart, decimals: context.totalRounding.decimals } %} {% endif %} {% endif %} {% else %} {{ parent() }} {% endif %} {% endblock %}