0

From my magento2 backend i created 2 website. 1st default website xxxx.com 2nd website is yyyy.com. In my sales order email template, added

$_order = $_item->getOrder();
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$product = $_objectManager->get('Magento\Catalog\Model\Product')->load($_item->getProductId());
echo $product->getProductUrl();

When i place order from 2nd website (i.e.,) yyyy.com, product Base URL getting xxxx.com

Please let me know how to get base URL for multiwebsite sales email template.

Priya
  • 589
  • 5
  • 29

4 Answers4

0

try this.

$product = $_objectManager->get('Magento\Catalog\Model\Product')->setStoreId($your_store_id)->load($_item->getProductId());
Rakesh Varma
  • 2,226
  • 10
  • 18
  • i tried this too. still geting same base_url. For my clarification let me know how to find "$your_store_id" ? – Priya Oct 30 '19 at 12:35
  • https://www.rakeshjesadiya.com/get-default-store-id-of-website-by-website-id-magento-2/ follow this to get default store id based on website id. – Rakesh Varma Oct 30 '19 at 12:39
  • i had tried this, but still getting default Base URL – Priya Oct 31 '19 at 12:06
0

Access your DB and browse your store table. you will get the complete picture what store do you want.

Then Try this:

$product = $_objectManager->get('Magento\Catalog\Model\Product')->setStoreId($your_store_id)->load($_item->getProductId());
Ali Hussain
  • 167
  • 7
0

In case that you are using template from Magento_Sales/templates/email/items/order/default.html

You can simply do:

$_item->getProduct()->getProductUrl()

this works fine in my fresh Magento 2.3.3

Note from me: Please don't use Object Manager, especially in templates.

underser
  • 550
  • 3
  • 11
0

I tried may ways but i got only Default base url. So 1st i get store BaseUrl and and get UrlKey, then i combined.

$base_url = $_item->getStore(2)->getBaseUrl();
$product_key = $_item->getProduct()->getUrlKey(); 
echo $base_url . $product_key; 
Priya
  • 589
  • 5
  • 29