Getting quote (cart) items programatically shows duplicate SKUs for both the configurable and simple product
According to Magento, when a configurable product added at cart then two rows are inserted at the database. one configurable product cart another is a simple product
One row has configurable id and simple product SKU and parent item id is null
Other rows have simple id and simple product SKU and parent item id should above row id
As you have using getAllItems()
then on for loop you need to check
is it has parent item $item->getParentItemId()
.
foreach ($cart->getAllItems() as $item) {
/ * add this */
if ($item->getParentItemId()) {
continue;
}
........
}
Use $cart->getAllVisibleItems()
instead of $cart->getAllItems()
.
You get duplicates because when adding a configurable product to the cart, magento actually adds 2 products, the simple product and the configurable product but only one is visible for the user.