I have built an observer which fires at checkout_cart_product_add_after. In the observer I set the quantity like this:
$item->setQty($quantity);
I would like to fetch the quantity that is already in the cart for that product, so that the quantity for the product gets updated instead or overwritten. Yet when I try to get the product quantity in the cart (Mage::helper('checkout/cart')), I get the "new" quantity, probably because the update quantity code has already fired.
How could I get the cart quantity for the product?
Thanks in advance,
Joost
EDIT:
This is the full code of the observer:
public function modifyPrice(Varien_Event_Observer $obs)
{
$item = $obs->getQuoteItem();
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
$price = $this->_getPrice($item);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$quantity = $this->_getQuantity($item);
$item->setQty($quantity);
$item->getProduct()->setIsSuperMode(true);
}
protected function _getPrice(Mage_Sales_Model_Quote_Item $item)
{
$price = 0;
Mage::app()->getRequest()->getPost();
$qtydropdownbox = Mage::app()->getRequest()->getParam('qtydropdownbox');
$prices = $item->getProduct()->getData('qty_dropdownbox_prices');
$quantities = $item->getProduct()->getData('qty_dropdownbox_quantities');
$array_prices = explode(';', $prices);
$array_quantities = explode(';', $quantities);
$price = $array_prices[$qtydropdownbox] / $array_quantities[$qtydropdownbox];
return $price;
}
protected function _getQuantity(Mage_Sales_Model_Quote_Item $item)
{
$quantity = 0;
Mage::app()->getRequest()->getPost();
$qty = Mage::app()->getRequest()->getParam('qty');
$qtydropdownbox = Mage::app()->getRequest()->getParam('qtydropdownbox');
$quantities = $item->getProduct()->getData('qty_dropdownbox_quantities');
$array_quantities = explode(';', $quantities);
$quantity = $array_quantities[$qtydropdownbox] * $qty;
return $quantity;
}