0

I want to add child product in the new line if it is already exists in the cart, I am able to check it is exists or not with below code but how can i add that with new line

$productId = 1;
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (! $quote->hasProductId($productId)) {
    // Product is not in the shopping cart so 
    // go head and show the popup.
}
Laty
  • 191
  • 6
  • Duplicate: http://magento.stackexchange.com/questions/14174/how-can-i-show-the-same-product-multiple-times-in-the-shopping-cart – muhammedv Apr 14 '16 at 09:45
  • I hav checked that and with return false; it only stops item from adding but i want to add it in new line. – Laty Apr 14 '16 at 09:47
  • Can you try this one: http://magento.stackexchange.com/questions/46604/same-product-added-to-cart-different-line-items It is a bit different approach. – muhammedv Apr 14 '16 at 09:50
  • Custom options will do the trick, you can either add it from Admin or programatically like in the second example. – muhammedv Apr 14 '16 at 09:54
  • I don't want to go with custom options – Laty Apr 14 '16 at 09:59
  • That's acceptable. We can find another way. But first, did I understood your question correctly: You want to check if a product is already in cart when add-to-cart action called, if that product is in cart you don't want to get qty increased, you want to add it like a new product in a new line? – muhammedv Apr 14 '16 at 10:03

1 Answers1

0

If you don't want to use Custom Options, you don't have any other option to differentiate your products in cart. So, you need to overload Mage_Sales_Model_Quote_Item class and rewrite representProduct function.

Create a custom module, overload sales/quote_item model and rewrite representFunction as below:

/**
 * Check product representation in item
 *
 * @param   Mage_Catalog_Model_Product $product
 * @return  bool
 */
public function representProduct($product)
{
    //You can check here if the product is the one that you need to add as a new line or not.
    if(/* some checks with $product */) {
        return false;
    }

    //run parent function as default
    return parent::representProduct($product);
}

So, any product added to cart will not represent another product -that already in cart- and be evaluated as a new product.

Community
  • 1
  • 1
muhammedv
  • 879
  • 8
  • 18
  • Thanks it works with all products but what if we want to work it only for related or any child product. – Laty Apr 14 '16 at 10:27
  • So you want to apply this only to a simple product that is linked to a configurable product? – muhammedv Apr 14 '16 at 10:35