How can I apply different discount percentages for each brand?

Hey folks,
I need your help again! :slightly_smiling_face:

I need to insert a different discount percentage for each brand.

I tried to insert the code below on my template–product.liquid but doesn’t work.

{% for product in collection.products %}
  {% if product.vendor == "Brand Name" %}
    {% assign discounted_price = product.price | times: 0.9 %}
    <p>Discounted Price: {{ discounted_price | money }}</p>
  {% endif %}
{% endfor %}

Where is the issue?

Please, can you help me???

Thank you so much!

Code seems fine, except that I would use contains instead of ==

Per me understanding, you have to insert this code in 2 files and create additional elsif statement for when no vendors are available, and insert this whole code instead of the original price code.

Look for file such as item-grid or something like that, which would be your product within collection, and then either product-form or product-template, which is your single product.

Code would looks like this:

{% for product in collection.products %}

  {% if product.vendor == "Brand Name" %}
    {% assign discounted_price = product.price | times: 0.9 %}
    <p>Discounted Price: {{ discounted_price | money }}</p>

{% elsif product.vendor == "Other Brand Name" %}
{% assign discounted_price = product.price | times: 0.7 %} 
<p>Discounted Price: {{ discounted_price | money }}</p>

{% else %}
<p> Price: {{ product.price }} </p>

  {% endif %}
{% endfor %}

Hi @kgbfashionista ,

thank you so much for your reply.

I tried to insert you code. The price are correct but I cannot see the items.

Please check the screeshot:

What can I do?

Thank you again

This line:

{% for product in collection.products %}

Is supposed to go at the top, where your product starts, and {% endfor %} is for where your product ends. FOR statement loops through.

Delete these two lines and try again.

I tried to delete these two lines but the code doesn’t work.
Maybe I wronged the code position on the liquid file. I don’t know whats happen :disappointed_face:

Please send the whole code where you tried to paste this.

I try to insert in template–collection.liquid. You can see the code below:

Thank you so much again for your help!

{%- assign limit = section.settings.grid | times: section.settings.rows -%}
{% paginate collection.products by limit %}

    

        {%- assign is_empty_collection = false -%}
        {% case section.settings.grid %}
            {% when 2 %}
            {%- assign grid_item_width = 'two-col-grid' -%}
            {%- assign grid_image_width = '600x600' -%}
            {% when 3 %}
            {%- assign grid_item_width = 'three-col-grid' -%}
            {%- assign grid_image_width = '600x600' -%}
            {% when 4 %}
            {%- assign grid_item_width = 'four-col-grid' -%}
            {%- assign grid_image_width = '600x600' -%}
                {% when 5 %}
                {%- assign grid_item_width = 'five-col-grid' -%}
            {%- assign grid_image_width = '600x600' -%}
                {% when 6 %}
            {%- assign grid_item_width = 'six-col-grid' -%}
            {%- assign grid_image_width = '600x600' -%}
        {% endcase %}
        {%- capture olclasses -%}
            {%- case section.settings.grid -%}
                {%- when 2 -%}
                    {% cycle 'mobileCycle': ' alpha mobile-clear tablet-clear', ' omega' %} wow fadeInUp {% cycle 'animDelay': '', 'delay-1' %}
                {%- when 3 -%}
                    {% cycle 'mobileCycle': ' alpha mobile-clear', '', ' mobile-clear omega', 'alpha', ' mobile-clear', ' omega' %} wow fadeInUp {% cycle 'animDelay': '', 'delay-1', 'delay-2' %}
                {%- when 4 -%}
                    {% cycle 'mobileCycle': ' alpha mobile-clear tablet-clear', '', ' mobile-clear tablet-clear', ' omega' %} wow fadeInUp {% cycle 'animDelay': '', 'delay-1', 'delay-2', 'delay-3' %}
                {%- when 5 -%}
                    {% cycle 'mobileCycle': ' alpha mobile-clear tablet-clear', '', ' mobile-clear tablet-clear', '', ' omega mobile-clear tablet-clear', ' alpha', ' mobile-clear tablet-clear', '', ' mobile-clear tablet-clear', ' omega' %} wow fadeInUp {% cycle 'animDelay': '', 'delay-1', 'delay-2', 'delay-3', 'delay-4' %}
                {%- when 6 -%}
                    {% cycle 'mobileCycle': ' alpha mobile-clear tablet-clear', '', ' mobile-clear', ' tablet-clear', ' mobile-clear', ' omega' %} wow fadeInUp {% cycle 'animDelay': '', 'delay-1', 'delay-2', 'delay-3', 'delay-4', 'delay-5' %}
            {%- endcase -%}
        {%- endcapture -%}
        

            

                {% for product in collection.products %}
                    1. {%-
                               render 'product-grid--indiv-product',
                               liquidObject: product
                           -%}
                    

                {% else %}
                    {% comment %}
                    Add default products to help with onboarding for collections/all only.
                    The onboarding styles and products are only loaded if the
                    store has no products.
                    {% endcomment %}
                    {% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0 %}
                        {% for i in (1..8) %}
                            {%- capture alphaclasses -%}
                                {%- case section.settings.grid -%}
                                {%- when 2 -%}
                                    {% cycle 'alpha', 'omega' %}
                                {%- when 3 -%}
                                    {% cycle ' alpha', '', ' omega' %}
                                {%- when 4 -%}
                                    {% cycle ' alpha', '', '', ' omega' %}
                                {%- when 5 -%}
                                    {% cycle ' alpha', '', '', '', ' omega' %}
                                {%- when 6 -%}
                                    {% cycle ' alpha', '', '', '', '', ' omega' %}
                                {%- endcase -%}
                            {%- endcapture -%}
                            
                                {% render 'product-grid--onboarding' %}
                            

                        {% endfor %}
                    {% else %}
                        {%- assign is_empty_collection = true -%}
                    {% endif %}
                {% endfor %}
            

        

        {% if is_empty_collection %}
        
            

