0
    {
        "item_id": 191111111,
        "sku": "qqqqqqq",
        "qty": 1,
        "name":"asdasd",
        "price": 736.52,
        "product_type": "simple",
        "quote_id": "1111",
        "product_option": {
            "extension_attributes": {
                "custom_options": [
                    {
                        "option_id": "1111",
                        "option_value": "12131111111089"
                    }
                ]
            }
        }
    }

i want to get the option_id and vales from it Anyone can help?

0

Use this below code for get option id and option value :

public function __construct(\Magento\Checkout\Model\Cart $cart)
{
    $this->cart = $cart;
}

$cartItem =  $this->cart->getItems();
$customOptions = $cartItem->getProductOption()->getExtensionAttributes()->getCustomOptions();
if (!empty($customOptions) && is_array($customOptions)) {
    $requestData = [];
    foreach ($customOptions as $option) {
        $requestData['options'][$option->getOptionId()] = $option->getOptionValue();
    }
}
  • $option->getOptionId() => You will get option_id
  • $option->getOptionValue() => You will get option_value
4

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.