0

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.

2 Answers 2

0

You can achieve this according to me by creating event and observer. I have some findings just you need to do minor changes. Please refer :
https://community.magento.com/t5/Magento-2-x-Programming/Magento-2-add-custom-attributes-in-quote-and-order/td-p/477189 Might be helpful for you. If it is so let me know, and revert back on this post. Thank You.

0
if ($subject->getCustomerIsGuest()) {
    $quote = $this->quoteFactory->create()->loadByIdWithoutStore($subject->getQuoteId());
    $quote->setCustomerHitAuthnetProfileLimit(1);
    $this->quoteRepository->save($quote);
    return;
    }

Can you try above code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.