{{ 'collections.general.no_matches' | t }}

        

        {% endif %}
        {% if paginate.pages > 1 %}
            
                {% if section.settings.pagination_type == 'paged_navigation' %}
                {% render 'pagination', paginate: paginate  %}
                {% elsif section.settings.pagination_type == 'infinite_scrolling' %}
                

                    {% if paginate.next %}
                    {{ 'collections.paginate.infinite_scrolling' | t }}
                    {% endif %}
                

                {% else %}
                
                    {% if paginate.next %}
                    {{ 'collections.paginate.load_more' | t }}
                    {% endif %}
                

                {% endif %}
            

        {% endif %}
    

{% endpaginate %}
{% if has_collection_image %}
	
{% endif %}

{% schema %}
{
    "name": {
        "en": "Collection grid"
    },
    "class": "collection-grid-wrapper",
    "settings": [
        {
            "type": "range",
            "id": "grid",
            "min": 2,
            "max": 6,
            "step": 1,
            "label": {
                "en": "Products per row",
                "de": "Produkte pro Zeile",
                "es": "Productos por fila",
                "fr": "Produits par ligne",
                "pt-PT": "Produtos por linha"
            },
            "default": 4
        },
        {
            "type": "range",
            "id": "rows",
            "min": 3,
            "max": 8,
            "step": 1,
            "label": {
                "en": "Rows per page",
                "de": "Zeilen pro Seite",
                "es": "Filas por página",
                "fr": "Nombre de lignes par page",
                "pt-PT": "Linhas por página"
            },
            "default": 3
        },
        {
            "type": "header",
            "content": {
                "en": "Pagination"
            }
        },
        {
            "type": "select",
            "id": "pagination_type",
            "label": {
                "en": "Pagination type",
                "de": "Seitenzählungsart",
                "es": "Tipo de paginación",
                "fr": "Type de pagination",
                "pt-PT": "Tipo de paginação"
            },
            "default": "paged_navigation",
            "options": [
                {
                    "value": "paged_navigation",
                    "label": {
                        "en": "Paged navigation",
                        "de": "Seitennummerierte Navigation",
                        "es": "Navegación por páginas",
                        "fr": "Navigation paginée",
                        "pt-PT": "Navegação paginada"
                    }
                },
                {
                    "value": "infinite_scrolling",
                    "label": {
                        "en": "Infinite scrolling",
                        "de": "Unendliches Scrolling",
                        "es": "Desplazamiento continuo",
                        "fr": "Défilé infini",
                        "pt-PT": "Rolagem infinita"
                    }
                },
                {
                    "value": "load_more",
                    "label": {
                        "en": "Load more button",
                        "de": "Schaltfläche 'Mehr anzeigen'",
                        "es": "Cargar más botones",
                        "fr": "Bouton Charger plus",
                        "pt-PT": "Carregar mais botão"
                    }
                }
            ]
        }
    ],
    "blocks": [
        {
            "name": "Grid card vendor",
            "type": "grid-card-vendor",
            "limit": 1,
            "settings": [
                {
                    "type": "paragraph",
                    "content": "This block determines the position of the product grid item vendor."
                }
            ]
        },
        {
            "name": "Grid card heading",
            "type": "grid-card-title",
            "limit": 1,
            "settings": [
                {
                    "type": "paragraph",
                    "content": "This block determines the position of the product grid item heading."
                }
            ]
        },
        {
            "name": "Grid card price",
            "type": "grid-card-price",
            "limit": 1,
            "settings": [
                {
                    "type": "paragraph",
                    "content": "This block determines the position of the product grid item price."
                }
            ]
        },
        {
            "name": "Grid card swatches",
            "type": "grid-card-swatches",
            "limit": 1,
            "settings": [
                {
                    "type": "paragraph",
                    "content": "This block determines the position of the product grid item swatches."
                }
            ]
        }
    ]
}
{% endschema %}

