Archive

Archive for June, 2010

Fixing “Catalog Price Rules” cart issue in Magento 1.4.1.0

June 29th, 2010

After recently upgrading one of my stores running Magento Commerce I found out the the latest version (at this time 1.4.1.0) had a major bug. Don’t want to sound too harsh, but unfortunately Magento’s support was again awful – there have been one thread on the forum and one issue in their bug tracking system for a while now (almost two weeks if not more) and still no update, although as I said the bug has quite an impact – even tweet’ed the problem to @magento and haven’t gotten any reply (again it’s not the first time). Yes, the product is free, yes it’s open source, but I think a bit of transparency and better communication could come to their advantage.

Bug details/behavior

So, updated from 1.4.0.1 to 1.4.1.0, everything looks fine, catalog price rules are being applied in the catalog (categories and product pages), but when adding the product to the cart the quote item price was the regular price not the special one.

Solution/Fix

After a few hours playing with the rules, observer and other core elements I found the problem. A big “thank you” goes to “myself” who posted the second comment for the issue mentioned above. The problem was within the CatalogRule Observer, when fetching the ID of the Customer Group. Here’s how to fix it:

1 – create the following folders in your Magento distro: app/code/local/Mage/CatalogRule/Model
2 – copy app/code/core/Mage/CatalogRule/Model/Observer.php to app/code/local/Mage/CatalogRule/Model
3 – open the new/copied file and go to line 105. Change this code:

        if ($observer->hasCustomerGroupId()) {
            $gId = $observer->getEvent()->getCustomerGroupId();
        } elseif ($product->hasCustomerGroupId()) {
            $gId = $product->hasCustomerGroupId();
        } else {
            $gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        }

to:

        if ($observer->hasCustomerGroupId()) {
            $gId = $observer->getEvent()->getCustomerGroupId();
        } elseif ($product->hasCustomerGroupId()) {
            $gId = $product->getCustomerGroupId();
        } else {
            $gId = Mage::getSingleton('customer/session')->getCustomerGroupId();
        }

To be more precise, you have to change hasCustomerGroupId to getCustomerGroupId on line 105.

You can now enjoy your store again!

Magento