2

We have installed Magento ver. 2.1.6. using composer with sample data.

We have call event checkout_cart_product_add_after for adding addition information with item. The event observer code is given below.

$item = $observer->getQuoteItem();

    $additionalOptions = array();

    if ($additionalOption = $item->getOptionByCode('additional_options')){
        $additionalOptions = (array) unserialize($additionalOption->getValue());
    }

    $post = $this->_request->getParam('info');

    if(is_array($post)){
        foreach($post as $key => $value){
            if($key == '' || $value == ''){
                continue;
            }

            $additionalOptions[] = [
                'label' => $key,
                'value' => $value
            ];
        }
    }

    if(count($additionalOptions) > 0){
        $item->addOption(array(
            'code' => 'additional_options',
            'value' => serialize($additionalOptions)
        ));
    }

When we add the configurable product with addition information in the cart then in shopping cart page display additional information with error Some item options or their combination are not currently available

5

Cart Quote Item Option data stored in the quote_item_option table. This table contains option_id, item_id, product_id, code and value fields.

I have to pass product_id, code and value data to the addOption function but missing to pass product_id. Refer the following code

$item = $observer->getQuoteItem();

    $additionalOptions = array();

    if ($additionalOption = $item->getOptionByCode('additional_options')){
        $additionalOptions = (array) unserialize($additionalOption->getValue());
    }

    $post = $this->_request->getParam('info');

    if(is_array($post)){
        foreach($post as $key => $value){
            if($key == '' || $value == ''){
                continue;
            }

            $additionalOptions[] = [
                'label' => $key,
                'value' => $value
            ];
        }
    }

    if(count($additionalOptions) > 0){
        $item->addOption(array(
            'product_id' => $item->getProductId(),//Missing data
            'code' => 'additional_options',
            'value' => serialize($additionalOptions)
        ));
    }
  • 1
    I did the above thing and my additional options started coming in the quote_item_option table and gets displayed under product detail on checkout/cart page , but as soon as I refresh the checkout/cart page, the additional_options row gets deleted and it disappears from checkout/cart product. This doesn't happen with simple product. Any idea why this happens? – Nausif Oct 12 '17 at 6:46
  • After testing couple of times, I came to know that this happens when user is logged in otherwise works perfectly fine – Nausif Oct 12 '17 at 9:47
  • After more testing, I found out that the additional_options row for configurable product gets deleted from quote_item_options table when I land on checkout/cart product, any idea where this happens and how to stop it? – Nausif Oct 12 '17 at 11:48

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.