0

How to get only simple products from cart as currently i am getting configurable product also.

currently i need to check with an if condition

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 
        $itemsCollection = $cart->getQuote()->getItemsCollection();
        $itemsVisible = $cart->getQuote()->getAllVisibleItems();
        $itemsd = $cart->getQuote()->getAllItems();

        foreach ($itemsd as $key => $value) {
            $product = $objectManager->create('Magento\Catalog\Model\Product')->load($value->getProductId());
            if($product->getTypeId() == 'configurable'){ 
                continue;
            }
        }

how to get only simple product not configurable product.

2
  • have you tried to change the typeId to simple?
    – Asssd
    Commented Sep 30, 2021 at 9:53
  • its done by using $cart->getQuote()->getAllVisibleItems()
    – Prits
    Commented Sep 30, 2021 at 9:54

1 Answer 1

0

you are almost there :

  foreach($itemsVisible as $_item) {
         echo 'Name: '.$_item->getName();
    }
1
  • Yes correct Have you any idea how to get its custom option like Colour and size ?
    – Prits
    Commented Sep 30, 2021 at 10:30

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.