<p>After further testing and debugging, it turns out these issues are related to this bug in Commerce:</p>

<p><a href="https://github.com/craftcms/commerce/issues/1206" rel="nofollow noreferrer">https://github.com/craftcms/commerce/issues/1206</a></p>

<p>As per that github issue, it was a Discount with <code>Ignore sales when this discount is applied</code> enabled that was the culprit, but shouldn't be once that bug is fixed.</p>

CC BY-SA 4.0
2020-01-21T05:35:58.827Z
2020-01-21T05:35:58.827Z
Mike
<p>I have an issue where sales and sale pricing seem not to be present in the cart. This is on an ecommerce flow where this was previously all working but I had moved onto other dev work on this site for many weeks, applying Craft and Commerce updates over that time - and have now returned to the ecommerce flow to find this not working.</p>

<p>Craft Pro 3.3.20.1</p>

<p>Commerce 2.2.14</p>

<p>What is happening is that when I have a sale for a given product, the discounted sale price does not appear to be in the cart (Craft returns the base price) and the lineItems do not appear to have any sales in place for a given item. I stripped this back to a barebones template:</p>

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

{% if cart.isEmpty() %}
  Empty
{% else %}
    {% set lineItems = cart.lineItems %}
    {% for item in cart.lineItems %}
      {% set variant = item.purchasable %}
      {% set product = variant.product %}
      &lt;p&gt;{{ product.title }}&lt;/p&gt;
      &lt;p&gt;
        {% if item.onSale %}
            Sale: {{ item.salePrice }} - Was: {{ item.price }}&lt;/span&gt;
        {% else %}
          No Sale: {{ item.price }}
        {% endif %}
      &lt;/p&gt;
    {% endfor %}
  {% endif %}

  &lt;pre&gt;{{ dump(lineItems) }}&lt;/pre&gt;


  itemTotal:{{ dump(cart.itemTotal) }}&lt;br&gt;&lt;br&gt;
  itemSubtotal:{{ dump(cart.itemSubtotal) }}&lt;br&gt;&lt;br&gt;
  total:{{ dump(cart.total) }}&lt;br&gt;&lt;br&gt;
  totalDiscount:{{ dump(cart.totalDiscount) }}&lt;br&gt;&lt;br&gt;
  totalTaxablePrice:{{ dump(cart.totalTaxablePrice) }}&lt;br&gt;&lt;br&gt;
  totalShippingCost:{{ dump(cart.totalShippingCost) }}&lt;br&gt;&lt;br&gt;
  totalSaleAmount:{{ dump(cart.totalSaleAmount) }}&lt;br&gt;&lt;br&gt;
  getTotal():{{ cart.getTotal() }}&lt;br&gt;&lt;br&gt;
  getItemSubtotal():{{ cart.getItemSubtotal() }}&lt;br&gt;&lt;br&gt;
  getItemTotal():{{ cart.getItemTotal() }}&lt;br&gt;&lt;br&gt;
</code></pre>

<p>So what happens:</p>

<ol>
<li>I add a product to the cart which has an applicable sale (I've tested it has one by triple-checking the sale logic in the CP against the product and checking the product details in twig via <code>{% set productSales = product.defaultVariant.getSales() %}</code> to confirm it has applicable sales.</li>
<li>Once in the cart, via the template above, the returned prices all reflect the base price - no sale price.</li>
<li>The <code>sales</code> object has nothing in it from <code>lineItems</code> and <code>item.onSale</code> is <code>false</code> (though I notice <code>lineItems[0].snapshot.onSale</code> is <code>true</code> (but I'm not certain what that is supposed to represent).</li>
</ol>

<p>I'd normally conclude I was doing something wrong, but I believe my code follows the Commerce template examples and was working fine when I last worked on it (awhile back... maybe October).</p>

<p>I wondered if some commerce update has fundamentally changed something about how this should all work but could find no clues in the changelog.</p>

<p>Can anyone confirm there isn't something fundamentally wrong with my cart code above - or has something changed in Commerce? Or could there actually be a bug?</p>

<p><strong>EDIT:</strong> The non-sale (base price) I see in the cart is reflected in the actual order details in the CP.</p>

<craft3><plugin-craftcommerce2><cart>
Commerce 2 Sales Not Present In Cart lineItems
# Commerce 2 Sales Not Present In Cart lineItems

(Asked by: username_0 on 2020-01-20)

I have an issue where sales and sale pricing seem not to be present in the cart. This is on an ecommerce flow where this was previously all working but I had moved onto other dev work on this site for many weeks, applying Craft and Commerce updates over that time - and have now returned to the ecommerce flow to find this not working.
Craft Pro 3.3.20.1
Commerce 2.2.14
What is happening is that when I have a sale for a given product, the discounted sale price does not appear to be in the cart (Craft returns the base price) and the lineItems do not appear to have any sales in place for a given item. I stripped this back to a barebones template:
{% set cart = craft.commerce.carts.cart %}

{% if cart.isEmpty() %}
  Empty
{% else %}
    {% set lineItems = cart.lineItems %}
    {% for item in cart.lineItems %}
      {% set variant = item.purchasable %}
      {% set product = variant.product %}
      {{ product.title }}
      
        {% if item.onSale %}
            Sale: {{ item.salePrice }} - Was: {{ item.price }}
        {% else %}
          No Sale: {{ item.price }}
        {% endif %}
      
    {% endfor %}
  {% endif %}

  {{ dump(lineItems) }}


  itemTotal:{{ dump(cart.itemTotal) }}
  itemSubtotal:{{ dump(cart.itemSubtotal) }}
  total:{{ dump(cart.total) }}
  totalDiscount:{{ dump(cart.totalDiscount) }}
  totalTaxablePrice:{{ dump(cart.totalTaxablePrice) }}
  totalShippingCost:{{ dump(cart.totalShippingCost) }}
  totalSaleAmount:{{ dump(cart.totalSaleAmount) }}
  getTotal():{{ cart.getTotal() }}
  getItemSubtotal():{{ cart.getItemSubtotal() }}
  getItemTotal():{{ cart.getItemTotal() }}

So what happens:

I add a product to the cart which has an applicable sale (I've tested it has one by triple-checking the sale logic in the CP against the product and checking the product details in twig via {% set productSales = product.defaultVariant.getSales() %} to confirm it has applicable sales.
Once in the cart, via the template above, the returned prices all reflect the base price - no sale price.
The sales object has nothing in it from lineItems and item.onSale is false (though I notice lineItems[0].snapshot.onSale is true (but I'm not certain what that is supposed to represent).

I'd normally conclude I was doing something wrong, but I believe my code follows the Commerce template examples and was working fine when I last worked on it (awhile back... maybe October).
I wondered if some commerce update has fundamentally changed something about how this should all work but could find no clues in the changelog.
Can anyone confirm there isn't something fundamentally wrong with my cart code above - or has something changed in Commerce? Or could there actually be a bug?
EDIT: The non-sale (base price) I see in the cart is reflected in the actual order details in the CP.

**Tags:** craft3, plugin-craftcommerce2, cart

---

## 1 answers

### Answer by username_0 on 2020-01-21. Score: 1 | Accepted answer

After further testing and debugging, it turns out these issues are related to this bug in Commerce:

<https://github.com/craftcms/commerce/issues/1206>

As per that github issue, it was a Discount with `Ignore sales when this discount is applied` enabled that was the culprit, but shouldn't be once that bug is fixed.


---

