Created
November 2, 2020 19:11
-
-
Save AugustMiller/1742fb0b87e8fcead3fcb5aaee51e80b to your computer and use it in GitHub Desktop.
Increment or decrement quantity of product in cart
This file contains 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
{% set incrementable = incrementable ?? true %} | |
{% set decrementable = decrementable ?? true %} | |
<div class="line-item__controls"> | |
{% if incrementable or decrementable %} | |
<div class="line-item__quantity"> | |
<form | |
method="POST" | |
data-ajax> | |
{{ csrfInput() }} | |
{{ actionInput('commerce/cart/update-cart') }} | |
{{ hiddenInput("lineItems[#{lineItem.id}][qty]", lineItem.qty - 1) }} | |
<button | |
class="line-item__quantity-button line-item__quantity-button--decrement" | |
type="submit" | |
title="Remove One" | |
{% if not decrementable %}disabled{% endif %}>−</button> | |
</form> | |
<div class="line-item__quantity-readout">{{ lineItem.qty }}</div> | |
<form | |
method="POST" | |
data-ajax> | |
{{ csrfInput() }} | |
{{ actionInput('commerce/cart/update-cart') }} | |
{{ hiddenInput("lineItems[#{lineItem.id}][qty]", lineItem.qty + 1) }} | |
<button | |
class="line-item__quantity-button line-item__quantity-button--increment" | |
type="submit" | |
title="Add One" | |
{% if not incrementable %}disabled{% endif %}>+</button> | |
</form> | |
</div> | |
{% endif %} | |
<div class="line-item__remove"> | |
<form | |
method="POST" | |
data-ajax> | |
{{ csrfInput() }} | |
{{ actionInput('commerce/cart/update-cart') }} | |
{{ hiddenInput("lineItems[#{lineItem.id}][remove]", 'Yes, please!') }} | |
<button | |
class="line-item__remove-button" | |
type="submit">Remove</button> | |
</form> | |
</div> | |
</div> |
This file contains 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
{# Info about your line item... #} | |
{# Then, include the partial (optionally passing `incrementable` or `decrementable` booleans, depending on whether it's possible to modify quantity) #} | |
{% include '__blocks/line-item__controls' with { | |
lineItem: lineItem | |
} only %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment