0
votes

I am on Magento 1.9.1.1 and currently I am trying to create a shopping cart price rule based off a custom attribute for a product that is in the cart. I use the following code in my observer (sales_quote_save_after) to set the attribute, it has no effect on the shopping cart price rule. It appears that when I am setting the cart product attribute, the price rule is actually checking the product attribute instead of the product attribute in the cart.

$quote = $observer->getEvent()->getQuote();
$cartItems = $quote->getAllVisibleItems();
$productSkus = Mage::getSingleton('core/session')->getProductSkus();
foreach ($cartItems as $item) {
    $skuname = $item->getSku();                             
    if ($skuname == $productSkus){
        $item->getProduct()->setData('stone_remnant_flag',$remnant);
        $item->save();
        break;
    }
}

So I am wondering how I would go about creating a shopping cart price rule condition based off a Cart Item Attribute. Currently Magento only shows:

  • Price in cart
  • Quantity in cart
  • Row total in cart
1
There is no separated cart item attribute. All items in the cart are actually regular products. Why are you trying to set these values dynamically? Even if you set some attributes on the product dynamically, it is important to mention which observer are you using to do that. - Bob
I need to give the product a discount. These are all the same product with custom options. Depending on the custom option (associated with a product) chosen by the user, the observer is updating the attribute so that a discount can be applied. I am using the sales_quote_save_after observer. If what you say is true, then something must be wrong with how I am setting the attribute. - Chris Rosenau
are you try to develop a magento extension or use magento? if is the 2 you can try to use promotions / Shopping cart rules in the magento admin side, in that you can create a conditions for you r needs - chefjuanpi

1 Answers

0
votes

You are probably using the wrong event. Did you try to use this event checkout_cart_product_add_after?

This is how your observer should look like:

$quoteItem = $observer->getEvent()->getQuoteItem();
$product = $observer->getEvent()->getProduct();
// your code here