Magento:将产品添加到购物车以自定义价格 [英] Magento : Add Product to cart with custom price

查看:59
本文介绍了Magento:将产品添加到购物车以自定义价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我正在开发自定义价格的扩展,并且在产品页面上有一个输入,此图描述了我所做的事情:

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>

  1. 模型中的添加方法apply_customprice()

  1. 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.

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_ -_module_development_in_magento/customizing_magento_using_event-observer_method

这篇关于Magento:将产品添加到购物车以自定义价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