0

i have added new custom column in quote_item table. i want to add the value in that custom column by item_id in controller. i have item_id 16,17,18 of quote 3 and i want to add value in custom column for particular row

i have item_id 16 of quote 3 and i want to add value in custom column for particular row

1
  • Use InstallSchema class or UpgradeSchema class or for magento 2.3 and above you can use db_schema.xml
    – Avesh Naik
    Jan 22 at 7:44

1 Answer 1

0
  <?php
  /**
   * @package Vendor_Module
  */
  declare(strict_types=1);

  namespace Vendor\Module\Helper;

  use \Magento\Framework\App\Helper\AbstractHelper;
  use Magento\Checkout\Model\Session;
  use Magento\Quote\Model\QuoteRepository;

  class Data extends AbstractHelper
  {
      /**
       * @var Session
      */
      private $checkoutSession;

      /**
       * @var QuoteRepository
      */
      private $quoteRepository;
       
      public function __construct(
         Session $checkoutSession,
         QuoteRepository $quoteRepository
      ) {
           $this->checkoutSession = $checkoutSession;
           $this->quoteRepository = $quoteRepository;
      }
     
      public function addCustomValuetoQuoteItem($cartId) 
      {
         $quote = $this->quoteRepository->get($cartId);
         foreach ($quote->getAllVisibleItems() as $item) {
            if (your condition) {
               continue;
            }
            $item->setData('custom_column', 'hello');
            $item->save();
      }
   }
}
1
  • It's worked for me
    – Vigesh P v
    Jan 24 at 13: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.