dan.codes
dan.codes

Reputation: 3523

Possible Bug with Shopping Cart Promotions and Product Attributes Combination, always returning true for certain conditions

I was doing some debugging, trying to see how a condition for a promotion on the shopping cart was validating attributes when using the product attributes combination. I didn't understand how Magento was getting custom attribute values from a product, if that custom attribute isn't added to the quote item product in a config.xml.

So as I was debugging down into the the validation logic, I did a test where I created an attribute called package_price and assigned it to a product and gave it a value of 20. I then setup a condition:

If an item is FOUND in the cart with ALL of these conditions true: Package Price greater than 1

As it got down into the logic you eventually get here /app/code/core/Mage/Rule/Model/Condition/Abstract.php

and in the method validateAttribute. It gets here after attempting to get the attribute value out of the quote item product. In my case the parameter $validatedValue was null since it couldn't get it off of the data array.

The code works right getting down to here

            case '<=': case '>':
            if (is_array($validatedValue) || is_null($validatedValue)) {
                $result = false;
            } else {
                $result = $validatedValue<=$value;
            }
            break;

And it obviously gets set to false. What I don't understand after the switch statement you have this little piec of code

if ('!='==$op || '>'==$op || '<'==$op || '!{}'==$op || '!()'==$op) {
            $result = !$result;
}

Which sets certain operators $result variable to be the opposite, so in my case it made it true and then made my condition pass even though it shouldn't have. I am thinking that any time someone makes a shopping cart promotion with custom attributes that are not added to the quote item, which would happen a lot if you just have admin users running the interface trying add new attributes to products and create promotions with them.The the promotion would always pass if they used one of these operators. I can't for the life of me figure out what would need this or why > would be any different than >=.

Not to mention, don't you think any attribute that is marked as used for promo conditions should be added to the quote item product?

Can someone help me understand this as to why it needs to work this way. I wanted to post this here before contacting Magento.

Upvotes: 1

Views: 190

Answers (1)

dan.codes
dan.codes

Reputation: 3523

This is a bug for at least Enterprise Edition and there is a patch available now if you contact Varien Support.

Upvotes: 0

Related Questions