Magento 2: Data printed in Controller but display null in observer
-
16-04-2021 - |
문제
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);
해결책
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]);
제휴하지 않습니다 magento.stackexchange