Modifying the product.liquid asset via API

oferp
Shopify Partner
2 0 0

Hi,

I'm trying to modify the product.liquid asset in the templates section.

I call the API but when I look at the product.liquid in the web interface I see the value was erased.

Any idea?

                

 $params = array
                (
                    "asset"=>array
                    (
                        "key"=>"templates/product.liquid",
                        "value"=>'{% include 'product' %}\n{% include 'test_shopify' %}'
                        
                    )
                );

                $sc->call('PUT','/admin/themes/'.$themeId.'/assets.json?asset[key]=templates/product.liquid&theme_id='.$themeId,$params);
                

 

0 Likes
Chris_Saunders
Shopify Staff
Shopify Staff
582 0 48

What do you mean the value was erased? Was your information not properly sent to shopify or did the template get completely blanked out?

One thing I am noticing here is that your templates value looks a little fishy. You are using single quotes with single quotes within the string, which shouldn't even be valid.

"value"=>'{% include 'product' %}\n{% include 'test_shopify' %}'

Should be

"value" => "{% include 'product' %}\n{% include 'test_shopify' %}"

Also, I don't know if \n is valid or not. Are you able to use HEREDOC or something similar? Or perhaps just have a bunch of template files on disk that you load up and send the results of reading that file over instead? One advantage is it moves all those gross bits out of your source code.

0 Likes
oferp
Shopify Partner
2 0 0

Yep,

That was the problem :)

Thanks!

0 Likes
rahulevince
New Member
2 0 0

Hello Chris,

 

Can you help me with the product templates modify by asset API?

 

I need to put "call for price" button on product detail page for the product which has zero price. Can you help me with that or any other documentation? 

 

I am creating an custom app which provide this facility when "Enable Call for Price" from setting. 

0 Likes