0

I tried to add a product to cart programmatically, but it should be in different line with other product in the cart.

I already tried the code below but it only adds a product to cart and adds the qty if there's same product in the cart. How can I make it to a new line rather than add the qty?

Add product code :

$cartObj = $objectManager->create('Magento\Checkout\Model\Cart');
$cartObj->addProduct($_product,$params);
$cartObj->save();
2

You must add custom options to the $_product with

$customOptions = [
    'label' => 'test',
    'value' => 'value different by product (line)'
];
$_product->addCustomOption('custom_option', serialize($customOptions));

Before add product in cart

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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