Magento – Shopping Cart Price Rules not applied to correct group_id

cart-rulemagento-1.7magento-enterpriseprice-rules

While debugging the shopping cart price rule calculation i found out that the system uses the default_group configured in backend instead of the actual customer group on this customer group sensitive rule.

It seems to me that this is a bug. But i have never heard of this. I am quite sure there is no custom code responsible for this. When i look into sales_flat_quote db table the customer group id is correctly set with the actual customers group id.

Any hints on this topic?

I checked this in class

code/core/Mage/SalesRule/Model/Quote/Discount.php

in method

collect()

This is the proof:

        Mage::log("BEFORE ENTERING CALCULATOR WE SEE default_group ID");
        Mage::log($quote->getCustomerGroupId());
        $this->_calculator->init($store->getWebsiteId(), $quote->getCustomerGroupId(), $quote->getCouponCode());

I am still debugging but maybe you guys have some hint from experiencing same problems…thank you so much!

P.S.: this is found in EE 1.12 but i am sure its in 1.7.0.2 too.

Best Answer

We experienced the same problem with a Magento 1.7.0.2 webshop.

Fortunately this bug was fixed in Magento 1.8.1.0 (I didn't check 1.8.0.0) and can easily by ported over to Magento 1.7.

You have to take a look at the difference between the method changeQuoteCustomerGroupId of the class Mage_Sales_Model_Observer from Magento 1.7.0.2 and 1.8.1.0 Those differences are the fix for the bug.

➜ diff ~/Projects/magento1702/app/code/core/Mage/Sales/Model/Observer.php ~/Projects/magento1810/app/code/core/Mage/Sales/Model/Observer.php
23c23
<  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
---
>  * @copyright   Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
420a421
>         $isDisableAutoGroupChange = $customerInstance->getDisableAutoGroupChange();
440c441,443
<         if (empty($customerVatNumber) || !Mage::helper('core')->isCountryInEU($customerCountryCode)) {
---
>         if ((empty($customerVatNumber) || !Mage::helper('core')->isCountryInEU($customerCountryCode))
>             && !$isDisableAutoGroupChange
>         ) {
488,490c491,497
<         $groupId = $customerHelper->getCustomerGroupIdBasedOnVatNumber(
<             $customerCountryCode, $gatewayResponse, $customerInstance->getStore()
<         );
---
>         if (!$isDisableAutoGroupChange) {
>             $groupId = $customerHelper->getCustomerGroupIdBasedOnVatNumber(
>                 $customerCountryCode, $gatewayResponse, $customerInstance->getStore()
>             );
>         } else {
>             $groupId = $quoteInstance->getCustomerGroupId();
>         }
Related Topic