I want to save custom data in to cart item and add new cart item instead of update quantity when product add to cart in Magento.

I have added below code in Observer.php file

    public function checkoutCartProductAddAfter(Varien_Event_Observer $observer){
    try {
        $data = $this->_getRequest()->getPost();
        $item = $observer->getQuoteItem();
        $product = $item->getProduct();

            $results['data'] = $data['customize_data'];
            $productModel = Mage::helper('productcustomizer')->getCustomizeData($product->getId());
            $results['price'] = $productModel->getCustomizePrice();

            $file_name = $item->getProduct()->getId()."-".time()."-".rand(0,999).'-'.$item->getProduct()->getUrlKey();
            $path = Mage::getBaseDir()."/media/productcustomizer/customize_image/";
            $url = Mage::getBaseUrl()."media/productcustomizer/customize_image/";
            $new_file_name = Mage::helper('productcustomizer')->save_base64_image($data['customize_image'],$file_name, $path);
            $image_data = array(
                'url' => $url.$new_file_name,
                'path' => $path,
                'name' => $new_file_name

            $results['image'] = $image_data;

                  "product_id" => $product->getId(),
                  "product" => $product,
                  "code" => "customizer_data",
                  "value" => serialize($results)

            if(!empty($results['price']) ){
                $finalPrice = $product->getPrice();
                $qty = $item->getQty();

                $price = ($finalPrice + $results['price']) * $qty;

    catch (Exception $e) {

It is saving custom data into cart item but when i add same product in to cart then it is updating quantity. I want to add new item instead of update quantity.

I want to add separately because "customization data" and "price" of the product is different every time when add item into cart.

  • if those products were same why you want them as a seprate product Jan 4, 2017 at 9:23
  • If you added same product, then magento always update qty into cart not added as seprate product. Specify what you try to archive, so other can help you into that way. Jan 4, 2017 at 9:27
  • Product is same but customization data and price of the product is different every time. Jan 4, 2017 at 9:30

1 Answer 1


You can use this event to meet your requirement,


On this event you can call this updated function to show your product with new row,

public function saveProductTabData(Varien_Event_Observer $observer)
        $product = $observer->getEvent()->getProduct();
        $quote = Mage::getModel('checkout/cart')->getQuote();
        $quoteItem = $quote->getItemByProduct( $product );

        $productId = $product->getId();
        try {

            $data = Mage::app()->getRequest()->getPost();

            $customize_price = $data['customize_price'];
            $customize_data = $data['customize_data'];
            $customize_status = $data['customize_status'];
            $customize_description = $data['customize_description'];

                  "code" => "new_row_for_product",
                  "value" => serialize(array(time()))
        catch (Exception $e) {
  • Have you tried this in Magento 2 Nov 15, 2018 at 10:27

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.