Skip to content

Want to remove the File option while updating the cart item in mageno 2

I Want to remove the File option while updating the cart item in Magento 2.
Below is the my code but not working

$quoteItemId = $this->getRequest()->getParam('quote_item_id');
    $optionId = $this->getRequest()->getParam('option_id');

    // Load the quote item
    $quote = $this->quoteRepository->getActive($this->session->getQuoteId());
    $quoteItems = $quote->getAllItems();
    $logger->info($quoteItemId." ===== ".$optionId);

    foreach ($quoteItems as $item) {
        if ($item->getItemId() == $quoteItemId) {
            $logger->info("item found");
            // Fetch the custom options for the item
            $options = $item->getBuyRequest()->getOptions();
            $logger->info(print_r($options[$optionId],true));
            if (isset($options[$optionId])) {
                $logger->info("options found");
                // Remove the custom option from the item
                $item->removeOption($optionId);
                $quote->save();
                $this->quoteRepository->save($quote);
                $quote->save();
            }
            break;
        }
    }