0

I just found out that Magento seems to have a bug since 1.8 relating to cart rules.

let's say we have some configurable products and want to add a "discount" for a specific product if the qty is less then 50. In my case it a surcharge not a discount (you can easily add negative discount so it'll get surcharge by changing two files see http://php.quicoto.com/extra-fee-shopping-cart-price-rules-magento/).

so what does magento do?

1) checks if rule is valid for that product 2) if not it checks if it is a configurable product, then takes the first simple product, and check the rule against that.

in this case true cause qty is less then 50 ( cause this simple product is not even in cart.... )

extending the rule by a "less then 50 and more then 1" didn't worked.

    $product = $object->getProduct();
    if (!($product instanceof Mage_Catalog_Model_Product)) {
        $product = Mage::getModel('catalog/product')->load($object->getProductId());
    } 
    // here, everythign correct. $valid is false cause item is less then x times in cart..
    $valid = parent::validate($object);  



// this part makes no sense, cause he's checking on a child which is not in cart.
     /** /
     if (!$valid && $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) {
        $children = $object->getChildren();
        $valid = $children && $this->validate($children[0]);
    }/**/

this small snippet is related to it, and in my eyes it doesn't make any sense. why the rule should be checked against the first product of a configurable one? why randomly check the rule against some other product?

does anyone has an idea about that?

my solution for now, just comment this line out ... ;-) and the rule get applied as it should.

greets felix

here's an image about the rule in magento backend

Jeff
  • 11
  • 2

1 Answers1

0

Looks like $object is instance of Mage_Sales_Quote_Item. If so, it explains why rule is being checked against first child - because it is the only child of configurable product in cart. It can't be more than one child of particular configurable product item in the cart at the same time

Igor
  • 178
  • 10
  • Sorry buddy, didn't get that at all.. :-) $object is the item in cart which get's validated first, and the variable $valid will be set to false. Like this it is correct... But then cause $valid is false it goes in the statement i mentioned above and just get's the first item of the configurable it finds ( $children[0] ) which has no relation to the one in cart. I also checked that with two configurations in cart of the same configurable product. Works fine. No need for that check. – Jeff Jan 07 '16 at 17:15
  • If you look at sales_flat_[order/quote]_item table(s), you'll see 'parent_id' column. In case of bundle products we can see 1+ children (because this product type allows purchase 1+ 'components' (products, in fact) within one bundle). In case of configurable product you'll see strict one-to-one relation - configurable_item-simple_child_item. There is no need to search for 2nd, 3rd etc children because they do not exist - you may add to cart only one simple product along with its' parent - configurable item. – Igor Jan 07 '16 at 17:42
  • So, generally, sentense '$children[0] has no relation to any item in cart' is wrong - it has relation to the particular simple product ('option' of configurable product) you've chosen before adding product to cart. If you have configurable product 'T-shirt' and 3 simple (children) - green, yellow, white - and decided to add white T-shirt to cart - $children[0] will correspond to white T-shirt – Igor Jan 07 '16 at 17:47