This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% comment %} | |
| In this case, the merchant, for UX testing would like subscription products to be on top of the cart drawer, followed by the one-time purchase items. | |
| Usually, we would have two forloops inside the markup, with their distinctive conditions in order to sort the different products. | |
| Instead, we will prepare all the necessary data beforehand and loop over the more explicit arrays in the markup. | |
| For performance, in place of two for loops over the items, we only have one. In more critical use-cases, several ms are gained. | |
| For readability and maintenability, we have a DRY declaration at defined location which makes it more maintainable and readable. | |
| Note: The arrays are constructed using a for loop, a common pattern that works pretty well ! | |
| {% endcomment %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% # Cart filters testing %} | |
| {% liquid | |
| # A small liquid snippet to compare the two new filters from what was possible before | |
| # See https://shopify.dev/docs/api/liquid/filters/cart-filters for reference | |
| # Quite redundant in my opinion as this is basically sugar but maybe they'll find their audience | |
| assign targetProduct = all_products['product-handle'] | |
| assign productId = targetProduct.id | |
| assign targetVariant = targetProduct.selected_or_first_available_variant | |
| assign variantId = targetVariant.id |
NewerOlder