0

I need to create a link like

http:// base_url / storeId / productID?q

how do I correctly specify storeId / productID.

0

You 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.

| improve this answer | |
  • Thanks, but I didn’t understand what to do. I'm a newbie. I need that in one link the id of the store and the product is transmitted. more examples are possible. Thanks again. – Anya Moroz Aug 7 '19 at 13:13
  • I have a module that inserts a button on the product page and by clicking on this button I need to go to a third-party application. The link that the button should transmit to the third-party application storeId and productId. – Anya Moroz Aug 7 '19 at 13:42
  • @AnyaMoroz based off of this comment, you can in that case grab store ID by \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

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.