0

I am using the products API (rest/V1/products/:sku) and getting back an id for a product.

I'd like to use that to build a URL to the product page - something like

http://my-store.com/index.php/catalog/product/view/id/:id

What is the correct URL?

Note: Direct link to a category works properly:

http://my-store.com/index.php/catalog/category/view/id/:id

One of the custom_attributes returned by the products API is url_key, but I can't seem to get that to work either:

[10] => stdClass Object ( [attribute_code] => url_key [value] => zoltan-gym-tee-l-blue )

http://my-store.com/zoltan-gym-tee-l-blue doesn't work (with or without .html suffix).

I wonder if this is a bug in the products API, because the real url key does not include attribute information - i.e., the URL

http://my-store.com/zoltan-gym-tee.html does work. (But note that this is not the URL key - the url key is "zoltan-gym-tee-l-blue".)

  • Should use a user friendly SEO url- url key of product. For example: http://my-store.com/product-url-key. – Khoa TruongDinh Jul 18 '17 at 4:17
  • Tried that too - updated the question to show it. – Scott C Wilson Jul 18 '17 at 10:49
  • 1
    How about my-store.com/zoltan-gym-tee-l-blue.html – PY Yick Jul 18 '17 at 10:51
  • Nope. That didn't work either. Or product/zoltan-gym-tee-l-blue with or without .html. – Scott C Wilson Jul 18 '17 at 10:54
  • Did you try to reindex database? – Khoa TruongDinh Jul 18 '17 at 11:15
0

The answer is,

http://my-store.com/index.php/catalog/product/view/id/:id

is indeed the correct URL. However, this will not work if the product does not have the Visibility setting (in Admin->Products->Catalog->edit product) set so that "Catalog" is included in the value (e.g. "Catalog" or "Catalog,Search").

Note that once this has been done, PY Yick's comment that you should be able to use use http://my-store.com/zoltan-gym-tee-l-blue.html (i.e. http://my-store.com/product-url-key.html) is correct - provided ".html" is the configured suffix set in Admin->Stores->Configuration->Catalog->SEO->Product URL Suffix.

The Magento team says they have a backlog item to add URL to the Products API, so hopefully this improvement will be made soon.

| improve this answer | |
0

This FOSS Module might help.

It overwrites the router and redirects exact SKU matches to the product

https://github.com/karliuka/m2.ProductSkuRedirect

So you would have link like example.com/1337 if your SKU is 1337

There is also this one which uses a specific route

https://github.com/kodbruket/magento2-gotosku

Here the link is example.com/gotosku/?sku=1337

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.