1
                    $product
                           ->setPrice($price)
                           ->setSpecialPrice($price)
                           ->setTierPrice([])
                           ->setBasePrice($baseprice)
                           ->setOriginalCustomPrice($price);
                                /** @var \Magento\Framework\DataObject $request */
                           $request = $this->dataFactory->create();
                           $request->setData('qty', (int)$qty)
                           $quote->addProduct($product, $request);

I have added the products to quote using the above code. But this merges the row qty for same SKU (as it supposes to).

How to create 2 different item-lines for the same SKU?

2 Answers 2

3

You can customize method Magento\Quote\Model\Quote\Item::representProduct() to return false if the product SKU matches your criteria.

Reference post: Magento 2: How to Prevent item's quantity from being added

1
  • this solution works with adding new item to cart, but when i am trying to edit cart item and update qty and press update cart button than it again merges line items into one line item Commented Jul 2 at 6:56
1

All you need is to create the item object BEFORE adding it to the quote, instead of directly adding the product to the quote and letting Magento create the item.

/** @var \Magento\Quote\Model\Quote\Item $quoteItem */
$quoteItem = $this->itemFactory->create();
$quoteItem->setPrice(123.33);
$quoteItem->setRowTotal($quoteProduct->getPrice());
$quoteItem->setProductType($quoteProduct->getTypeId());
$quoteItem->setOriginalPrice(123.33);
$quoteItem->setCustomPrice(123.33);
$quoteItem->setOriginalCustomPrice(123.33);
$quoteItem->setQtyOrdered(1);
$quoteItem->setQty(1);
$quoteItem->setProduct($quoteProduct);
$quote->addItem($quoteItem);

Original post link: https://magento.stackexchange.com/a/324605/54929

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.