Change var in array

Highlighted
Tourist
16 0 1

Hi,

I have the following code in product template page: 

{% assign productVariants = product.variants %}
Then I go over a list of more products that are in the same collection and I concat to productVariants other products variants.

  {% assign productVariants = productVariants | concat:productListItem.variants %}
 

At the end, I wanted to update "product.variants" but it didn't seem to work, so I thought maybe I can't edit the that var, so I did the following: 

 

{% assign product_edited  = product %}
{% assign product_edited.variants = productVariants %}


But this also didn't work, for some reason which I can't understand, I'm unable to update product_edited.variants, It just stays with the original variants array. 

I made sure productVariants was saved correctly by printing the following : {{ productVariants | json }}

 

0 Likes
Shopify Expert
9869 64 1416

You can not change the properties of the object like this.

{% assign product_edited.variants = productVariants %}

You'd need to approach this in a different way. For example, assigning values into a group of arrays, or just creating an array of index (numbers) that you can use to reference back to your larger master object.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Tourist
16 0 1

Thank you, can you give me a code example ? I'm not sure I understand how to do it 

BTW, I'm doing this as a part of your manual to have more then 100 variations per product. I'm using theme named Ella and several files access the main product.varient , so I was trying to create another var that will look exactly like product but with the extra varients that took from my other products. 

If its not possible and you think I should just change all the scripts that user product.varient to use just the varient var, I can probably achive that as well. 


Thanks.

0 Likes