Looks like you have to do this in other file: product-grid–indiv-product

Send the code from there

Yes, I have!

You can see below!

{% assign crop_setting = settings.product-grid %}
{% assign image_crop = nil %}
{% if crop_setting == "square" %}
    {% assign image_crop = "aspect-ratio--square" %}
{% elsif crop_setting == "tall" %}
    {% assign image_crop = "aspect-ratio--tall" %}
{% elsif crop_setting == "wide" %}
    {% assign image_crop = "aspect-ratio--wide" %}
{% endif %}

First, paste this code anywhere at the beginning & change to your needs.

{% if product.vendor == “Brand Name” %}
{% assign discounted_price = product.price | times: 0.9 %}

{% elsif product.vendor == “Other Brand Name” %}
{% assign discounted_price = product.price | times: 0.7 %}

{% elsif product.vendor == “New Brand Name” %}
{% assign discounted_price = product.price | times: 0.8%}

{% endif %}

Then, change this code:

{% when ‘grid-card-price’ %}

{% if liquidObject.compare_at_price_max > liquidObject.price %}

{{ liquidObject.compare_at_price_max | money }}

{% endif %}

{% if liquidObject.price_varies %}

{{ ‘products.general.from’ | t }}

{{ liquidObject.price_min | money }}

{% else %}

{{ liquidObject.price_min | money }}

{% endif %}

To this:

{% when ‘grid-card-price’ %}

{% if liquidObject.compare_at_price_max > liquidObject.price %}

{{ liquidObject.compare_at_price_max | money }}

{% endif %}

{% if liquidObject.price_varies %}

{{ ‘products.general.from’ | t }}

{{ discounted_price | money }}

{% else %}

{{ discounted_price | money }}

{% endif %}

Let me know how this worked out.

As you can see in the image, I cannot see the price :disappointed_face:

Now I see the original price, but miss the discount price! :tired_face:

Try changing this line as well:

{{ liquidObject.compare_at_price_max | money }}

to

{{ discounted_price | money }}

I do it but it doesn’t work. I attach the code below. :roll_eyes:

{% if product.vendor == "Gucci" %}
{% assign discounted_price = product.price | times: 0.9 %}
{% elsif product.vendor == "Oakley" %}
{% assign discounted_price = product.price | times: 0.7 %}
{% elsif product.vendor == "Persol" %}
{% assign discounted_price = product.price | times: 0.8%}
{% endif %}

{% assign crop_setting = settings.product-grid %}
{% assign image_crop = nil %}
{% if crop_setting == "square" %}
    {% assign image_crop = "aspect-ratio--square" %}
{% elsif crop_setting == "tall" %}
    {% assign image_crop = "aspect-ratio--tall" %}
{% elsif crop_setting == "wide" %}
    {% assign image_crop = "aspect-ratio--wide" %}
{% endif %}

Hard to suggest what else could be done without seeing changes in real life :slightly_smiling_face:

If this wont work, then Ill be lost.

{% if product.vendor == “Gucci” %}
{% assign discounted_price = product.price | times: 0.9 %}
{% elsif product.vendor == “Oakley” %}
{% assign discounted_price = product.price | times: 0.7 %}
{% elsif product.vendor == “Persol” %}
{% assign discounted_price = product.price | times: 0.8%}

