1

I got this code off of Craft Commerce, I had caught an error on the site previously so I'm thinking there might be an error here? I've put it in my file but when I input anything in the form I don't have any response of any kind. I don't get an error message or success message, it just redirects back to the cart and the pricing also remains exactly the same. Thanks!

<form method="POST">
     <input type="hidden" name="action" value="commerce/cart/updateCart">
     <input type="hidden" name="redirect" value="store/cart">
     {{ getCsrfInput() }}
     <span class="{% if cart.getError('couponCode') %}has-error{% endif %}">
     <input type="text" name="couponCode" class="{% if cart.getError('couponCode') %}has-error{% endif %}" value="{{ cart.couponCode }}" placeholder="{{ "Coupon Code"|t }}">
     </span>
     <input type="submit" value="{% if cart.couponCode %}Change{% else %}Apply{% endif %} Coupon"/>
</form>
3
  • What does cart.getErrors() return? Guessing there is a validation error on one of the other cart properties. – Brad Bell Oct 4 '17 at 23:02
  • cart.getErrors() doesn't return anything, at least not in this code. – Darryl Hardin Oct 5 '17 at 12:50
  • Same issue here. How did you fix it? – Rosana Ruiz May 16 '18 at 10:12
2

I had this problem and the cause was that I was doing this in the base template:

{% set cart = craft.commerce.carts.cart %}

When I should be doing the following:

{% if cart is not defined %}
    {% set cart = craft.commerce.carts.cart %}
{% endif %}

The reason behind is that the cart object in cart.getError function was always being initialized instead of getting the cart from the POST response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.