Bug in Magento core affecting Catalog Price Rules targetting Customer Groups

I came across this issue to begin with using the Wildcardbi_RulePriceAttribute module to be able to specify custom prices for specific customer groups (in this case, wholesale/trade pricing) without having to setup an entire new store view for it.

The problem was though, that the custom price would be applied in the catalog, but lost when the product was added to the cart. Nor would the custom price re-appear at any point during checkout. Doing a bit of digging, I found a (rather sloppy, IMHO) typo in Magento’s core which basically prevents any Catalog Price Rule targetting Customer Groups other than “General” from working. Just before writing this, I submitted a bug report to Magento’s bug tracker in the hopes that they can fix the core. But in the meantime, if you need to get around this issue, do the following:

  • Copy app/code/core/Mage/CatalogRule/Model/Observer.php to app/code/local/Mage/CatalogRule/Model/Observer.php
  • Open the copied file and navigate to line 105 where you (should) see this:
    $gId = $product->hasCustomerGroupId();
  • Replace the above line with the following:
    $gId = $product->getCustomerGroupId();
  • Save and add a product to your cart (or update your cart (forces a save where this code is triggered) that has it’s price affected by your customer group. And voila – custom price now in the basket.

If you want to know the reason why it doesn’t work, hasCustomerGroupId() only returns true or false, as to whether that attribute/key is set in the model’s data array. It’s doesn’t actually return the value. That’s what get*() is for. As this typo is in an if statement evaluating whether hasCustomerGroupId() is true or not, then $gId will ALWAYS be 1 when it’s casted to an integer later on in the code. It’s a rather crap typo to be honest, and reading some of the comments in the code, they’re not all that au-fait with the English language either. But oh well.

Join the Conversation


  1. Worked great. It’s important to note that you may need to clear your browser cache and reapply the rules for it to take effect. Worked fine from here. (The only one I could find online that actually DID work.) Thanks!

  2. Não deu certo apareceu o erro:
    Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE or ‘$’ in /home/oyaalimentos/www/emporio/app/code/core/Mage/CatalogRule/Model/Observer.php on line 105

    Alguém pode me ajudar?

  3. O erro está sugerindo que você copiou e colou o código dentro do ficheiro, e é um texto copiado ou não PHP do meu site (Tynt Analytics faz isso), ou se você digitou em manualmente, então você perdeu alguma coisa (falta um ponto e vírgula à direita ou algo assim) e PHP não gosta dela.
    Como você modificou o arquivo de núcleo, em vez de fazer o que eu sugeri e copiá-lo para “local” e depois modificá-lo, você vai precisar para extrair outra cópia do Magento para reverter / substituir o arquivo. Se você copiá-lo para local e, em seguida ele falhar, então você pode renomear o arquivo local. “velha”ou algo assim, eo problema vai embora.
    Se você está lutando, me enviar o arquivo e eu vou dar uma olhada.
    PS, desculpe se a tradução é uma porcaria, eu digitei isso no Google Translate, como eu não falam Português!

Leave a comment

Your email address will not be published. Required fields are marked *