Adding IF statements for the "add to cart" function

Solved
bakyboy
Excursionist
49 0 1

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? 

0 Likes
Speedimize
Shopify Partner
289 46 122

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.

 

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
bakyboy
Excursionist
49 0 1

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

0 Likes
bakyboy
Excursionist
49 0 1

please help

0 Likes
Speedimize
Shopify Partner
289 46 122

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. 

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
0 Likes
bakyboy
Excursionist
49 0 1

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

0 Likes
bakyboy
Excursionist
49 0 1

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



0 Likes
Speedimize
Shopify Partner
289 46 122

Hi @bakyboy 

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

 

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
bakyboy
Excursionist
49 0 1

yes, do I did

0 Likes
Speedimize
Shopify Partner
289 46 122

Can you please send me the URL of your shop? 

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

We Speedimize your store
Have a problem with speed performance, send me email here: hello@speedimize.io


If our advice was helpful please LIKE or ACCEPT SOLUTION
0 Likes