{% comment %} See all documentation for this here: https://github.com/carolineschnapp/donation Author: Caroline Schnapp Enter below the handle of your link list that contains a first link pointing to your donation product. Then, you're done. {% endcomment %} {% assign linklist_handle = 'donation' %} {% if linklists[linklist_handle].empty? %}

You don't have a link list with handle {{ linklist_handle }}.

{% elsif linklists[linklist_handle].links.first.type != 'product_link' %}

Your {{ linklists[linklist_handle].title }} link list does not contain a link that points to a product.

{% else %} {% assign product = linklists[linklist_handle].links.first.object %} {% comment %} If the product has one variant, we are showing a text box. If the product has more than 1 variant, we show radio buttons for each fixed amount, followed by a text box if we have a variant with price $1. {% endcomment %}

Donation

{% comment %} Determining below if we will need an input box for user to type in an amount. Note: variant.price is in cents! {% endcomment %} {% assign has_variable_donation = false %} {% assign variable_donation_index_in_product = 0 %} {% for variant in product.variants %} {% if variant.price == 100 %} {% assign has_variable_donation = true %} {% assign variable_donation_index_in_product = forloop.index0 %} {% endif %} {% endfor %} {% comment %} Examining the content of the cart, looking for a donation. {% endcomment %} {% assign donation_amount = 0 %} {% assign donation_index = 0 %} {% assign cart_count = 0 %} {% for item in cart.items %} {% if has_variable_donation and item.id == product.variants[variable_donation_index_in_product].id %} {% assign donation_amount = item.quantity %} {% assign donation_index = forloop.index0 %} {% assign cart_count = cart_count | plus: 1 %} {% else %} {% assign cart_count = cart_count | plus: item.quantity %} {% endif %} {% endfor %} {% if product.variants.size > 1 or has_variable_donation == false %} {% assign fixed_amount_in_cart = false %} {% for variant in product.variants %} {% unless has_variable_donation and forloop.index0 == variable_donation_index_in_product %} {% assign is_active = false %} {% for item in cart.items %} {% if item.id == variant.id and is_active == false %} {% assign fixed_amount_in_cart = true %} {% assign is_active = true %} {% endif %} {% endfor %} {% endunless %} {% endfor %} {% if has_variable_donation %} {% endif %} {% else %} {% endif %}
{% comment %} Special font here. {% endcomment %} {{ '//fonts.googleapis.com/css?family=Montserrat' | stylesheet_tag }} {% comment %} Variables for styles. {% endcomment %} {% assign donation_font = 'Montserrat, sans-serif' %} {% assign donation_color_active = '#6bb801' %} {% assign donation_color_inactive = '#cccccc' %} {% assign donation_text_color = '#ffffff' %} {% comment %} Our styles. {% endcomment %} {% endif %}