I need to create a link like
http:// base_url / storeId / productID?q
how do I correctly specify storeId / productID
.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou have to understand that natively, there is no URL constructed like this :
base_url/ storeId/productID?q
About the STORE :
To set store in URL, you can add this : ?___store=storecode
(?+3 underscores)
Example : https://domaine.com/?___store=fr
About the PRODUCT :
You should understand that in Magento, the product page url is constructed like this :
https://domaine.com/catalog/product/view/id/1043
the 1043
is the product id, and Magento Rewrite this URL in a pretty one like this :
https://domaine.com/catalog/sweet-shirt-miroo.html
So you understood, to get your URL as you need, you have to do some stuff to rewrite the native Magento URL to the yours.
I hope it clarified the way.
\Magento\Store\Model\StoreManagerInterface#getStore()#getId()
and the product ID by \Magento\Catalog\Api\Data\ProductInterface#getId()
- you can then do something similar to sprintf('http://my-prefix/%u/%u', $storeId, $productId)
to grab a formatted URL. You'll need to figure out how it is most appropriate to get instances of both classes as we can't help you further with the information you've provided.
– Adam Mellen
Aug 7 '19 at 13:53