Skip to content

Adding Custom attribute to Quote magento 2

I need to set a custom attribute to Quote entity. I saw some tutorials on how to set a custom attribute to quote_item, followed a similar structure, but it didn’t work.

I’m on Magento 2.4.4

Here is where i set the attribute:

        $quoteSetup = $this->quoteSetupFactory->create(['setup' => $setup]);

        $quoteSetup->addAttribute('customer_hit_authnet_profile_limit', 'boolean', [
            'type' => 'int',
            'label' => 'Authnet over profile limit',
            'input' => 'boolean',
            'sort_order' => 83,
            'source' => '',
            'global' => 1,
            'visible_on_front' => 1,
            'group' => 'quote',
            'visible' => 1,
            'required' => 0,
            'user_defined' => 1,
            'default' => 0,
            'backend' => '',
            'system' => 0,
        ]);

Here is where I try to set it.

        if ($subject->getCustomerIsGuest()) {
        $quote = $this->quoteFactory->create()->loadByIdWithoutStore($subject->getQuoteId());
        $quote->setCustomAttribute('customer_hit_authnet_profile_limit', '1');
        $this->quoteRepository->save($quote);
        return;
        }

I would really apreciate if any of you could help me.
Thanks.