Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save markpinero/279135faab9f91bbd6929d474c8eee25 to your computer and use it in GitHub Desktop.

Select an option

Save markpinero/279135faab9f91bbd6929d474c8eee25 to your computer and use it in GitHub Desktop.
cart upsell
{%- liquid
assign cart_item_ids = cart.items | map: 'product_id' | join: ','
assign cart_collection_size = cart_collection.products.size
assign product_form_id = 'product-form-' | append: section.id
for product in cart_collection.products
if cart_item_ids contains product.id
assign cart_collection_size = cart_collection_size | minus: 1
endif
endfor
-%}
{% if cart_collection_size > 0 %}
<div>
{% for product in cart_collection.products %}
{% unless cart_item_ids contains product.id %}
<product-form data-section-id="{{ section.id }}">
{%- form 'product',
product,
id: product_form_id,
class: 'form',
novalidate: 'novalidate',
data-type: 'add-to-cart-form'
-%}
<input
type="hidden"
name="id"
value="{{ product.selected_or_first_available_variant.id }}"
{% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
disabled
{% endif %}
>
<!-- ... -->
<button
type="submit"
{% if product.selected_or_first_available_variant.available == false or quantity_rule_soldout %}
disabled
{% endif %}
>
Add to cart
</button>
{% endform %}
</product-form>
{% endunless %}
{% endfor %}
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment