1

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 %}
      <p>{{ product.title }}</p>
      <p>
        {% if item.onSale %}
            Sale: {{ item.salePrice }} - Was: {{ item.price }}</span>
        {% else %}
          No Sale: {{ item.price }}
        {% endif %}
      </p>
    {% endfor %}
  {% endif %}

  <pre>{{ dump(lineItems) }}</pre>


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

So what happens:

  1. 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.
  2. Once in the cart, via the template above, the returned prices all reflect the base price - no sale price.
  3. 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.

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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