Catalog price rules core bug in Magento CE 1.9.1 and EE 1.14.1.0 (Array to string conversion error and incorrect price rules behaviour)

magento-catalog-price-rules-bugShort summary of the problem – if you have Magento catalog price rules with multiple select attributes in conditions or ONE OF price rules conditions with comma separated values – on latest Magento versions – you can have Array to string conversion error during you apply rules or incorrect rules behavior.

In this post we provide explanation and information about how to fix this Magento core bug what exists on latest Magento Community Edition 1.9.1 and Enterprise Edition 1.14.1.0 (confirmed on this versions by a lot of manualtests described below, we also know that on Magento CE 1.7 everything works fine and according to StackExchange issue can exist on all versions CE 1.8.x – 1.9.x). Issues are already reported on Magento bug tracker, but no any official patches are confirmed. Fixes provided below have been created in urgent matter for the significant Magento upgraded from 1.7 to 1.9.1. The update includes about 100 different price rules and 20000 products, fixes were tested and used on production but we can not guarantee that our core patches resolve issue complete. Keep in mind, that all code is provided without any guarantees and you can use it on your own responsibility. In a case when something went wrong, we can’t be blamed.  We hope to get official patches for Community and Enterprise editions from Magento team as soon as possible!

'

Issue reports:

Download patch from GitHub repository – just upload it in app/code/local to overwrite core methods with patched methods

 

Samples of catalog rules issues on Magento CE 1.9.1 & EE 1.14.1.0

1. Catalog price rules which use multiple select attribute values in CONTAINS or NOT CONTAINS conditions can not be applied and cause error during you apply catalog price rules – Array to string conversion in app/code/core/Mage/Rule/Model/Resource/Rule/Condition/SqlBuilder.php in line 75, In same time IS ONE OF and IS NOT ONE OF conditions work good.

MultiSelect Attribute (attribute code – brand)

– TEST: Create catalog price rule with brand CONTAINS (any number of selected values)

– RESULT: Get an exception thrown and a message stating unable to apply rules in the admin.

2015-01-30T00:38:49+00:00 ERR (3): exception ‘Exception’ with message ‘Notice: Array to string conversion in app/code/core/Mage/Rule/Model/Resource/Rule/Condition/SqlBuilder.php on line 75’ in app/code/core/Mage/Core/functions.php:245

– TEST: Create catalog product price rule with brand NOT CONTAINS (any number of selected values)

– RESULT: Get an exception thrown and a message stating unable to apply rules in the admin.

2015-01-30T00:43:42+00:00 ERR (3): exception ‘Exception’ with message ‘Notice: Array to string conversion in app/code/core/Mage/Rule/Model/Resource/Rule/Condition/SqlBuilder.php on line 75’ in app/code/core/Mage/Core/functions.php:245

– TEST: Create catalog product price rule with brand IS ONE OF (any number of selected values)

– RESULT: No exceptions thrown and condition SQL generated correctly:

[0] = > ‘cpf’.’brand’ IN(‘237’, ‘236’, ‘232’, ‘235’)

– TEST: Create catalog product price rule with brand IS NOT ONE OF (any number of selected values)

– RESULT: No exceptions thrown and condition SQL generated correctly:

[0] => ‘cpf’.’brand’ NOT IN(‘237’, ‘236’, ‘232’, ‘235’)

2. Catalog price rules which use text attribute values in ONE OF condition cannot be applied correctly because in SQL query values are not exploded by comma to array

Text Attribute (attribute code – stock)

– TEST: Create catalog price rule with stock is one of: 1,3

– RESULT: Incorrect rules applied as the comma separated values as not accepted:

(‘cpf’.’stock’ IN(‘1,3’))

– TEST: Create catalog price rule with stock contains: 1,3

– RESULT: Incorrect rules applied as the comma separated values are not split correctly:

(‘cpf’.’stock’ LIKE ‘%1,3%’)

– TEST: Create catalog price rule with the following matching rules, stock IS 1 OR stock IS 3

– RESULT: Rules are applied as expected:

(‘cpf’.’stock’=’1′ OR ‘cpf’.’stock’=’3′)

Source code of patch for catalog price rules

To fix issues with catalog price rules, we have edited two Magento core files. In code below you can find our code between comments //CORE PATCH: … /// END CORE PATCH

File : app/code/local/Mage/Rule/Model/Resource/Rule/Condition/SqlBuilder.php

File : app/code/local/Mage/CatalogRule/Model/Action/Index/Refresh.php

 

'