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
    Sep 30 at 9:53
  • its done by using $cart->getQuote()->getAllVisibleItems()
    – Prits
    Sep 30 at 9:54
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
    Sep 30 at 10:30

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.