0

I have created a module to change the prices of a product when added to cart, but the module doesn't get to the method.

The observer.php file and the class Zain_ProductLabelPricing_Model is running but the method 'modifyPrice' is not. Can someone guide me how to fix this?

Config.xml

<?xml version="1.0"?>
<config>
    ...
    <global>
        <models>
            <chdispatcher>
                <class>Zain_ProductLabelPricing_Model</class>
            </chdispatcher>
        </models>
    </global>

    <frontend>
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <modify_to_custom_price>
                        <class>chdispatcher/observer</class>
                        <method>modifyPrice</method>
                    </modify_to_custom_price>
                </observers>
            </checkout_cart_product_add_after>
        </events>
    </frontend>
    ...
</config>

Observer.php

<?php
// die(); this is working
class Zain_ProductLabelPricing_Model {
    public function modifyPrice(Varien_Event_Observer $obs) {
        //die(); this is not working
        Mage::log('This worked');
    }
}
0

Your event configuration is looking for the model Zain_ProductLabelPricing_Model_Observer. This is derived from chdispatcher/observer which is translated to: module/model.

Just add _Observer to your class name and place the file in the folder Zain/ProductLabelPricing/Model with the filename Observer.php.

0
0

The class must be named Zain_ProductLabelPricing_Model_Observer

The only reason, why your die() is executed, is that Magento loads Observer.php to look for this observer class. It does not find it, so the next thing that happens is a "class not found" error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.