0

I want to use a foreach loop to loop through all products in the cart and if it exists and the user adds it to the cart again, it should increase that item's total by 1 but I am not sure how to implement this. What I want to happen is that if a user clicks "add to cart" on an item it gets added to the cart with quantity of 1. If they click "add to cart" again for the same item, it should change to quantity of 2 for that item.

3
  • Need more detail , magento already this feature .
    – mohan
    Commented Apr 5, 2018 at 7:34
  • noo....its not....i am using 1.9.3.2 version.
    – XYZ
    Commented Apr 5, 2018 at 7:47
  • while clicking add to cart directly add quote table? or using magento default function?
    – mohan
    Commented Apr 5, 2018 at 12:11

1 Answer 1

0

That's how add to cart button in product page already works. You can check this function: Mage_Sales_Model_Quote_Item::addQty(). It always adds a previous quantity. If it was not added to the cart before, the previous quantity added will be 0. Default previous quantity 0 is set here: Mage_Sales_Model_Quote::addProductAdvanced(). The default add to cart controller action from where everything is started from the button click is: Mage_Checkout_CartController::addAction().

So, from wherever you want to add items to cart, you should use one of that functions. For example: $item->addQty(1);

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.