2

I am looking for an event observer which is suitable for my requirements.

My requirement is I add to cart the product but qty I want to add to this cart will be decided by the product attribute.

I will be having a custom attribute called attribute1 which will have an integer number.

So when I add to cart the product, I will get the attribute and number which is defined in it and I set this number as a qty to the product which is getting added to cart.

So following are the observers I tried, but not getting any success checkout_cart_product_add_after and I am looking for event something like checkout_cart_product_add_before but it seems not their.

Please help me.

1
  • Can you plse check answer below?
    – sv3n
    Apr 25, 2019 at 23:47

4 Answers 4

0

You could use the sales_quote_product_add_after event. You can access there the added quote items and change the quantity. Just be careful not to change the quantity for items that have a parent set (you can check if $item->getParentItem() is set).

0

I don't know the code you have used, but it works with checkout_cart_product_add_after and set quantity on $strockItem instead of $product:

public function checkoutCartProductAddAfter(Varien_Event_Observer $observer)
{
    $product = $observer->getProduct();
    $stockItem = $product->getStockItem();
    $stockItem->setQty($product->getData('attribute1'));
    $stockItem->save();
}
0

I would say that the best approach is using the min sale qty this way the quantity added to the cart will be the value that you have set.

0

You can rewrite Mage_Checkout_CartController or check if any third party module have rewrite Mage_Checkout_CartController class already then use that class to rewrite,

In AddAction function - get attribute1 value and setParam qty = attribute1 of getRequest. Then call - parent::AddAction(); - So that this wont break the original code of magento.

Did anyone find my answer useful or not? Because of -1 point I can't post answers and questions in other Stack Exchange websites. I'm completely frustrated & stuck because of this -1 point. Otherwise I will not come to any Stack Exchange sites any more.

Your Answer

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

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