We are working on a Shopify store using the Tinker theme. I need to implement a bottle deposit calculation for liquor sales in British Columbia (BC). My current code (generated by AI) is unstable and causing several issues.
Current Problems:
- Missing/Incorrect Properties: Line items for liquor are not correctly carrying properties[_deposit] or properties[_containers_per_unit]. This causes the sync script to "guess," resulting in missing or duplicated deposits.
- Unstable Sync Triggers: The script currently listens to button clicks or uses update.js via variant IDs. This results in:
- Deleted items being "added back" by the script.
- Discrepancies between the Cart (hidden) and Checkout (visible).
- Single items being split into multiple lines.
Proposed Solution/Requirements:
- Configuration (theme.liquid):
Place the window.BC_DEPOSIT_SYNC configuration in the , specifically after {{ content_for_header }} and before the sync script.
{%- assign deposit_product = all_products['bottle-deposit'] -%}
<script>
window.BC_DEPOSIT_SYNC = {
depositHandle: "bottle-deposit",
variantIdByValue: {
{% if deposit_product %}
{% for v in deposit_product.variants %}
"{{ v.option1 | strip }}": {{ v.id }}{% unless forloop.last %},{% endunless %}
{% endfor %}
{% endif %}
}
};
</script>
<script defer src="{{ 'bottle-deposit-sync.js' | asset_url }}"></script>
- Product Form Updates (buy-buttons.liquid):
Clean up duplicate property inputs. Only one set of _deposit and _containers_per_unit hidden inputs should exist, updating dynamically with the variant picker.
- Sync Script Logic (bottle-deposit-sync.js):
The goal for the script is:
- Calculate deposits based strictly on line item properties.
- Automatically reduce/remove deposits when the parent item is removed.
- Use a fetch interceptor (patching window.fetch) to trigger a re-sync after any /cart/add.js, change.js, or update.js call.
We are working on a Shopify store using the Tinker theme. I need to implement a bottle deposit calculation for liquor sales in British Columbia (BC). My current code (generated by AI) is unstable and causing several issues.
Current Problems:
Proposed Solution/Requirements:
- Configuration (theme.liquid):
<script> window.BC_DEPOSIT_SYNC = { depositHandle: "bottle-deposit", variantIdByValue: { {% if deposit_product %} {% for v in deposit_product.variants %} "{{ v.option1 | strip }}": {{ v.id }}{% unless forloop.last %},{% endunless %} {% endfor %} {% endif %} } }; </script> <script defer src="{{ 'bottle-deposit-sync.js' | asset_url }}"></script>Place the window.BC_DEPOSIT_SYNC configuration in the , specifically after {{ content_for_header }} and before the sync script.
{%- assign deposit_product = all_products['bottle-deposit'] -%}
Clean up duplicate property inputs. Only one set of _deposit and _containers_per_unit hidden inputs should exist, updating dynamically with the variant picker.
The goal for the script is: