【发布时间】:2019-02-11 00:48:57
【问题描述】:
您好,我如何在类别项目被编辑后呼叫观察员?基本上我有一个观察者列出每个事件中的所有类别,例如保存新类别、删除类别、移动类别位置和编辑类别。
但问题是在编辑类别时,它会检索该类别的最后内容。假设当前类别名称为 Test,我在保存内容时将其更改为 Test 101,生成的文件正在保存,内容为 Test 应该是 Test 101 下面是我的 events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="category_prepare_ajax_response">
<observer name="category-edit" instance="Module\FrontName\Observer\CategoryEditObserver" />
</event>
</config>
这是检索子类别的代码
public function getStoreCategories($storeManager)
{
// $categories = $category_helper->getStoreCategories();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryFactory = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\CollectionFactory');
$categories = $categoryFactory->create()
->addAttributeToSelect('*')
->addAttributeToFilter('level', array('eq' => 2))
->addIsActiveFilter()
->setStore($storeManager->getStore()); //categories from current store will be
}
知道如何检索新编辑的类别吗?我在想编辑事件后回调什么的
【问题讨论】:
标签: magento2 magento-2.0 magento2.2 magento2.1