Problem with If control tag

nhathao93
New Member
1 0 0

Hi guys,

I am working on this code.

{% assign USVendors = "
customcat,
gearment,
melaninfulcc
" %}

{% assign USVendorArray = USVendors | split: "," %}
{% assign ProductVendor = product.vendor | downcase | strip %}
{% assign USShipped = false %}

{% for item in USVendorArray %}
	{% if item == ProductVendor %}
		{% assign USShipped = true %}
		{% break %}
	{% endif %}
{% endfor %}

{{ USShipped }}

 

Product.type is 'CustomCat' in this case. I expect USShipped to return as "true" but it always shows "false". But if I use "contains" instead of "==" in the if line, it works perfectly.

{% for item in USVendorArray %}
	{% if item contains ProductVendor %}
		{% assign USShipped = true %}
		{% break %}
	{% endif %}
{% endfor %}

 

I don't understand where I did wrong. Can you please help me?

 

0 Likes
hardik355
Shopify Partner
184 16 24

Hi  

You doing good but issue is operator so = is assignment operator. And ‘==’ operator checks whether the two given operands are equal or not. 

 

If helpful then please Like and Accept Solution.
For Design, Development and custom changes Hire Me.
Skype: live:hardikradadiya355
Thanks

 

0 Likes

If you want to check "==" you need to bring 2 variants to the same data type. You just need to do this, it will work fine:
{% for item in USVendorArray %}
{% assign check = item | downcase | strip %}
{% if check == ProductVendor %}
{% assign USShipped = true %}
{% break %}
{% endif %}
{% endfor %}

LitExtension - #1 Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes