Shopify Support Request - liquid support for Automatic Discounts to Dawn theme

Shopify Support Request - liquid support for Automatic Discounts to Dawn theme

CluckinAwesome
Tourist
7 1 2

I did some testing and found that our shopify store Automatic Discounts are not able to be referenced via "active_discounts" in our liquid files for the Dawn theme, but this seems to be exposed in other themes. I used the below debugging section in the price.liquid, and main-product.liquid files and found that active_discounts is not able to be referenced.

<div class="discount-debug">
{% if active_discounts %}
<p>Discount detected!</p>
<p>Discount amount: {{ active_discounts.first.amount | money }}</p>
{% else %}
<p>No discount active.</p>
{% endif %}
</div>



Please make this variable accessible so we can simply set a discount on collections/products, and then we could use code similar to the following for price.liquid to display store-wide or collection-wide sales very easily in the Dawn theme's price.liquid file.

{%- liquid
  if use_variant
    assign target = product.selected_or_first_available_variant
  elsif placeholder
    assign target = null
  else
    assign target = product
  endif

  assign compare_at_price = target.compare_at_price
  assign price = target.price | default: 1999
  assign price_min = product.price_min
  assign price_max = product.price_max
  assign available = target.available | default: false
  assign money_price = price | money
  assign money_price_min = price_min | money
  assign money_price_max = price_max | money
  if settings.currency_code_enabled
    assign money_price = price | money_with_currency
    assign money_price_min = price_min | money_with_currency
    assign money_price_max = price_max | money_with_currency
  endif

  if target == product and product.price_varies
    assign money_price = 'products.product.price.from_price_html' | t: price: money_price
  endif
-%}

{%- unless target == null and placeholder == null -%}
  <div
    class="
      price
      {%- if price_class %} {{ price_class }}{% endif -%}
      {%- if available == false %} price--sold-out{% endif -%}
      {%- if compare_at_price and compare_at_price > price and product.quantity_price_breaks_configured? != true %} price--on-sale{% endif -%}
      {%- if compare_at_price and compare_at_price > price and product.quantity_price_breaks_configured? %} volume-pricing--sale-badge{% endif -%}
      {%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
      {%- if show_badges %} price--show-badge{% endif -%}
    "
  >
    <div class="price__container">
      <div class="price__regular">
        {%- if product.quantity_price_breaks_configured? -%}
          {%- if show_compare_at_price and compare_at_price -%}
            {%- unless product.price_varies == false and product.compare_at_price_varies %}
              <span class="visually-hidden visually-hidden--inline">
                {{- 'products.product.price.regular_price' | t -}}
              </span>
              <span>
                <s class="price-item price-item--regular variant-item__old-price">
                  {% if settings.currency_code_enabled %}
                    {{ compare_at_price | money_with_currency }}
                  {% else %}
                    {{ compare_at_price | money }}
                  {% endif %}
                </s>
              </span>
            {%- endunless -%}
          {%- endif -%}
          <span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
          <span class="price-item price-item--regular">
            {{ 'products.product.volume_pricing.price_range' | t: minimum: money_price_min, maximum: money_price_max }}
          </span>
        {%- else -%}
          <span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
          <span class="price-item price-item--regular">{{ money_price }}</span>
        {%- endif -%}
      </div>
      
      <div class="price__sale">
        {%- if compare_at_price and compare_at_price > price -%}
          <span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
          <span>
            <s class="price-item price-item--regular">
              {% if settings.currency_code_enabled %}
                {{ compare_at_price | money_with_currency }}
              {% else %}
                {{ compare_at_price | money }}
              {% endif %}
            </s>
          </span>
        {%- endif -%}

        <span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.sale_price' | t }}</span>
        <span class="price-item price-item--sale price-item--last">
          {{ money_price }}
        </span>

        {%- if active_discounts -%}
          {%- if compare_at_price == blank -%}
            <span class="price-discount">You save {{ active_discounts.first.amount | money }}</span>
          {%- elsif compare_at_price and compare_at_price <= price -%}
            <span class="price-discount">You save {{ active_discounts.first.amount | money }}</span>
          {%- endif -%}
        {%- endif -%}
      </div>

      <small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
        <span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
        <span class="price-item price-item--last">
          <span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
          <span aria-hidden="true">/</span>
          <span class="visually-hidden">&nbsp;{{ 'accessibility.unit_price_separator' | t }}&nbsp;</span>
          <span>
            {%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
              {{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
            {%- endif -%}
            {{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
          </span>
        </span>
      </small>
    </div>

    {%- if show_badges -%}
      {%- if compare_at_price and compare_at_price > price -%}
        <span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
          {{ 'products.product.on_sale' | t }}
        </span>
      {%- elsif active_discounts -%}
        <span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
          {{ 'products.product.on_sale' | t }}
        </span>
      {%- endif -%}
    {%- endif -%}
  </div>
{% endunless %}

 

Reply 1 (1)

tim
Shopify Partner
3911 394 1435

There is https://shopify.dev/docs/api/liquid/objects/cart#cart-discount_applications 

 

there is no global active_discounts variable AFAIK


"active_discounts" in our liquid files for the Dawn theme, but this seems to be exposed in other themes.

 

 

 

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com