Solved

Help beginner coder | item.final_price equals item_originalprice ? BUG?

tenaciousone
Tourist
10 0 2

I hope you're having a good day so far! I've been on this for a couple hours now with a good friend of mine, and regardless what we try it returns the price of the sale. It does the same thing in checkout, what I display below is only in the "View Cart" stage before Initiating Checkout.

I started by trying to enable the display discount functionality in cart-template.liquid, and though it works the striked-out price is incorrect.

tenaciousone_0-1623213706150.png

As you can see, the compare price is $10 higher than the price and @ cart screen it doesn't show the correct compare at price ($89.99)

tenaciousone_2-1623213826324.png

Below is the source code:

{%- assign hasDiscount = true -%}
                {%- if item.original_price != item.final_price -%}
                  {%- assign hasDiscount = true -%}
                {%- endif -%}

                <div data-cart-item-price>
                  <dl data-cart-item-price-list>
                    {%- comment -%}
                      Markup template for discount item
                    {%- endcomment -%}
                    <div {% unless hasDiscount %}class="hide" {% endunless %}data-cart-item-discounted-price-group>
                      <dt>
                        <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
                      </dt>
                      <dd>
                        <s data-cart-item-original-price>{{ item.original_price | money }}</s>
                      </dd>
                      <dt>
                        <span class="visually-hidden">{{ 'products.product.sale_price' | f }}</span>
                      </dt>
                      <dd>
                        <span class="order-discount" data-cart-item-final-price>{{ item.final_price | money }}</span>
                      </dd>
                    </div>

                    {%- comment -%}
                      Markup template for regular price item
                    {%- endcomment -%}
                    <div {% if hasDiscount %}class="hide" {% endif %}data-cart-item-regular-price-group>
                      <dt>
                        <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
                      </dt>
                      <dd data-cart-item-regular-price>
                        {{ item.original_price | money }}
                      </dd>
                    </div>

                    {%- comment -%}
                      Markup template for unit price
                    {%- endcomment -%}
                    <div {% unless item.unit_price_measurement %}class="hide" {% endunless %}data-unit-price-group>
                      <dt>
                        <span class="visually-hidden visually-hidden--inline">{{ 'products.product.unit_price_label' | t }}</span>
                      </dt>
                      <dd>
                        <span class="price-unit-price">
                          {%- capture unit_price_separator -%}
                            <span aria-hidden="true">/</span><span class="visually-hidden">{{ 'general.accessibility.unit_price_separator' | t }}&nbsp;</span>
                          {%- endcapture -%}
                          {%- capture unit_price_base_unit -%}
                            {%- if item.unit_price_measurement.reference_value != 1 -%}
                              {{- item.unit_price_measurement.reference_value -}}
                            {%- endif -%}
                            {{ item.unit_price_measurement.reference_unit }}
                          {%- endcapture -%}

                          <span data-unit-price>{{ item.unit_price | money }}</span>{{- unit_price_separator -}}<span data-unit-price-base-unit>{{- unit_price_base_unit -}}</span>
                        </span>
                      </dd>
                    </div>
                  </dl>
                </div>

Any help would be greatly appreciated!

Andrew

 

Accepted Solution (1)

iDoThemes
Trailblazer
207 43 91

This is an accepted solution.

compare_at is not treated as a discount in the same way that an item discounted with a discount code is.  You should something like item.variant.compare_at_price, not original_price in your equation for what you are trying to do.

That said, your code is actually working, but only items using discount codes.

 

You can think of the compare at system as indicating that an item is 'on sale', not 'discounted'.

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line

View solution in original post

Replies 3 (3)

iDoThemes
Trailblazer
207 43 91

This is an accepted solution.

compare_at is not treated as a discount in the same way that an item discounted with a discount code is.  You should something like item.variant.compare_at_price, not original_price in your equation for what you are trying to do.

That said, your code is actually working, but only items using discount codes.

 

You can think of the compare at system as indicating that an item is 'on sale', not 'discounted'.

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line
tenaciousone
Tourist
10 0 2

Sweet, thank you, that worked! What's funny is I think I tried that, I just put it in the wrong line. 

Would I be able to display the same thing in the checkout section? There it shows only the subtotal, too, and if it could work the same way it did in the cart that'd be fantastic. 

iDoThemes
Trailblazer
207 43 91

Modifying checkout.liquid is only available on the plus plan, if you're on that it should be doable.

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line