Fixing “Catalog Price Rules” cart issue in Magento 1.4.1.0
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 not a even an 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!
Thanks for your fix. I came across the same issue.
There’s a little problem with your fix. Price rules for the group “NOT LOGGED IN” are not working. If you change line 105 to the following, everything works as it should be:
$gId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId();
You can also comment out the second elseif part:
if ($observer->hasCustomerGroupId()) {
$gId = $observer->getEvent()->getCustomerGroupId();
//} elseif ($product->hasCustomerGroupId()) {
// $gId = $product->getCustomerGroupId();
} else {
$gId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId();
}
If this works you’re realy da MAAAAAN
Thanks alot! ! you save my life~
Hi,
I have tried it but guess what… I am still using Magento 1.4.0.1 and there is no such exact code in Observer.php so I can’t change it
My problerm remains. I guess the file has been rewritten in version 1.4.1.
To bad because I’m to affraid to upgrade
Yes, 1.4.0.1 is different and everything should work fine on that version. Could you describe your problem? Is it the same as this one? Maybe your cron doesn’t work and rules aren’t applied, maybe you have another rule overwriting this rule, maybe some custom code… I do have other 1.4.0.1 (and 1.3.x.x) stores and they seem to be working fine.
Thank you very much for your research and the fix.
T H A N K Y O U ! ! ! ! !
My site is B2B with loads of discount rules and this has saved the day!
i would like to reproduce this error.
I would like to use “special Price” as “Per Month” price and but have magento add the “regular price” to the cart.
however, i’m using magento 1.3.2.4 and in the file there is only this;
“if ($observer->hasCustomerGroupId()) {
$gId = $observer->getEvent()->getCustomerGroupId();
} else {
$gId = Mage::getSingleton(‘customer/session’)->getCustomerGroupId();
}”
how can i reproduce this error, i tried cutting and pasting the original code you mention but it did not work.
thank you
@Cristi
Hi chris, thanks 4 the reply and sorry mine is late.
My problem is this:
When I create a bundle product, fi:
product A = $ 10
product B = $ 20
Together I give bundle discount of 10%.
So a little math tells us: 10 + 20 = 30 – 10% (3) = 27.
This GOOD price will show up in the detailed page but when a customer adds the bundled product to his cart Magento will charge the normal 30 instead of the discounted bundle price
Hope you get my point.
OK, I see what you mean. Have you tried to replicate the same problem to simple products (or any other type of products)? If this problem only applies to bundles, it might be a problem with that type of products, not with catalog rules.
Another way to test it would be to open Observer.php and see what
print_rshows for$productand$product->getSpecialPrice(). Everything related to catalog rules happens in that file – if the corresponding method is not triggered, there’s a problem with attaching the observer to the correct event or the event is not triggered at all.Another problem I found on the forums was with member groups – sometimes catalog price rules were not applied to “Not logged in” customers, but I wasn’t able to replicate it on my 1.4.0.1 installation.
Hope this helps…
Let me get into both ‘might be’ solutions
Otherwise I seriously have to think about upgrading to 1.4.1 or even better, a fresh install of the newest version.
I’ll get back to you
t.4.y.r.
@Cristi
Hello Cristi, I have this problem too in 1.4.0.1.
I created some catalogue price rules, and they are showing fine in the catalogue. But then suddenly (and this is not daily) when adding such a discounted product to the shopping cart, it is showing the old price…
When I go back and re-apply my price rules, it works fine again.
I noticed this by examining google analytics and searching for products that were added to shopping cart but not bought…
I’m losing customers with this problem – very annoying.
Can you help me out?
I don’t understand why the prices are showing correctly in the catalogue, but not in the shopping cart. Ant today I noticed that (apparently sometimes) the correct price is showing in the catalogue, but not in the product view and the shopping cart…
After applying the rules again, everything is working fine…
I don’t think this is a cron problem, is it?
Ilse, your problem might actually consist of several issues. Make sure you check the following:
- cron is scheduled and running correctly
- re-index everything
- refresh all cache
- if you are using 1.4.1.0 use the patch described in this post.
I had no problems with 1.4.0.1, so you should also check to see if you have any extensions that modify catalog rules or shopping cart rules – if you do, disable them for the moment, and test the store again. If there are no extensions, try a clean install on a staging environment and try to replicate the issue (adding minimal data to the store).
Good luck!
Thanks for the fix! Just started offering fixed discounts to some of my clients and found this error. Everything’s back on track now.
This works in 1.4.1.1 also. Thanks!
I am having problems with Shopping Cart Price Rules, specifically using conditions. I am trying to apply a simple conditional rule and it doesn’t seem to pick up. I tested a coupon code and that actually worked. However, using only conditionals didn’t work at all. I am using 1.4.1.1 and any help would be much appreciated. Thanks!
My first thought is that your conditions are wrong. Try a simple rule like if sku equals some sku of your product, offer 10% discount. save it, go to the frontend, add that product in the cart and check to see if it’s applied. It should be, but if it’s not, make sure you don’t have any extensions overwriting Shopping Cart rules.
Thank you so much.
Great work!
Best Regards
Hi, I can only say TTHHHAAANNNKKK YOU
Thanks, this solution works perfect…. But we i use catalogue pricerules, these rules Will be applied for à sort thime. When applied à rule everything is Oké, but after à few days cart is not showing correct prices anymore. When we noticed this, and apply THE rule again everything is fine ….. For à short time…. Does anyone have à solution for this?
Have you properly setup a cronjob for magento?
Great work. The fix works fine for me!
Wow..Cristi and Simon Lagendijk….thanks for you’re comments and great fix! I send you nothing but good vibes and good things to come for you guys! Made my day!