0

I've override the default.phtml file in for order success mail for dynamic value of storename. The below code will work when we send the order from admin panel but same code is not working when we placed the order the store name is missing on the mail.

Please help where i'm doing mistake.

File location -

/home/top10/public_html/app/design/frontend/Magento/Vendorname/Magento_Sales/templates/email/items/order/default.phtml

    <?php

/** @var $block \Magento\Sales\Block\Order\Email\Items\DefaultItems */

/** @var $_item \Magento\Sales\Model\Order\Item */
$_item = $block->getItem();
$_order = $_item->getOrder();
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();


    if ($_order->getShippingMethod() == 'customerpickup_customerpickup') {

        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $connection = $resource->getConnection();
        $order_id = $_order->getIncrementId();
        $sql = "SELECT `name` FROM `stores` WHERE `store_id` = (select store_id from clickncollect where order_id = '".$order_id."')";
        $result=$connection->fetchOne($sql);
        $store_name = "Click and Collect From ".$result;
    }else{
        $store_name = "";
    }
    ?>
16
  • remove ) on this line ` $store_name = "Click and Collect From ".$result);` Oct 15, 2019 at 10:30
  • yes removed but not working
    – Satish V
    Oct 15, 2019 at 10:31
  • In else part can you give some static text and check it like else{ $store_name = "test"; } Oct 15, 2019 at 10:33
  • else part is working fine if shipping method is different
    – Satish V
    Oct 15, 2019 at 10:38
  • store name is not a problem, then check within your your if condition and check with your query result. Oct 15, 2019 at 10:41

1 Answer 1

0

Get store name from order

$store_name = $_order->getStore()->getName();
if($store_name){
   $store_name= "Click and Collect From ".$store_name;
}
4
  • I want store name from my custom table 'store'
    – Satish V
    Oct 15, 2019 at 12:10
  • print $sql in log and run in your DB / compare it with admin order and check what is missing there Oct 15, 2019 at 13:09
  • if i send mail from admin panel it will work. when i placed that only time store name not coming
    – Satish V
    Oct 16, 2019 at 10:03
  • update question with $sql in both case it will help better to solve it Oct 16, 2019 at 10:04

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.