0

I need to get all the configurable items related to an item in the cart. For example, if the cart item is of a size "XL", then I need to get all the other options like "S", "M" and "L" together with their attributes.

I get all the cart items using the following method:

$items = $cart->getQuote()->getAllVisibleItems();

And then I try:

foreach( $items as $item ) {
  foreach ($item->getOptions() as $option) {
    // Here I need to get the attributes for each option but I'm not sure how to go about that
  }
}

Is getOptions() the way to go?

Thanks!

0

Options depends on product type:

switch ($item->getProductType()) {
    case 'configurable':
        $block   = $this->objectManager
            ->get('Magento\ConfigurableProduct\Block\Cart\Item\Renderer\Configurable');
        $block->setItem($item);
        $options = $block->getOptionList();
        break;
    case 'bundle':
        $block   = $this->objectManager
            ->get('Magento\Bundle\Block\Checkout\Cart\Item\Renderer');
        $block->setItem($item);
        $options = $block->getOptionList();
        break;
    .....
|improve this answer|||||

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.