0

Is it possible to add the same product to the shopping cart, but have it appear as different line items?

In my specific case I am adding a product to the cart programatically based on some conditions of the cart, specifically its subtotal.

When i add the product, I want to add it as a unique line item, regardless of whether that product already appears in the cart now or in future: added by a customer normally.

For example, say the cart look like this:

Product A - qty 1
Product B - qty 1

and I wanted to add Product B in my code, I would like it to appear like:

Product A - qty 1
Product B - qty 1
Product B (custom) - qty 1
0

1 Answer 1

0

My bet would be to add your programmatically added product with a non-existent custom option. That way it's saved to the session/database and you have a nice place to show the customer the reason why you added the product. Talking about the reason, that's probably as part of some promotion because they're spending a certain amount, if so, don't forget to observe changes to the quote so that when the subtotal drops below a certain amount you can remove the free product again.

To do this start your research at the addOption() function within the Mage_Sales_Model_Quote_Item class, something like this:

$quoteItem->addOption(new Varien_Object(array(
    'product' => $product,
    'code' => 'info_buyRequest',
    'value' => serialize(array('qty' => $qty, 'marty_wallace_product' => true))
)));

Because this buyRequest cannot be reproduced by the customer, the product will end up on its own line.

2
  • Would this work for a product that was already in the cart? Dec 7, 2014 at 17:53
  • What are you trying to accomplish exactly? I don't know exactly if Magento only checks the uniqueness of the buyRequest on adding, or every time it gets the items. Dec 7, 2014 at 18:03

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