2

I am working on custom email template layout. In this template.html file I use custom layout handle with custom object variables as shown as below.

{{layout handle="custom_layout_handle" quote=$quote }}

"custom_layout_handle" contains custom phtml file where I try to get quote object but it gives me type of null.

In my send mail class file. I pass variables using DataObject() class too., but it still not working.

Here, I share my code

$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

$vars = [ 'quote' => $quote ];
$transportObject = new DataObject($vars);
$om = \Magento\Framework\App\ObjectManager::getInstance();
$transportBuilder = $om->get('\Magento\Framework\Mail\Template\TransportBuilder');
$state = $om->get('\Magento\Framework\Translate\Inline\StateInterface');

$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;

$builder = $transportBuilder
        ->setFrom(['email'=>"[email protected]", 'name'=>"Main"])
        ->setTemplateOptions(([
            'area' => Area::AREA_FRONTEND,
            'store' => $ruleQuote->getStoreId()
        ]))
        ->setTemplateVars($transportObject->getData());

 $builder->addTo("[email protected]");
    $transport = $builder->setTemplateIdentifier($schedule->getTemplateId(), $storeScope)->getTransport();
    $transport->sendMessage();
    $state->resume();

Thanks.

6
  • check the object of quote you are passing to html have data or null or please update you question with code
    – Mehran
    Dec 26, 2022 at 7:45
  • in same template I pass $quote.getCustomerFirstname(), it gives me proper customer name, but when it comes through layout handler, it passes null object @Mehran Dec 26, 2022 at 8:47
  • you have to pass template variable like this ->setTemplateVars([ 'quote' => $quote ])
    – Mehran
    Dec 26, 2022 at 10:12
  • I tried it so far, still it does not work for me. Dec 26, 2022 at 11:27
  • do you get something from quote in your html file? maybe the quote object your are passing is null
    – Mehran
    Dec 26, 2022 at 12:46

1 Answer 1

1

You need to pass quote_id and load that Quote using quote id.

{{layout handle="custom_layout_handle" quote_id=$quoteId }}
2
  • I also tried this one. It does not work for me. Dec 26, 2022 at 11:36
  • in your phtml file use $block->getQuoteId() to get quote_id Dec 26, 2022 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.