我想在我向目錄添加新產品或更新任何產品時呼叫一個api,見螢屏截圖。
。對此有什么可能的解決方案嗎?
uj5u.com熱心網友回復:
你可以在事件catalog_product_save_after上使用一個觀察者來解決這個問題。
你需要在你的專案中使用這些檔案:
app/code/Community.com>。
app/code/Company/Module/registration.php:
<?php
declare(strict_types = 1)。
使用 MagentoFrameworkComponentComponentRegistrar;
組件注冊器::register(
ComponentRegistrar::MODULE,
'Company_Module'。
__DIR__.
);
app/code/Company/Module/etc/module.xml:
<?xml version="1.0"? >
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/span>
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">/span>
<module name="Company_Module"/span>/>
</config>/span>
app/code/Company/Module/etc/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="catalog_product_save_after"/span>>
< observer name="company_module_product_save_after"instance="CompanyModuleObserverCatalogProductSaveAfter" />
</event>
</config>
app/code/Company/Module/Observer/Catalog/ProductSaveAfter.php:
<?php
declare(strict_types = 1)。
namespace CompanyModuleObserverCatalog;
使用 MagentoFrameworkEventObserver。
使用 MagentoFrameworkEventObserverInterface。
class ProductSaveAfter implements ObserverInterface
{
/**。
*執行觀察者
*
* @param Observer $observer
* @return void
*/
public function execute()
觀察者$observer。
)。) void {
//你的代碼邏輯在這里,就像:。
$product = $observer->getProduct()。
$productData = $product->getData()。
}
之后從命令列運行bin/magento setup:upgrade來啟用該模塊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/320572.html
標籤:
上一篇:"Invalidrequests[0].updateCells:在googlespreadsheetAPI上使用barchUpdate時,出現"無效欄位
