猿问

在将产品添加到购物车时更改报价的价格:magento

我想在将产品添加到购物车时更改产品价格。

怎么可能让我知道...


哈士奇WWW
浏览 747回答 3
3回答

月关宝盒

做到这一点的方法是添加一个观察该事件的观察者'sales_quote_add_item':<events>&nbsp; &nbsp; <sales_quote_add_item>&nbsp; &nbsp; &nbsp; &nbsp; <observers>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <priceupdate_observer>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <type>singleton</type>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <class>mymodule/observer</class>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <method>updatePrice</method>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </priceupdate_observer>&nbsp; &nbsp; &nbsp; &nbsp; </observers>&nbsp; &nbsp; </sales_quote_add_item></events>观察者应具有执行以下操作的方法:public function updatePrice($observer) {&nbsp; &nbsp; $event = $observer->getEvent();&nbsp; &nbsp; $quote_item = $event->getQuoteItem();&nbsp; &nbsp; $new_price = <insert logic>&nbsp; &nbsp; $quote_item->setOriginalCustomPrice($new_price);&nbsp; &nbsp; $quote_item->save();}

30秒到达战场

您可以使用观察者类来收听checkout_cart_product_add_after,并使用产品的“超级模式”为报价项设置自定义价格。在您的/app/code/local/{namespace}/{yourmodule}/etc/config.xml中:<config>&nbsp; &nbsp; ...&nbsp; &nbsp; <frontend>&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; &nbsp; &nbsp; <events>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <checkout_cart_product_add_after>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <observers>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <unique_event_name>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <class>{{modulename}}/observer</class>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <method>modifyPrice</method>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </unique_event_name>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </observers>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </checkout_cart_product_add_after>&nbsp; &nbsp; &nbsp; &nbsp; </events>&nbsp; &nbsp; &nbsp; &nbsp; ...&nbsp; &nbsp; </frontend>&nbsp; &nbsp; ...</config>然后在/app/code/local/{namespace}/{yourmodule}/Model/Observer.php中创建一个Observer类&nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; class <namespace>_<modulename>_Model_Observer&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public function modifyPrice(Varien_Event_Observer $obs)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $customPrice = Mage::getSingleton(’core/session’)->getCustomPriceCalcuation(); // Provide you price i have set with session&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $p = $obs->getQuoteItem();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $p->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }

慕田峪4524236

坚果汤。文件:/app/etc/modules/config.xml<?xml version="1.0" encoding="UTF-8"?><config>&nbsp; <modules>&nbsp; &nbsp; <Ajax_ProductAdjust>&nbsp; &nbsp; &nbsp; <codePool>local</codePool>&nbsp; &nbsp; &nbsp; <active>true</active>&nbsp; &nbsp; </Ajax_ProductAdjust>&nbsp; </modules></config>文件:/app/code/local/Ajax/ProductAdjust/etc/config.xml<?xml version="1.0"?>&nbsp; &nbsp; &nbsp; <config>&nbsp; &nbsp; &nbsp; &nbsp;<modules>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<Ajax_ProductAdjust>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<version>1.0.1</version>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</Ajax_ProductAdjust>&nbsp; &nbsp; &nbsp; &nbsp;</modules>&nbsp; &nbsp; &nbsp; &nbsp;<global>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<models>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<Ajax_ProductAdjust>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<class>Ajax_ProductAdjust_Model</class>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</Ajax_ProductAdjust>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</models>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<events>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <sales_quote_add_item>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <observers>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<ajax_productadjust_model_observer>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <type>singleton</type>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <class>Ajax_ProductAdjust_Model_Observer</class>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <method>updatePrice</method>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</ajax_productadjust_model_observer>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</observers>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </sales_quote_add_item>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </events>&nbsp; &nbsp; &nbsp; </global>&nbsp; &nbsp; &nbsp;</config>文件:/app/code/local/Ajax/ProductAdjust/Model/Observer.php<?php//Notesclass Ajax_ProductAdjust_Model_Observer{&nbsp; &nbsp; public function _construct()&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; public function getNewPrice()&nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; //Your new functionality here&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; &nbsp; $newprice = "";&nbsp; &nbsp; &nbsp; &nbsp; return $newprice;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp;public function updatePrice( Varien_Event_Observer $observer )&nbsp;&nbsp; &nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; $event = $observer->getEvent();&nbsp; &nbsp; &nbsp; &nbsp; $quote_item = $event->getQuoteItem();&nbsp; &nbsp; &nbsp; &nbsp; $new_price = $this->getNewPrice();&nbsp; &nbsp; &nbsp; &nbsp; $quote_item->setOriginalCustomPrice($new_price);&nbsp; &nbsp; &nbsp; &nbsp; $quote_item->save();&nbsp; &nbsp; &nbsp; }&nbsp;}干杯,
随时随地看视频慕课网APP
我要回答