Magento-自定义模块不起作用 [英] Magento - Customized Module not working

查看:58
本文介绍了Magento-自定义模块不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个模块,以在将其添加到购物车时自定义产品价格,但无法正常工作.我正在使用 checkout_cart_product_add_after 方法.

I'm creating a module to customize my products price when adding it to the cart but it's not working. I'm using the checkout_cart_product_add_after method.

我遵循的步骤:

1)在/app/etc/modules 上创建XML( TrediMarketplace_PriceUpdate ),该XML已经出现在Magento界面上( System> Configuration>高级>高级)

1) Create a XML (TrediMarketplace_PriceUpdate) at /app/etc/modules and it's already appearing at the Magento interface (System > Configuration > Advanced > Advanced)

2)创建config.xml:

2) Create the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <TrediMarketplace_PriceUpdate>
            <version>0.0.1</version>
        </TrediMarketplace_PriceUpdate>
    </modules>
    <global>
        <models>
            <tredimarketplace_priceupdate>
                <class>TrediMarketplace_PriceUpdate_Model</class>
            </tredimarketplace_priceupdate>
        </models>
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <tredimarketplace_priceupdate>
                        <class>tredimarketplace_priceupdate/observer</class>
                        <method>priceUpdate</method>                        
                    </tredimarketplace_priceupdate>
                </observers>
            </checkout_cart_product_add_after>
        </events>
    </global>
</config>

文件位于以下路径:/app/code/local/TrediMarketplace/PriceUpdate

3)创建Observer.php:

3) Create the Observer.php:

<?php   
    class TrediMarketplace_PriceUpdate_Model_Observer{
        public function priceUpdate(Varien_Event_Observer $observer){
            // Get the quote item
                $item = $observer->getQuoteItem();
            // Ensure we have the parent item, if it has one
                $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            // Load the custom price
                $price = "300.00";
            // Set the custom price
                $item->setCustomPrice($price);
                $item->setOriginalCustomPrice($price);
            // Enable super mode on the product.
                $item->getProduct()->setIsSuperMode(true);
        }
    }
?>

文件位于以下路径:/app/code/local/TrediMarketplace/PriceUpdate/Model

通过这个步骤,我希望添加到购物车中的所有产品的价格都为$ 300.00(我在模块上固定的值),但这没有发生.

With this steps my expectations are that all products added to the cart appear with $300.00 (value that I fixed on my module) but this is not occurring.

有什么建议吗?

推荐答案

我创建了一个压缩模块及其全部功能.我使用了您的代码段,并将其组装成一个模块.您可能会遇到任何语法问题,但它会起作用.请从此处 https://github.com/lapitspublic/TrediMarketplace_PriceUpdate.git

I have created a compressed module and its fully functional. I used your code snippets and assembled into a module. You might have any syntactical issue but its working. Please clone from here https://github.com/lapitspublic/TrediMarketplace_PriceUpdate.git

这篇关于Magento-自定义模块不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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