【问题标题】:Altering the price of configurable product更改可配置产品的价格
【发布时间】:2012-03-29 08:20:01
【问题描述】:

我正在寻找一种方法来为可配置产品的价格添加价值所有必需的选项都被选中。我需要匹配所选简单产品的完整 SKU,因此每个选项的价格不合适

我已经使用 SKU - 价格对构建了一个 JSON,现在正在寻找一个 JS 事件来干净利落地完成任务,并在添加到购物车和结帐阶段保留新价格

提前感谢您的任何见解

【问题讨论】:

    标签: javascript magento product configurable


    【解决方案1】:

    您可以使用观察者类收听checkout_cart_product_add_after,并使用产品的“超级模式”针对报价项设置自定义价格。

    在您的 /app/code/local/{namespace}/{yourmodule}/etc/config.xml 中:

    <config>
        ...
        <frontend>
            ...
            <events>
                <checkout_cart_product_add_after>
                    <observers>
                        <unique_event_name>
                            <class>{{modulename}}/observer</class>
                            <method>modifyPrice</method>
                        </unique_event_name>
                    </observers>
                </checkout_cart_product_add_after>
            </events>
            ...
        </frontend>
        ...
    </config>
    

    然后在 /app/code/local/{namespace}/{yourmodule}/Model/Observer.php 创建一个 Observer 类

    class <namespace>_<modulename>_Model_Observer
    {
        public function modifyPrice(Varien_Event_Observer $obs)
        {
            // Get the quote item
            $item = $obs->getQuoteItem();
            // Ensure we have the parent item, if it has one
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            // Load the custom price
            $price = $this->_getPriceByItem($item);
            // Set the custom price
            $item->setCustomPrice($price);
            $item->setOriginalCustomPrice($price);
            // Enable super mode on the product.
            $item->getProduct()->setIsSuperMode(true);
        }
    
        protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
        {
            $price;
    
            //use $item and maybe your json object to determine the correct price
    
            return $price;
        }
    
    }
    

    这将处理来自后端的价格变化。至于javascript,对不起,我不太确定!

    【讨论】:

    • 接受了您的回答,因为我设法实现了 JS 部分 :) 不过还有一个问题 - 当匿名客户将产品添加到购物车然后登录商店时更新自定义价格,因此必须重新计算价格,你对此有什么想法吗?
    • 你的JS是怎么做的?我很想看看你的解决方案是什么。至于登录问题,客户登录时是否会重置价格?也许有更好的事件可以听,或者你可以观察登录事件并迭代每个项目。
    • 我已经解决了sales_quote_merge_after 事件中的定价问题,这是匿名客户购物车转换为登录客户的地方。至于 JS,我已经为管理值对构建了一个完整的选项 ID JSON,收集了完整的简单 SKU 并为最终价格增加了价值(再次来自 JSON)
    猜你喜欢
    • 1970-01-01
    • 2013-11-03
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    相关资源
    最近更新 更多