【问题标题】:Magento - dynamic pricingMagento - 动态定价
【发布时间】:2014-09-30 23:25:24
【问题描述】:

我创建了一个简单的电子商务应用程序,它根据许多选项计算价格。

价格是根据存储在 MySQL 中的一堆变量在 PHP 中计算出来的。我已将 PHP 编码为使用 jQuery AJAX 进行查询的 Web 服务。

我需要将它集成到使用 Magento 的客户现有电子商务网站中。

我想让客户将我的“动态定价产品”添加到他们的购物车中。我需要能够添加自定义价格以及产品信息(我很高兴在单个隐藏字段中拥有这些信息)。

我熟悉编程(客户端和服务器端,大多数语言),但我一点也不熟悉 Magento。有没有一种简单的方法可以实现这一目标?理想情况下,我会将信息添加到现有表单中。

【问题讨论】:

    标签: magento dynamic product


    【解决方案1】:

    我能想到的最简单的方法是在 magento 中创建一个产品以用作模板。

    然后创建一个观察者

    <events>
        <sales_quote_add_item>
            <observers>
                <priceupdate_observer>
                    <type>singleton</type>
                    <class>mymodule/observer</class>
                    <method>updatePrice</method>
                </priceupdate_observer>
            </observers>
        </sales_quote_add_item>
    </events>
    

    然后在你的观察者方法中你做这样的事情:

    public function updatePrice($observer) {
        $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        $new_price = <insert logic to check if this is the custom product and to get value from ajax>
        $quote_item->setOriginalCustomPrice($new_price);
        $quote_item->save();
    }
    

    (请注意,用户总是可以伪造帖子并更改商品价格)

    Customize Magento using Event/Observer

    【讨论】:

    • 谢谢,这似乎正是我想要的!我知道有人可以“欺骗”该值,但当管理员用户查找它时会重新检查它。
    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多