Plugins Magento 2 afterGetSpecialPrice插件获胜';不要更改WEBAPI中的特殊价格
我已经实现了一个自定义magento 2插件,以编程方式更改某些产品的特殊价格。这是一个成功的前端,但仍然在webapi中,我得到了原始的特殊价格 di.xmlPlugins Magento 2 afterGetSpecialPrice插件获胜';不要更改WEBAPI中的特殊价格,plugins,module,magento2,Plugins,Module,Magento2,我已经实现了一个自定义magento 2插件,以编程方式更改某些产品的特殊价格。这是一个成功的前端,但仍然在webapi中,我得到了原始的特殊价格 di.xml <?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectMana
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Vendor\Module\Api\PromotionManagementInterface" type="Vendor\Module\Model\PromotionManagement"/>
<type name="Magento\Catalog\Model\Product">
<plugin name="change_product" type="Vendor\Module\Plugin\Product" sortOrder="1" disabled="false"/>
</type>
</config>
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
<plugin name="change_special_price" type="Vendor\Module\Plugin\Repository"/>
</type>
frontpage结果:$60.00,webapi结果:$70.00(原始特价)
原因可能是什么?根据示例代码,有必要在插件类中使用afterGetList方法 di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Vendor\Module\Api\PromotionManagementInterface" type="Vendor\Module\Model\PromotionManagement"/>
<type name="Magento\Catalog\Model\Product">
<plugin name="change_product" type="Vendor\Module\Plugin\Product" sortOrder="1" disabled="false"/>
</type>
</config>
<type name="Magento\Catalog\Api\ProductRepositoryInterface">
<plugin name="change_special_price" type="Vendor\Module\Plugin\Repository"/>
</type>
Vendor\Module\Plugin\Repository.php
<?php
namespace Vendor\Module\Plugin;
class Repository
{
public function afterGetList(\Magento\Catalog\Api\ProductRepositoryInterface $subject,\Magento\Framework\Api\SearchResults $searchResult) {
foreach ($searchResult->getItems() as $product) {
$product->setData('special_price',60.0000); //custom special price
}
return $searchResult;
}
}