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

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 that you have read and understand our privacy policy and code of conduct.

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