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..!
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI 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..!
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']);
}
}
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());
}