CART – CROSS-SELLS MINI CART

{% assign seen_ids = ” %}
{% assign has_related = false %}
{% for item in cart.items %}
{% assign related_products = item.product.metafields.shopify–discovery–product_recommendation.related_products.value %}
{% if related_products %}
{% assign has_related = true %}
{% endif %}
{% endfor %}

{% if has_related %}

{% if settings.Upsell_title != blank %}

{{ settings.Upsell_title }}

{% endif %}

{% for item in cart.items %}
{% assign related_products = item.product.metafields.shopify–discovery–product_recommendation.related_products.value %}
{% if related_products %}
{% for related_product in related_products %}
{% unless seen_ids contains related_product.id %}



{{ related_product.title }}

{{ related_product.price | money }} {{ settings.inkl_MwSt }}
{% if settings.tax_text %}
{{ settings.tax_text }}
{% endif %}

{% render ‘custom-addtocart-btn’, product: related_product %}

{% assign seen_ids = seen_ids | append: related_product.id | append: ‘,’ %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}

{% else %}

{%- comment -%} Nếu không có related_products, dùng danh sách upsell cố định {%- endcomment -%}

{% if settings.Upsell_title != blank %}

{{ settings.Upsell_title }}

{% endif %}

{% for up_prod in upsall_product_list limit: 5 %}
{% assign is_not_in_cart = true %}
{% for line_item in cart.items %}
{% if line_item.product.handle == up_prod.handle %}
{% assign is_not_in_cart = false %}
{% break %}
{% endif %}
{% endfor %}
{% if is_not_in_cart %}



{{ up_prod.title }}

{{ up_prod.price | money }} {{ settings.inkl_MwSt }}
{% if settings.tax_text %}
{{ settings.tax_text }}
{% endif %}
{% assign selected_variant = up_prod.selected_or_first_available_variant %}
{% if selected_variant.available and selected_variant.unit_price_measurement %}
(
{{ selected_variant.unit_price | money }}

{% if selected_variant.unit_price_measurement.reference_value != 1 %}
{{ selected_variant.unit_price_measurement.reference_value }}
{% endif %}
{{ selected_variant.unit_price_measurement.reference_unit }})

{% endif %}

{% render ‘custom-addtocart-btn’, product: up_prod %}

{% endif %}
{% endfor %}

{% endif %}

Leave a Reply

Your email address will not be published. Required fields are marked *