Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Current Logic (Summary):
Proposed Modifications:
Code Implementation (Summary):
The below code is working pretty good, just doesn't take into account if the very next stock transfer is spoken for and to look ahead to which stock transfer the customer will be able to reserve product on. I have attached the HTML for reference
Sorry here is the updated code we have been using
"
{% assign current_stock_level = product.variants.first.inventory_quantity %}
{% assign backordered_quantity = 0 %}
{% if current_stock_level < 0 %}
{% assign backordered_quantity = current_stock_level | abs %}
{% endif %}
{% assign cumulative_stock = current_stock_level %}
{% assign next_available_date = blank %}
{% assign found_stock = false %}
{% for stock in product.variants.first.incoming_stock %}
{% if backordered_quantity > 0 %}
{% assign cumulative_stock = cumulative_stock | plus: stock.quantity %}
{% if cumulative_stock >= 0 %}
{% assign next_available_date = stock.date %}
{% assign found_stock = true %}
{% break %}
{% else %}
{% assign backordered_quantity = backordered_quantity | minus: stock.quantity %}
{% endif %}
{% endif %}
{% endfor %}
{% if found_stock %}
{% assign formatted_incoming_date = next_available_date | date: "%B %d, %Y" %}
<span style="font-family: 'Lato', sans-serif; font-size: 16px;">Backordered. Estimated restock date: {{ formatted_incoming_date }}.</span>
{% elsif current_stock_level > 0 %}
<span style="font-family: 'Lato', sans-serif; font-size: 16px; color: #228B22;">In stock and ready to ship now.</span>
{% else %}
<span style="font-family: 'Lato', sans-serif; font-size: 16px;">Currently out of stock. Check back soon for updates.</span>
{% endif %}"