Solved

Adding IF statements for the "add to cart" function

bakyboy
Excursionist
78 0 2

Hey, 
I have 2 products of the same thing. one used with 2 images (1 picture and one gif) for the hover effect
and another one used with one image only (for another purpose on the home page)

(if its possible) I want to code an if statement that if a customer adds two of the same product then the cart knows its the same product so it doesn't add twice of the same.

can someone help me with the code and where specifically to add it? 

Accepted Solution (1)
Not applicable

This is an accepted solution.

Hi @bakyboy 

Sorry for making you wait. 

It's Done.

In the featured-product.liquid file, the product-form.liquid is included and all changes are made there. We put the check on the main page and added the class.
Can you check it please?

View solution in original post

Replies 16 (16)

Not applicable

Hi @bakyboy 

Aibek is here from Speedimize.io

Welcome to Shopify Community. 

Create only one product and add two images. One of them is normal, and the other is a gif. And this will be the default product that will be shown for the product page. On the main page you will use the same product, only you need to put a check
{% if template == "index" %}
//Home page product
{% endif %}
If there is a {% for%} loop, then you will need to put {% break %} on the first pass. That is, put it at the end. For example as below:

{% for image in product.images %}
<li class="grid__item {{ product_thumbnail_width }} product-single__thumbnails-item">
  <a
     href="{{ image.src | img_url: product_image_size, scale: product_image_scale }}"
     class="text-link product-single__thumbnail product-single__thumbnail--{{ section.id }}"
     {% if enable_zoom %}data-zoom="{{ image.src | img_url: product_image_zoom_size, scale: product_image_scale }}"{% endif %}>
    <img class="product-single__thumbnail-image" src="{{ image.src | img_url: product_thumb_size, scale: product_image_scale }}" alt="{{ image.alt | escape }}">
  </a>
</li>
{% if template == 'index' %}
    {% break %}
{% endif %}
{% endfor %}

We don't know which is your theme and structure of it. Therefore, the above example is from the debut theme. Most likely, the section on your main page is called featured-product. liquid. All changes will need to be made in this file. In the example above, the loop will only run once and only one image will be shown. This is the simplest logic for solving your problem.

 

bakyboy
Excursionist
78 0 2

Hey, im using the showcase theme
and for some reason I can't seem to find the right section to copy this code to

bakyboy
Excursionist
78 0 2

please help

Not applicable

Hey @bakyboy 

Thanks for getting back to me.

Sorry for the delayed response due to the weekend. 

Can you please give us a staff account or grant access through Shopify partners?

Showcase is not a free theme, so we can't help you without this.

Hope for your cooperation. 

bakyboy
Excursionist
78 0 2

Hey, what email should I sent the staff invite to?

bakyboy
Excursionist
78 0 2

I sent the invite to this mail hello@speedimize.io



Not applicable

Hi @bakyboy 

You can send an invite here: hello@speedimize.io 

 

bakyboy
Excursionist
78 0 2

yes, do I did

Not applicable

Can you please send me the URL of your shop? 

I think it's will be better to use Shopify Partners. 

bakyboy
Excursionist
78 0 2
bakyboy
Excursionist
78 0 2
Not applicable

Request is sent.

bakyboy
Excursionist
78 0 2

approved

bakyboy
Excursionist
78 0 2

Hey, have you looked at it? done anything?

Not applicable

This is an accepted solution.

Hi @bakyboy 

Sorry for making you wait. 

It's Done.

In the featured-product.liquid file, the product-form.liquid is included and all changes are made there. We put the check on the main page and added the class.
Can you check it please?

bakyboy
Excursionist
78 0 2

hey I was a bit off these days, thank you very much! looks great 

appreciate it