제품 저장 이벤트 후에 magento 2 내에서 제품에 액세스하려고합니다.
리스너를 구성했습니다.
controller_action_catalog_product_save_entity_after
xml은 다음과 같습니다.
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="controller_action_catalog_product_save_entity_after">
<observer name="wire_products_update" instance="TBS\WireProductsHook\Observer\WireProductsUpdate" />
</event>
</config>
그런 다음 제품을 저장할 때 옵저버 클래스가 호출되지만 저장된 제품에 액세스하는 방법에 대한 정보를 찾을 수 없습니다. 관찰자 클래스는 다음과 같습니다.
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace TBS\WireProductsHook\Observer;
use Magento\Framework\Event\ObserverInterface;
class WireProductsUpdate implements ObserverInterface {
public function execute( \Magento\Framework\Event\Observer $observer ) {
// echos name of event: controller_action_catalog_product_save_entity_after
echo 'name of event: ' . $observer->getEvent()->getName();
// tried using the same method as the save class: <magento>/module-catalog/Controller/Adminhtml/Product/Save.php on line 76
$controller = $observer->getData('controller');
// Fails: Fatal error: Cannot access protected property ...
$product = $controller->initializationHelper->initialize($controller->productBuilder->build($controller->getRequest()));
}
}
/module-catalog/Controller/Adminhtml/Product/Save.php 내 에서 이벤트는 114 행에서 시작됩니다.
$this->_eventManager->dispatch(
'controller_action_catalog_product_save_entity_after',
['controller' => $this]
);
컨트롤러를 인수로 전달합니다. 그러나 이것을 사용하여 제품에 액세스하는 방법을 잘 모르겠습니다.
나는 제품을 구하고 싶다