5

Upgraded a store from CE 1.5 to 1.9.0.1 and while everything else works just fine several Catalog Price Rules stopped working. After some investigation I found something weird:

ANY condition is TRUE
  SKU "is one of" sku1
  SKU "is one of" sku2

works just fine.

ANY condition is TRUE
  SKU "is one of" sku1,sku2

doesn't work.

Any ideas what causes this anomaly, how to fix it and why is this behavior different from older versions?

UPDATE: Preliminary investigation reveals that it's actually a bug in Magento core ... once I have a fix, I'll post it here as an answer.

6
  • 1
    What about contains instead of is one of ? I recalled having problems with the later early on 1.8.
    – Niloct
    Commented Sep 18, 2014 at 17:33
  • I'll test it out tomorrow. However even if it works, there's still a considerable risk that longer SKU codes may contain shorter ones and thus cause unwanted false positive discounts.
    – Pronto
    Commented Sep 18, 2014 at 18:01
  • I think contains is about elements, so each SKU would count in their entirety, not as prefixes.
    – Niloct
    Commented Sep 18, 2014 at 18:21
  • 'ANY condition is TRUE' and SKU 'is one of' should work as you mentioned. Double check the SKU field on the individual products sometimes there is a space at the end and for some reason Magento doesn't trim those off automatically. Commented Sep 18, 2014 at 20:38
  • It doesn't work. Try it out yourself. At first glance it looks like magento is unable to explode comma separated values.
    – Pronto
    Commented Sep 18, 2014 at 20:55

3 Answers 3

7

I had the same issue, but on 1.8.1.0, so i tried to update to 1.9.0.1, still the same issue.

But I found why this happens:

This method: Mage_Rule_Model_Condition_Product_Abstract::prepareConditionSql()

Returns a part of a sql-statement, like so: cpf.sku IN('SKU')

What's interesting is that the IN contains the exact string that was entered in admin, like so: cpf.sku IN('SKU1, SKU2, SKU3')

Note the lack of ' between the SKU's, the string isn't exploded, so it won't find any sku's like that sting.

To fix the issue i modified (copied to local first of course) that method to look like this;

 public function prepareConditionSql()
{
    $alias     = 'cpf';
    $attribute = $this->getAttribute();
    $value     = $this->getValue();
    $operator  = $this->correctOperator($this->getOperator(), $this->getInputType());
      if ($attribute == 'category_ids') {
        $alias     = 'ccp';
        $attribute = 'category_id';
        $value     = $this->bindArrayOfIds($value);
    }

    // Andre Klang: This fixes issue with "is one of" & "is not one of"
    if(!is_array($value) && in_array($operator,array('()','!()'))) {
        $tmp = explode(',',$value);
        foreach($tmp as $trim) $values[] = trim($trim); 
        $value = $values;
    }

    /** @var $ruleResource Mage_Rule_Model_Resource_Rule_Condition_SqlBuilder */
    $ruleResource = $this->getRuleResourceHelper();

    return $ruleResource->getOperatorCondition($alias . '.' . $attribute, $operator, $value);
}

I also reported this as a bug to Magento: http://www.magentocommerce.com/bug-tracking/issue/index/id/278

1
  • I actually built a fix very similar. Haven't had time to post it here, so thanks and a well deserved up vote.
    – Pronto
    Commented Sep 23, 2014 at 6:14
5

Please note that this issue has been solved in Magento EE 1.14.2.0. The fix is darn simple :

In Mage_Rule_Model_Condition_Product_Abstract::prepareConditionSql() :

replace

$value = $this->getValue(); by $value = $this->getValueParsed();

1
0

Issue with catalog price rules still exist on latest Magento CE 1.9.1 and EE 1.14.1.0 , problems even more complex, details and hot fix for described problem and few more http://firebearstudio.com/blog/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-behavior.html , all reported to bug tracker but no any reaction yet. Core patch with fix on GitHub - https://github.com/biotech/Magento1.9-CatalogPriceRulesFix

1
  • 1
    Please elaborate a link is not an answer.
    – SR_Magento
    Commented Feb 8, 2015 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.