Magento - reloadPrice()修改

时间:2015-05-03 17:13:34

标签: javascript php magento

我的客户需要对产品自定义选项进行操作。

使用Magento CE,我创建了一个产品,并在内置的左侧菜单中为其提供了一些自定义选项。"管理产品" > "添加新产品",例如" mm" (毫米)和" mt" (米)

此产品将同时具有无线电选项和​​文本机会输入。

我们说我们有

Radio option B

我们假设用户选择10并在文本字段中输入1,2 * 10 + 0

价格应该更新:

radio value cost * textbox value + base price 

哪个是

reloadPrice()

有没有办法告诉代码取单选按钮的值,将它乘以文本框的值并将其全部加到基本价格上?

我在哪里可以查看产品自定义选项的当前行为?

修改

我看到每当选择一个值时,都会调用function bouncer(arr) { arr = arr.filter(function(x) { console.log(x === true) if(x !== false) { return true; } }); return arr; } 函数。

我想检查两个输入是否都是无线电和文本,然后获取文本的值并将其乘以收音机的值。

是吗?你能指点我一点吗?

2 个答案:

答案 0 :(得分:1)

这有助于我,我希望这也会对你有所帮助

 initialize : function(config){
                this.config = config;
                this.reloadPrice();
                document.observe("dom:loaded", this.reloadPrice.bind(this));

            },
            reloadPrice : function(){
               price = new Number();
                config = this.config;
                skipIds = [];
                skipIds = [];
                relatedword = [];
                relatedvalue = [];
                relatedid = [];
                counter_each=0;
                counter=1;
                first=0;
                areaValue=1;
                submitbutton=true;

                $$('body .product-custom-option').each(function(element){
                    var optionId = 0;
                    element.name.sub(/[0-9]+/, function(match){
                        optionId = match[0];
                    });
                    if (this.config[optionId]) {
                        if (element.type == 'checkbox' || element.type == 'radio') 
                        {
                            if (element.checked) 
                            {
                                if (config[optionId][element.getValue()]) 
                                {
                                    <?php if(Mage::getVersion() >= 1.7): ?>
                                        price += parseFloat(config[optionId][element.getValue()].price);
                                    <?php else: ?>
                                        price += parseFloat(this.config[optionId][selectOption.value]);
                                    <?php endif; ?>  
                                }
                            }
                        }
}

答案 1 :(得分:0)

reloadPrice()不会更新服务器级别的产品价格。实现此产品价格更新的一种方法是实施checkout_cart_product_add_after事件。

  • 您是否在客户端使用javascript详细页面自定义逻辑。将此值分配给product_addtocart_form形式下的某个隐藏变量。更好的方法是保存到会话以减少客户端漏洞,或者您可以找到自己更好的方法。或者仅在Observer方法中实现您的登录。无论你找到什么安全。
  • 重写课程Mage_Checkout_Model_Cart以修改为,

    public function addProduct($productInfo, $requestInfo=null)
    {
     ...
    Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product,'request_data'=>$request));
     ...
    }
    
  • 在您的yourmodule / etc / config.xml中:

    <config>
        ...
        <frontend>
            ...
            <events>
                <checkout_cart_product_add_after>
                    <observers>
                        <unique_name>
                            <class>modulename/observer</class>
                            <method>customPrice</method>
                        </unique_name>
                    </observers>
                </checkout_cart_product_add_after>
            </events>
            ...
        </frontend>
        ...
    </config>
    
  • 然后在yourmodule / Model / Observer.php上创建一个Observer类

    class <namespace>_<modulename>_Model_Observer
    {
        public function customPrice(Varien_Event_Observer $observer)
        {
            // Get the quote item
            $item = $observer->getQuoteItem();
            $request=$observer->getRequestData();
            // Ensure we have the parent item, if it has one
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            // Load the custom price
            $price = "custom price logic";//whatever from your hidden value or by some other mean. 
            // Set the custom price
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            // Enable super mode on the product.
            $item->getProduct()->setIsSuperMode(true);
        }
    

    }

有关详细信息,请查看here