首先,我正在开发定制价格的扩展,我在产品页面上有一个输入,这是一个描述我所做的图像:

当客户输入他想要的价格并点击添加到购物车时,产品必须加上他添加的价格.
我知道可以在控制器中编码,但我不知道怎么做?
这是控制器的空类:
<?php
class WebDirect_CustomPrice_savePriceController extends Mage_Core_Controller_Front_Action{
//put your code here
}
Run Code Online (Sandbox Code Playgroud)
谁都知道添加到购物车按钮的工作方式(代码)
你需要为它调用final_price观察者.需要遵循以下步骤:
1在etc/config.xml中添加Observer
<events>
<catalog_product_get_final_price>
<observers>
<xyz_catalog_price_observer>
<type>singleton</type>
<class>Xyz_Catalog_Model_Price_Observer</class>
<method>apply_customprice</method>
</xyz_catalog_price_observer>
</observers>
</catalog_product_get_final_price>
</events>
Run Code Online (Sandbox Code Playgroud)
在模型中添加方法apply_customprice()
public function apply_customprice($observer)
{
$event = $observer->getEvent();
$product = $event->getProduct();
// ADDD LOGIC HERE to get price added by customer
$product->setFinalPrice($specialPrice); // set the product final price
return $this;
}
Run Code Online (Sandbox Code Playgroud)点击下方,了解如何在购物车中添加产品时设置自定义价格.