在magento中获取自定义输入的值 [英] Get a value of a custom input in magento

查看:69
本文介绍了在magento中获取自定义输入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我在bello中描述的magento产品视图页面中创建了一个输入:

First I've created an input in magento product view page as described bello :

我做过一个观察者,因此它在添加到购物车时(checkout_cart_product_add_after事件)设置了自定义价格,这是该功能:

and I've done a observer so it set a custom price when add to cart (checkout_cart_product_add_after event) and this is the function :

public function applyCustomPrice(Varien_Event_Observer $observer) {

        /* @var $item Mage_Sales_Model_Quote_Item */
        $item = $observer->getQuoteItem();
        if ($item->getParentItem()) {
            $item = $item->getParentItem();
        }

        $item->setCustomPrice(599.5);
        $item->setOriginalCustomPrice(599.5);
        $item->getProduct()->setIsSuperMode(true);

    }

如您所见,我已经输入了"599.5",并且可以正常工作. 现在,我想要的是在产品视图页面中向观察者获取该输入的值,这就是输入:

as u can see I've put "599.5" and that worked. Now what I want is to get value of that input in product view page to the observer this is the input :

<div class="price-box">

    <span id="product-price-27" class="price">
        <input id="CP_ID" class="input-text price" type="text" onmouseout="onChangeCP(this);" value="2699.9900" style="width:auto;" name="custom_price"></input>
    </span>
    <input id="custom_price_total" type="hidden" value="2699.9900" name="custom_price_total"></input>

</div>

有人知道该怎么做吗?

推荐答案

如果您能够成功使用checkout_cart_product_add_after事件调用观察者,请在下面的代码中编写以更改产品价格

If you are able success to call your observer using checkout_cart_product_add_after event then write below code to change price of product

 $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        $new_price = Mage::app()->getRequest()->getPost('pricecustom');

其中 pricecustom 是我的隐藏变量

        if(!is_null($new_price))
        {
            $quote_item->setCustomPrice($new_price);
            $quote_item->setOriginalCustomPrice($new_price);
            $quote_item->getProduct()->setIsSuperMode(true);
        }

让我知道您是否有任何疑问

Let me know if you have any query

这篇关于在magento中获取自定义输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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