3 回答
TA贡献1772条经验 获得超5个赞
做到这一点的方法是添加一个观察该事件的观察者'sales_quote_add_item':
<events>
<sales_quote_add_item>
<observers>
<priceupdate_observer>
<type>singleton</type>
<class>mymodule/observer</class>
<method>updatePrice</method>
</priceupdate_observer>
</observers>
</sales_quote_add_item>
</events>
观察者应具有执行以下操作的方法:
public function updatePrice($observer) {
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = <insert logic>
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
TA贡献1828条经验 获得超6个赞
您可以使用观察者类来收听checkout_cart_product_add_after,并使用产品的“超级模式”为报价项设置自定义价格。
在您的/app/code/local/{namespace}/{yourmodule}/etc/config.xml中:
<config>
...
<frontend>
...
<events>
<checkout_cart_product_add_after>
<observers>
<unique_event_name>
<class>{{modulename}}/observer</class>
<method>modifyPrice</method>
</unique_event_name>
</observers>
</checkout_cart_product_add_after>
</events>
...
</frontend>
...
</config>
然后在/app/code/local/{namespace}/{yourmodule}/Model/Observer.php中创建一个Observer类
<?php
class <namespace>_<modulename>_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs)
{
$customPrice = Mage::getSingleton(’core/session’)->getCustomPriceCalcuation(); // Provide you price i have set with session
$p = $obs->getQuoteItem();
$p->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice);
}
}
TA贡献1875条经验 获得超5个赞
坚果汤。
文件:/app/etc/modules/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Ajax_ProductAdjust>
<codePool>local</codePool>
<active>true</active>
</Ajax_ProductAdjust>
</modules>
</config>
文件:/app/code/local/Ajax/ProductAdjust/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Ajax_ProductAdjust>
<version>1.0.1</version>
</Ajax_ProductAdjust>
</modules>
<global>
<models>
<Ajax_ProductAdjust>
<class>Ajax_ProductAdjust_Model</class>
</Ajax_ProductAdjust>
</models>
<events>
<sales_quote_add_item>
<observers>
<ajax_productadjust_model_observer>
<type>singleton</type>
<class>Ajax_ProductAdjust_Model_Observer</class>
<method>updatePrice</method>
</ajax_productadjust_model_observer>
</observers>
</sales_quote_add_item>
</events>
</global>
</config>
文件:/app/code/local/Ajax/ProductAdjust/Model/Observer.php
<?php
//Notes
class Ajax_ProductAdjust_Model_Observer
{
public function _construct()
{
}
public function getNewPrice()
{
//Your new functionality here
//
$newprice = "";
return $newprice;
}
public function updatePrice( Varien_Event_Observer $observer )
{
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = $this->getNewPrice();
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
}
干杯,
- 3 回答
- 0 关注
- 745 浏览
添加回答
举报