pass array from php file to phtml? The 2019 Stack Overflow Developer Survey Results Are In Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manaralayout handle not working in custom emailProgramatically Sending Transactional Emails Doesn't Include ProductsLocaly made php to magento directory- magento 2Set custom price of product when adding to cart code not workingwhich phtml file is use for New Order Confirmation Template for Guest/Seller?How to change the email template depending on shipping method?Magento 2: How to edit existing Order without cancel?Add “Tax amount” to totals in “New order” email templateRequest for quote and checkout at same timeHow to send a purchase email to the suppliers manually by clicking a button on order detail page in Magento 2?

Using dividends to reduce short term capital gains?

Identify 80s or 90s comics with ripped creatures (not dwarves)

ELI5: Why do they say that Israel would have been the fourth country to land a spacecraft on the Moon and why do they call it low cost?

Make it rain characters

Why doesn't a hydraulic lever violate conservation of energy?

Does Parliament need to approve the new Brexit delay to 31 October 2019?

Drawing vertical/oblique lines in Metrical tree (tikz-qtree, tipa)

Simulating Exploding Dice

Loose spokes after only a few rides

Is an up-to-date browser secure on an out-of-date OS?

Why don't hard Brexiteers insist on a hard border to prevent illegal immigration after Brexit?

Is there a writing software that you can sort scenes like slides in PowerPoint?

How did the audience guess the pentatonic scale in Bobby McFerrin's presentation?

Do working physicists consider Newtonian mechanics to be "falsified"?

Would an alien lifeform be able to achieve space travel if lacking in vision?

The following signatures were invalid: EXPKEYSIG 1397BC53640DB551

What happens to a Warlock's expended Spell Slots when they gain a Level?

Mortgage adviser recommends a longer term than necessary combined with overpayments

Are there continuous functions who are the same in an interval but differ in at least one other point?

Does Parliament hold absolute power in the UK?

For what reasons would an animal species NOT cross a *horizontal* land bridge?

What can I do if neighbor is blocking my solar panels intentionally?

University's motivation for having tenure-track positions

Button changing its text & action. Good or terrible?



pass array from php file to phtml?



The 2019 Stack Overflow Developer Survey Results Are In
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manaralayout handle not working in custom emailProgramatically Sending Transactional Emails Doesn't Include ProductsLocaly made php to magento directory- magento 2Set custom price of product when adding to cart code not workingwhich phtml file is use for New Order Confirmation Template for Guest/Seller?How to change the email template depending on shipping method?Magento 2: How to edit existing Order without cancel?Add “Tax amount” to totals in “New order” email templateRequest for quote and checkout at same timeHow to send a purchase email to the suppliers manually by clicking a button on order detail page in Magento 2?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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(MagentoFrameworkEventObserver $observer)

$orderData=array();
$order = $observer->getData('order');
$quote = $observer->getData('quote');
$quoteItems = $quote->getAllVisibleItems();
$orderData['customerName']=$order->getCustomerFirstname().' '.$order->getCustomerLastname();
foreach ($quoteItems as $quoteItem)
if ($quoteItem->getCurrentSellerId() != "")

$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][]=$quoteItem->getName();
$orderData['productinfo'][]=$quoteItem->getSku();
$orderData['productinfo'][]=$quoteItem->getQty();
$orderData['productinfo'][]=$quoteItem->getPrice();



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

$this->Seller_mail_method($orderData);

return $this;



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

$store = $this->storeManager->getStore();
$TemplateParameter=[
'customerName'=>$getOrderParams['customerName'],
'orderItems'=>$getOrderParams['productinfo']
];

$transport = $this->transportBuilder->setTemplateIdentifier(
'seller_order_email_template'
)->setTemplateOptions(
['area' => 'frontend', 'store' => $store->getId()]
)->addTo(
$receiverInfo['email'], $receiverInfo['name']
)->setTemplateVars(
$TemplateParameter
)->setFrom(
'general'
)->getTransport();

