扩展了 \Magento\Catalog\Model\Product模块 报错信息 Type Error occurred when creating object
通过事件监听。
参考
https://webkul.com/blog/magento2-set-custom-price-of-product/
把
<code>class CustomPrice implements ObserverInterface { public function execute(MagentoFrameworkEventObserver $observer) { $item = $observer->getEvent()->getData('quote_item'); $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); $price = 100; //set your price here $item->setCustomPrice($price); $item->setOriginalCustomPrice($price); $item->getProduct()->setIsSuperMode(true); } }</code>
改成你自己的逻辑代码就行。
<code>class CustomPrice implements ObserverInterface { public function execute(MagentoFrameworkEventObserver $observer) { $product = $observer->getEvent()->getData('product'); 。。。 } }</code>