i use observer on order place . sales_model_service_quote_submit_before when order is place i get order items and each item has a seller id . i get email from seller ids. and now send mail to those seller which has items in this order.

my observer code is

    public function execute(\Magento\Framework\Event\Observer $observer)
            $order = $observer->getData('order');
            $quote = $observer->getData('quote');
            $quoteItems = $quote->getAllVisibleItems();
            $orderData['customerName']=$order->getCustomerFirstname().' '.$order->getCustomerLastname();
            foreach ($quoteItems as $quoteItem){
                if ($quoteItem->getCurrentSellerId() != ""){


            //$this->logger->info(print_r($orderData, true));


            return $this;

public function Seller_mail_method($getOrderParams){
        /* Receiver Detail  */
        $receiverInfo = [
            'name' => 'Reciver Name',
            'email' => $getOrderParams['SellerEmail']

        $store = $this->storeManager->getStore();

        $transport = $this->transportBuilder->setTemplateIdentifier(
            ['area' => 'frontend', 'store' => $store->getId()]
            $receiverInfo['email'], $receiverInfo['name']

        try {
            // Send an email
        } catch (\Exception $e) {
            // Write a log message whenever get errors

my seller_email_template.html code is

{{template config_path="design/email/header_template"}} <!-- pathe of template header-->

    <tr class="email-intro">
            <p class="greeting">{{trans " <b>%customerName</b>," customerName=$customerName|row}}</p>

    <tr class="email-information">

            <table class="email-items">
                {{layout handle="sellers_email_order_items"  area="frontend"}}

{{template config_path="design/email/footer_template"}}

and phtml file code is


echo "testing";

<?php //$_order = $block->getOrder() ?>
<?php if ($items): ?>
    <?php //$_items = $_order->getAllItems(); ?>
    <table class="email-items">
            <th class="item-info">
                <?= /* @escapeNotVerified */  __('Items') ?>
            <th class="item-qty">
                <?= /* @escapeNotVerified */  __('Qty') ?>
            <th class="item-price">
                <?= /* @escapeNotVerified */  __('Price') ?>
        <?php foreach ($items as $item): ?>
       // Here want to set items
            <!--            <tr>-->
<!--                <td>-->
<!--                    --><?//= $item["product"]; ?>
<!--                </td>-->
<!--                <td>-->
<!--                    --><?//= $item["qty"]; ?>
<!--                </td>-->
<!--                <td>-->
<!--                    --><?//= $item["price"]; ?>
<!--                </td>-->
<!--            </tr>-->
        <?php endforeach; ?>
        <tfoot class="order-totals">

<?php endif; ?>

How can set $orderItems in phtm file ? my mail send correctly but now just set content. please guide me .

there is problem in my code how can manage to set orderItems of same sellers. when call mail method these problem will resolve later . But now 1 order 1 item of 1 seller. Thanks

  • Can you please provide some more information about the observer? Which event is used and the complete method. As far as I understand you want to pass data from that observer to the item renderer for transactional emails – HelgeB Apr 9 at 9:23
  • @HelgeB ! i edit my question please review question if you understand . please – HaFiz Umer Apr 9 at 9:44
  • i think may be session use here . to store orderitems in session and get session in phtml . is this suitable or other plz guide me – HaFiz Umer Apr 9 at 9:46

OK, if you send the mail from your observer, it is possible to pass the object to the item renderer template. As far as I can see the passing to seller_email_template.html already works since you use $customerName , so you just have to pass the $orderItems to the item renderer block.

I guess with the following changes you should get the order items in your email:


{{layout handle="sellers_email_order_items"  orderItems=$orderItems area="frontend"}}


<?php $items = $block->getOrderItems();?>
<?php if ($items): ?>

In your observer you should populate the array with the keys you want to access later in the template. I guess you should change the foreach loop like this:

foreach ($quoteItems as $quoteItem){
    if ($quoteItem->getCurrentSellerId() != ""){
        $orderData['productinfo'][] = [
            'name' => $quoteItem->getName(),
            'sku' => $quoteItem->getSku(),
            'qty' => $quoteItem->getQty(),
            'price' => $quoteItem->getPrice()
  • let me try it wait . . . . – HaFiz Umer Apr 9 at 10:11
  • You have also an error where you populate the array, I have updated the answer regarding that error – HelgeB Apr 9 at 10:18
  • HelgeB bro ! error in mail Error filtering template: Codility\VendorOrder\Observer\OrderItemToOrder does not implement BlockInterface My OderItemToOrder.php is not implemented with block interface. <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" label="Email Product List" design_abstraction="custom"> <block class="Codility\VendorOrder\Observer\OrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body> – HaFiz Umer Apr 9 at 10:28
  • my ` Codility\VendorOrder\Observer\OrderItemToOrder` in implemented with ObserverInterface. Thats why <?php $items = $block->getOrderItems();?> not work. how can do that – HaFiz Umer Apr 9 at 10:30
  • Then you need to create a block there you can't use an observer in the layout :-) Just create a simple block which extends \Magento\Framework\View\Element\Template and put that in your layout. – HelgeB Apr 9 at 10:33

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.