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.

  • Could you please specify where exactly you added the code above? – underser Oct 30 '19 at 11:59
  • in my child them/Magento_Sales/templates/email/items/order/default.phtml – Priya Oct 30 '19 at 12:06
0

try this.

$product = $_objectManager->get('Magento\Catalog\Model\Product')->setStoreId($your_store_id)->load($_item->getProductId());
  • 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
  • rakeshjesadiya.com/… 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());
  • i tried above method, still geting default base_url – Priya Oct 31 '19 at 6:37
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.

  • Please let me know, why you are saying not to use "Object Manager"? – Priya Oct 31 '19 at 10:23
  • @Priya you can read about this in magento.stackexchange.com/questions/117098/… – underser Oct 31 '19 at 10:54
  • @Priya does my answer help you? – underser Oct 31 '19 at 12:07
  • Yeah, Thank you – Priya Oct 31 '19 at 12:08
  • But for my Question i did not get answer. – Priya Oct 31 '19 at 12:10
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; 

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.