Skip to content

issues with bottle deposit calculations #2043

@dortheaz

Description

@dortheaz

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:
  1. 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>
  1. 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.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions