{"id":1447,"date":"2020-12-05T13:00:47","date_gmt":"2020-12-05T13:00:47","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-product-url-for-specific-store-in-magento-2\/"},"modified":"2025-05-22T11:23:47","modified_gmt":"2025-05-22T05:53:47","slug":"get-product-url-for-specific-store-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-product-url-for-specific-store-in-magento-2\/","title":{"rendered":"How to Get Product URL for Specific Store in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Medium to large-sized Magento 2 stores tend to use the multi-store facility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a merchant wants to sell the same products in the USA and in the UK, he\/she would use multi-store for separating the store and product URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As the number of stores increases, it becomes difficult for the admin to get store wise product URL in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This tutorial explains how to&nbsp;get product URL for specific store in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the solution while&nbsp;<a href=\"https:\/\/meetanshi.com\/magento-2-migration-service.html\" target=\"_blank\" rel=\"noreferrer noopener\">migrating to latest Magento 2 version<\/a>&nbsp;or developing custom functionalities for which you need to get the products URL.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Solution to Get Product URL for Specific Store in Magento 2:<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Meetanshi\\Module\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Store\\Model\\StoreManagerInterface;\nuse Magento\\Catalog\\Model\\Product;\nuse Magento\\Catalog\\Api\\ProductRepositoryInterface;\n\nclass Data extends AbstractHelper\n{\n    protected $productModel;\n    protected $productRepository;\n\n    public function __construct(\n        Context $context,\n        Product $productModel,\n        ProductRepositoryInterface $productRepository\n    )\n    {\n        $this->productModel = $productModel;\n        $this->productRepository = $productRepository;\n        parent::__construct($context);\n    }\n\n    public function getProductUrl($productId, $storeId)\n    {\n        $product = $this->productModel->load($productId);\n        $product->setStoreId($storeId);\n        $url = $product->getProductUrl();\n        \/\/ another way to get url\n        $product = $this->productRepository->getById($productId, false, $storeId);\n        $productURL = $product->setStoreId($storeId)->getUrlModel()->getUrlInStore($product, ['_escape' => true]);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Done.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider sharing this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Related Post:&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/get-product-image-url-magento-2\/\">How to Get Product Image URL in Magento 2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Medium to large-sized Magento 2 stores tend to use the multi-store facility. If a merchant wants to sell the same products in the USA and&#8230;<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1447","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1447","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1447"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1447\/revisions"}],"predecessor-version":[{"id":14593,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1447\/revisions\/14593"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1447"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1447"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1447"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}