Magento:将产品添加到购物车以自定义价格 [英] Magento : Add Product to cart with custom price
问题描述
首先,我正在开发自定义价格的扩展,并且在产品页面上有一个输入,此图描述了我所做的事情:
First I am developing an extension for custom price and I have an input on product page, this is an image describes what I've done :
当客户输入他想要的价格并单击添加到购物车"时,必须在产品上加上他添加的价格.
when a customer enters the price he wants and clicks add to cart, the product must be added with that price added by him.
我知道可以在控制器中进行编码,但我不知道如何?
I know that can be coded in the controller but I don't know how?
这是控制器的空类:
<?php
class WebDirect_CustomPrice_savePriceController extends Mage_Core_Controller_Front_Action{
//put your code here
}
任何人都知道添加到购物车按钮的工作方式(代码)
anyone knows how that add to cart button works(code)
推荐答案
您需要为此调用final_price观察器.需要遵循以下步骤:
You need to call final_price observer for it. Need to follow bellow steps:
1在etc/config.xml中添加观察者
1 add Observer in etc/config.xml
<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>
-
模型中的添加方法apply_customprice()
Add method in you model 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;
}
点击下面的类似图标,您可以在其中找到将商品添加到购物车时如何设置自定义价格.
Click on below like where you can find how to set custom price when product added in cart.
这篇关于Magento:将产品添加到购物车以自定义价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!