<p>I had this problem and the cause was that I was doing this in the base template:</p>

<pre><code>{% set cart = craft.commerce.carts.cart %}
</code></pre>

<p>When I should be doing the following:</p>

<pre><code>{% if cart is not defined %}
    {% set cart = craft.commerce.carts.cart %}
{% endif %}
</code></pre>

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

CC BY-SA 4.0
2018-05-16T11:21:11.860Z
2018-05-16T11:21:11.860Z
Rosana Ruiz
<p>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!</p>

<pre><code>&lt;form method="POST"&gt;
     &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
     &lt;input type="hidden" name="redirect" value="store/cart"&gt;
     {{ getCsrfInput() }}
     &lt;span class="{% if cart.getError('couponCode') %}has-error{% endif %}"&gt;
     &lt;input type="text" name="couponCode" class="{% if cart.getError('couponCode') %}has-error{% endif %}" value="{{ cart.couponCode }}" placeholder="{{ "Coupon Code"|t }}"&gt;
     &lt;/span&gt;
     &lt;input type="submit" value="{% if cart.couponCode %}Change{% else %}Apply{% endif %} Coupon"/&gt;
&lt;/form&gt;
</code></pre>

CC BY-SA 3.0
2017-10-04T23:02:59.423Z
What does `cart.getErrors()` return?  Guessing there is a validation error on one of the other cart properties.
Brad Bell
CC BY-SA 3.0
2017-10-05T12:50:36.987Z
`cart.getErrors()` doesn't return anything, at least not in this code.
Darryl Hardin
CC BY-SA 4.0
2018-05-16T10:12:31.193Z
Same issue here. How did you fix it?
Rosana Ruiz
<plugin-craftcommerce>
Using the coupon code from Craft Commerce site
# Using the coupon code from Craft Commerce site

(Asked by: username_0 on 2017-10-04)

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!

     
     
     {{ getCsrfInput() }}

**Tags:** plugin-craftcommerce

> **Comments:**
> **username_1**: What does `cart.getErrors()` return?  Guessing there is a validation error on one of the other cart properties.  
> **username_0**: `cart.getErrors()` doesn't return anything, at least not in this code.  
> **username_2**: Same issue here. How did you fix it?  

---

## 1 answers

### Answer by username_2 on 2018-05-16. Score: 2 | Accepted answer

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.


---