{% else %}

{% assign discounted_price = product.price %}
{% endif %}

{% assign crop_setting = settings.product-grid %}
{% assign image_crop = nil %}
{% if crop_setting == “square” %}
{% assign image_crop = “aspect-ratio–square” %}
{% elsif crop_setting == “tall” %}
{% assign image_crop = “aspect-ratio–tall” %}
{% elsif crop_setting == “wide” %}
{% assign image_crop = “aspect-ratio–wide” %}
{% endif %}

{% case settings.hover-effect %}

{% when ‘none’ %}

<a
class=“grid__image”
href=“{{ liquidObject.url}}”
title=“{{ liquidObject.title | escape }}”
tabindex=“-1”

{% if image_crop %}

{% endif %}
{% render ‘responsive-image’ with liquidObject.media[0].preview_image, alt: liquidObject.media[0].alt %}
{% if image_crop %}
{% endif %}

{% when ‘second-image’ %}

{% if liquidObject.media.size > 1 %}

{% else %} {% if image_crop %}
{% endif %} {% render 'responsive-image' with liquidObject.media[0].preview_image, alt: liquidObject.media[0].alt %} {% if image_crop %}
{% endif %}
{% endif %}

{% when ‘zoom’ %}

{% endcase %}

{% for block in section.blocks %}
{% case block.type %}
{% when ‘grid-card-vendor’ %}

{% if liquidObject.vendor %}

{{ liquidObject.vendor }}
{% endif %}

{% when ‘grid-card-title’ %}

{{ liquidObject.title }}

{% when ‘grid-card-price’ %}

{% if liquidObject.compare_at_price_max > liquidObject.price %}

{{ discounted_price | money }}

{% endif %}

{% if liquidObject.price_varies %}

{{ ‘products.general.from’ | t }}

{{ discounted_price | money }}

{% else %}

{{ discounted_price | money }}

{% endif %}

{% assign first_variant = liquidObject.variants[0] %}
{% render ‘unit-price-measurement-grid’, variant: first_variant %}

{% when ‘grid-card-swatches’ %}

{% if settings.show_swatches %} {% for option in liquidObject.options %} {% capture downcased_option %}{{ option | downcase }}{% endcapture %} {% assign option_handle = option | handle %} {% assign option_index = forloop.index0 %} {% assign prod_id = liquidObject.id %} {% assign image_option_name = settings.image_swatch_option | downcase %}

{% if downcased_option == image_option_name %}
{% if liquidObject.variants.size > 1 %}

{% assign values = '' %} {{ option_handle }}

{% for variant in liquidObject.variants %}

{% assign variantID = variant.id %}

{% assign value = variant.options[option_index] %}
{% capture wrapped_value %},{{ value }},{% endcapture %}
{% unless values contains wrapped_value %}

{% if variant.image %}
{% assign image = variant.image | product_img_url: ‘400x’ %}
{% else %}
{% assign image = liquidObject.media[0].preview_image | product_img_url: ‘400x’ %}
{% endif %}

<label
for=“section-{{ section.id }}-swatch-{{ prod_id }}-{{ value | handle }}”
style=“background-color: {{ value | split: ’ ’ | last | handle }}; background-image: url({{ value | handle | append: ‘.png’ | file_url }};)”

{{ value | handle }}

{% capture values %}{{ values }}{{ wrapped_value }}{% endcapture %}
{% endunless %}

{% endfor %}
{% endif %} {% endif %} {% endfor %} {% endif %}

{% endcase %}
{% endfor %}

{% if liquidObject.available %}
{% if liquidObject.compare_at_price_max > discounted_price and settings.sale_badge %}

{{ 'products.general.sale' | t }}
{% endif %} {% elsif settings.sold_out_badge %}
{{ 'products.product.sold_out' | t }}
{% endif %}

I try it but still doesn’t work! :disappointed_face:
If you want I can invite you on my site :wink:

Thank you so much for your help!

Just noticed that there is another file that renders for the products: product-grid–onboarding

Try to apply those changes in there.

I can`t really spend too much time here or on working on other websites, as I do this while at work :grinning_face_with_smiling_eyes:

I do hope that the file above will sort the issue. If not, then I am sorry.

Thank You!