try
// Send an email
$transport->sendMessage();
catch (Exception $e)
// Write a log message whenever get errors
$this->logger->critical($e->getMessage());




my seller_email_template.html code is



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

<table>
<tr class="email-intro">
<td>
<p class="greeting">trans " <b>%customerName</b>," customerName=$customerName</p>

</td>
</tr>
<tr class="email-information">
<td>

<table class="email-items">
<tbody>
layout handle="sellers_email_order_items" area="frontend"
</tbody>
</table>
</td>
</tr>
</table>

template config_path="design/email/footer_template"


and phtml file code is



<?php

echo "testing";



?>
<?php //$_order = $block->getOrder() ?>
<?php if ($items): ?>
<?php //$_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items') ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty') ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price') ?>
</th>
</tr>
</thead>
<?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">

</tfoot>
</table>
<?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










share|improve this question
























  • 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

















1















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(MagentoFrameworkEventObserver $observer)

$orderData=array();
$order = $observer->getData('order');
$quote = $observer->getData('quote');
$quoteItems = $quote->getAllVisibleItems();
$orderData['customerName']=$order->getCustomerFirstname().' '.$order->getCustomerLastname();
foreach ($quoteItems as $quoteItem)
if ($quoteItem->getCurrentSellerId() != "")

$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][]=$quoteItem->getName();
$orderData['productinfo'][]=$quoteItem->getSku();
$orderData['productinfo'][]=$quoteItem->getQty();
$orderData['productinfo'][]=$quoteItem->getPrice();



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

$this->Seller_mail_method($orderData);

return $this;



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

$store = $this->storeManager->getStore();
$TemplateParameter=[
'customerName'=>$getOrderParams['customerName'],
'orderItems'=>$getOrderParams['productinfo']
];

$transport = $this->transportBuilder->setTemplateIdentifier(
'seller_order_email_template'
)->setTemplateOptions(
['area' => 'frontend', 'store' => $store->getId()]
)->addTo(
$receiverInfo['email'], $receiverInfo['name']
)->setTemplateVars(
$TemplateParameter
)->setFrom(
'general'
)->getTransport();

try
// Send an email
$transport->sendMessage();
catch (Exception $e)
// Write a log message whenever get errors
$this->logger->critical($e->getMessage());




my seller_email_template.html code is



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

<table>
<tr class="email-intro">
<td>
<p class="greeting">trans " <b>%customerName</b>," customerName=$customerName</p>

</td>
</tr>
<tr class="email-information">
<td>

<table class="email-items">
<tbody>
layout handle="sellers_email_order_items" area="frontend"
</tbody>
</table>
</td>
</tr>
</table>

template config_path="design/email/footer_template"


and phtml file code is



<?php

echo "testing";



?>
<?php //$_order = $block->getOrder() ?>
<?php if ($items): ?>
<?php //$_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items') ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty') ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price') ?>
</th>
</tr>
</thead>
<?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">

</tfoot>
</table>
<?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










share|improve this question
























  • 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













1












1








1








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(MagentoFrameworkEventObserver $observer)

$orderData=array();
$order = $observer->getData('order');
$quote = $observer->getData('quote');
$quoteItems = $quote->getAllVisibleItems();
$orderData['customerName']=$order->getCustomerFirstname().' '.$order->getCustomerLastname();
foreach ($quoteItems as $quoteItem)
if ($quoteItem->getCurrentSellerId() != "")

$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][]=$quoteItem->getName();
$orderData['productinfo'][]=$quoteItem->getSku();
$orderData['productinfo'][]=$quoteItem->getQty();
$orderData['productinfo'][]=$quoteItem->getPrice();



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

$this->Seller_mail_method($orderData);

return $this;



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

$store = $this->storeManager->getStore();
$TemplateParameter=[
'customerName'=>$getOrderParams['customerName'],
'orderItems'=>$getOrderParams['productinfo']
];

$transport = $this->transportBuilder->setTemplateIdentifier(
'seller_order_email_template'
)->setTemplateOptions(
['area' => 'frontend', 'store' => $store->getId()]
)->addTo(
$receiverInfo['email'], $receiverInfo['name']
)->setTemplateVars(
$TemplateParameter
)->setFrom(
'general'
)->getTransport();

try
// Send an email
$transport->sendMessage();
catch (Exception $e)
// Write a log message whenever get errors
$this->logger->critical($e->getMessage());




my seller_email_template.html code is



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

<table>
<tr class="email-intro">
<td>
<p class="greeting">trans " <b>%customerName</b>," customerName=$customerName</p>

</td>
</tr>
<tr class="email-information">
<td>

<table class="email-items">
<tbody>
layout handle="sellers_email_order_items" area="frontend"
</tbody>
</table>
</td>
</tr>
</table>

template config_path="design/email/footer_template"


and phtml file code is



<?php

echo "testing";



?>
<?php //$_order = $block->getOrder() ?>
<?php if ($items): ?>
<?php //$_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items') ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty') ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price') ?>
</th>
</tr>
</thead>
<?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">

</tfoot>
</table>
<?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










share|improve this question
















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(MagentoFrameworkEventObserver $observer)

$orderData=array();
$order = $observer->getData('order');
$quote = $observer->getData('quote');
$quoteItems = $quote->getAllVisibleItems();
$orderData['customerName']=$order->getCustomerFirstname().' '.$order->getCustomerLastname();
foreach ($quoteItems as $quoteItem)
if ($quoteItem->getCurrentSellerId() != "")

$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][]=$quoteItem->getName();
$orderData['productinfo'][]=$quoteItem->getSku();
$orderData['productinfo'][]=$quoteItem->getQty();
$orderData['productinfo'][]=$quoteItem->getPrice();



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

$this->Seller_mail_method($orderData);

return $this;



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

$store = $this->storeManager->getStore();
$TemplateParameter=[
'customerName'=>$getOrderParams['customerName'],
'orderItems'=>$getOrderParams['productinfo']
];

$transport = $this->transportBuilder->setTemplateIdentifier(
'seller_order_email_template'
)->setTemplateOptions(
['area' => 'frontend', 'store' => $store->getId()]
)->addTo(
$receiverInfo['email'], $receiverInfo['name']
)->setTemplateVars(
$TemplateParameter
)->setFrom(
'general'
)->getTransport();

try
// Send an email
$transport->sendMessage();
catch (Exception $e)
// Write a log message whenever get errors
$this->logger->critical($e->getMessage());




my seller_email_template.html code is



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

<table>
<tr class="email-intro">
<td>
<p class="greeting">trans " <b>%customerName</b>," customerName=$customerName</p>

</td>
</tr>
<tr class="email-information">
<td>

<table class="email-items">
<tbody>
layout handle="sellers_email_order_items" area="frontend"
</tbody>
</table>
</td>
</tr>
</table>

template config_path="design/email/footer_template"


and phtml file code is



<?php

echo "testing";



?>
<?php //$_order = $block->getOrder() ?>
<?php if ($items): ?>
<?php //$_items = $_order->getAllItems(); ?>
<table class="email-items">
<thead>
<tr>
<th class="item-info">
<?= /* @escapeNotVerified */ __('Items') ?>
</th>
<th class="item-qty">
<?= /* @escapeNotVerified */ __('Qty') ?>
</th>
<th class="item-price">
<?= /* @escapeNotVerified */ __('Price') ?>
</th>
</tr>
</thead>
<?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">

</tfoot>
</table>
<?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







magento2 event-observer email-templates phtml getarray






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 9 at 11:40









HelgeB

3,2181323




3,2181323










asked Apr 9 at 8:06









HaFiz UmerHaFiz Umer

4319




