Solved

Metafield view API redirects to product page

akad
Excursionist
14 1 0

Hello all,

My client has 2 stores, one for production and one for development.

I am trying to get 'harmonized_system_code' from Storefront API, example:

https://{{store}}/products/{{ product.handle }}?variant={{ product.id }}&view=metafields

 

I am getting the right data from production store, but in development store I'm getting a JSON parse error since the request is getting the page's source code instead of a JSON code ( I am doing this to ajaxify adding to cart )

 

While debugging I found out that the link redirects to the product's page.

any idea?

 

Thanks in advance

Accepted Solution (1)

Jason
Shopify Expert
11194 225 2285

This is an accepted solution.

I'm not 100% sure on the need here but let's walk through that url. It gives clues.

 

this...

 

https://{{store}}/products/{{ product.handle }}?variant={{ product.id }}&view=metafields

... is built up with liquid.

 

We can see that it will make url like:

 

https://some-totally-fake-shop.com/products/some-handle?variant=123456&view=metafields

 

  1. So first up it's weird that this url is using a querystring parameter with the name of variant, but is using the product id. odd.
  2. the next part "&view=metafields" shows that the theme expects there to be an alternate product in place called "product.metafields.liquid". if it's missing, it will just show the default product template.

 

Does the dev shop have that alt template in place?

Got an example to share?

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 2 (2)

Jason
Shopify Expert
11194 225 2285

This is an accepted solution.

I'm not 100% sure on the need here but let's walk through that url. It gives clues.

 

this...

 

https://{{store}}/products/{{ product.handle }}?variant={{ product.id }}&view=metafields

... is built up with liquid.

 

We can see that it will make url like:

 

https://some-totally-fake-shop.com/products/some-handle?variant=123456&view=metafields

 

  1. So first up it's weird that this url is using a querystring parameter with the name of variant, but is using the product id. odd.
  2. the next part "&view=metafields" shows that the theme expects there to be an alternate product in place called "product.metafields.liquid". if it's missing, it will just show the default product template.

 

Does the dev shop have that alt template in place?

Got an example to share?

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
akad
Excursionist
14 1 0

I got the key problem from your reply, sir.

Thank you, the dev store's products do not have metafields, and that's what missing and why it redirects to the product page.

 

thank you