Skip to content

Instantly share code, notes, and snippets.

@andyxmas
Created June 26, 2023 07:45
Show Gist options
  • Save andyxmas/50549e583872d80dcefdb57d7fabb396 to your computer and use it in GitHub Desktop.
Save andyxmas/50549e583872d80dcefdb57d7fabb396 to your computer and use it in GitHub Desktop.
Proposed update to quote_state for blocked customers.
{% comment %}
Based on the data in the quote metafield and the cart
Returns one of the following [states](https://app.shortcut.com/medaire-online/write/IkRvYyI6I3V1aWQgIjYzNDQyYTFkLWMzODItNGUxYi05MDkxLWFiODc4ZWM1M2Y4NyI=)
{% endcomment %}
{% liquid
assign state = 'quote_not_present'
assign quote = customer.metafields.quote.data.value
assign cart_uploaded_at = cart.attributes['Quote Uploaded At'] | plus: 0
assign uploaded_at = quote.uploaded_at | plus: 0
if quote and quote.items != blank
# Blocked customers
if customer.tags contains 'blocked'
if cart_uploaded_at != 0
# There is a quote in the cart, but the customer quote is blocked
assign state = 'quote_in_cart_blocked'
else
# There's no quote in cart, but the customer quote is blocked
assign state = 'quote_blocked'
endif
# Not blocked...
elsif cart_uploaded_at == 0
# There is no quote in the cart, but there is a quote
assign state = 'quote_new'
elsif cart_uploaded_at < uploaded_at
# The quote in the cart is older than the quote on the customer: There's a new quote waiting, should update
assign state = 'quote_updated'
elsif cart_uploaded_at == uploaded_at
# There is a quote in the cart, and its the same as the quote on the customer
assign state = 'quote_in_cart'
elsif cart_uploaded_at > uploaded_at
# The quote in the cart is newer than the quote on the customer: Somethings wrong...
assign state = 'quote_error'
endif
endif
echo state
%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment