Magento 2: Data printed in Controller but display null in observer
-
16-04-2021 - |
Domanda
Controller file
$collection = $this->investmentFactory->create()->load($id);
$collection->getData();
// echo '<pre/>';
// print_r($collection->getData());
$this->eventManager->dispatch('trigger_order_place',['collection', $collection]);
exit;
In this observer file data is null
$collection = $observer->getEvent()->getCollection();
var_dump($collection);
Soluzione
I think the problem is that you must pass key => value and you pass like two array items. Here is from core code.
$this->eventManager->dispatch(
'sales_order_payment_capture',
['payment' => $payment, 'invoice' => $invoice]
);
Try changing to
$this->eventManager->dispatch('trigger_order_place',['collection' => $collection]);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange