Question

From quote I got array of customizable option. How can I retrieve it's title & value

 $quote = $this->_cart->getQuote();
    $cartAllItems = $quote->getAllItems();
    foreach ($cartAllItems as $item) {
        foreach ($item->getOptions() as $option) {

             echo "<pre>";
            print_r(json_decode($option['value']));die;

        }

This is the output but I need value

[options] => stdClass Object
    (
        [1] => Array
            (
                [0] => 2
            )

    )
Was it helpful?

Solution

// get cart items
$items = $cart->getItems();

// get custom options value of cart items
foreach ($items as $item) {
    $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
    $customOptions = $options['options'];
    if (!empty($customOptions)) {
        foreach ($customOptions as $option) {
            $optionTitle = $option['label']; 
            $optionValue = $option['value'];
        }
    }
}

NOTE in above code $cart is object of Magento\Checkout\Model\Cart

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top