5

I have successfully saved product additional options in "quote_items_options" table .
Now I want to retrieve those options using product_id.

Can anyone help me how can I get additional options?

Thanks in advance..!

3

You can get product wise additional option using below code. (Do not use Objectmanager directly if the code works then change dependency use via construct)

$productId = 68;
 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $cart = $objectManager->get('\Magento\Checkout\Model\Cart');
 //This return something
 $items = $cart->getQuote()->getAllItems();
   foreach ($items as $item) {
     $customOptions = $item->getOptionByCode('additional_options');
       $row = $customOptions->getData();
       if($row['item_id'] == $productId){
         print_r($row['value']);
       }
  }
| improve this answer | |
1
public function __construct(
    Context $context,
    \Magento\Quote\Model\ResourceModel\Quote\Item\Option\CollectionFactory $quoteItemCollectionFactory
) {
    $this->quoteItemCollectionFactory = $quoteItemCollectionFactory;
    parent::__construct($context);
}

/**
 * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
 */
public function execute()
{
    $quoteItemCollection = $this->quoteItemCollectionFactory->create();
    $quoteItemCollection->addFieldToFilter('product_id', 135);
    print_r($quoteItemCollection->getData()); 


}
| 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.