Question

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.

Was it helpful?

Solution 4

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; 

OTHER TIPS

try this.

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

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());

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top