4319












  • 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

















  • 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
















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





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





@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





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










1 Answer
1






active

oldest

votes


















1














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:



seller_email_template.html:



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


items.phtml:



<?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() != "")
$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][] = [
'name' => $quoteItem->getName(),
'sku' => $quoteItem->getSku(),
'qty' => $quoteItem->getQty(),
'price' => $quoteItem->getPrice()
];







share|improve this answer

























  • 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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

    – HaFiz Umer
    Apr 9 at 10:28












  • my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

    – HelgeB
    Apr 9 at 10:33











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269319%2fpass-array-from-php-file-to-phtml%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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:



seller_email_template.html:



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


items.phtml:



<?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() != "")
$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][] = [
'name' => $quoteItem->getName(),
'sku' => $quoteItem->getSku(),
'qty' => $quoteItem->getQty(),
'price' => $quoteItem->getPrice()
];







share|improve this answer

























  • 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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

    – HaFiz Umer
    Apr 9 at 10:28












  • my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

    – HelgeB
    Apr 9 at 10:33















1














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:



seller_email_template.html:



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


items.phtml:



<?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() != "")
$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][] = [
'name' => $quoteItem->getName(),
'sku' => $quoteItem->getSku(),
'qty' => $quoteItem->getQty(),
'price' => $quoteItem->getPrice()
];







share|improve this answer

























  • 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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

    – HaFiz Umer
    Apr 9 at 10:28












  • my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

    – HelgeB
    Apr 9 at 10:33













1












1








1







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:



seller_email_template.html:



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


items.phtml:



<?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() != "")
$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][] = [
'name' => $quoteItem->getName(),
'sku' => $quoteItem->getSku(),
'qty' => $quoteItem->getQty(),
'price' => $quoteItem->getPrice()
];







share|improve this answer















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:



seller_email_template.html:



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


items.phtml:



<?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() != "")
$userdetail=$this->userFactory->create()->load($quoteItem->getCurrentSellerId());
$orderData['SellerEmail']=$userdetail->getEmail();
$orderData['productinfo'][] = [
'name' => $quoteItem->getName(),
'sku' => $quoteItem->getSku(),
'qty' => $quoteItem->getQty(),
'price' => $quoteItem->getPrice()
];








share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 9 at 10:22

























answered Apr 9 at 10:09









HelgeBHelgeB

3,2181323




3,2181323












  • 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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

    – HaFiz Umer
    Apr 9 at 10:28












  • my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

    – HelgeB
    Apr 9 at 10:33

















  • 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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

    – HaFiz Umer
    Apr 9 at 10:28












  • my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

    – HelgeB
    Apr 9 at 10:33
















let me try it wait . . . .

– HaFiz Umer
Apr 9 at 10:11





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






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: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

– HaFiz Umer
Apr 9 at 10:28






HelgeB bro ! error in mail Error filtering template: CodilityVendorOrderObserverOrderItemToOrder 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="CodilityVendorOrderObserverOrderItemToOrder" name="seller_items_block" template="Codility_VendorOrder::email/SellerItems.phtml" /> </body>

– HaFiz Umer
Apr 9 at 10:28














my ` CodilityVendorOrderObserverOrderItemToOrder` in implemented with ObserverInterface. Thats why <?php $items = $block->getOrderItems();?> not work. how can do that

– HaFiz Umer
Apr 9 at 10:30






my ` CodilityVendorOrderObserverOrderItemToOrder` 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 MagentoFrameworkViewElementTemplate and put that in your layout.

– HelgeB
Apr 9 at 10:33





Then you need to create a block there you can't use an observer in the layout :-) Just create a simple block which extends MagentoFrameworkViewElementTemplate and put that in your layout.

– HelgeB
Apr 9 at 10:33

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269319%2fpass-array-from-php-file-to-phtml%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Sum ergo cogito? 1 nng

三茅街道4182Guuntc Dn precexpngmageondP