1

Can we add custom quote and order attribute/field using patch data in Magento 2.3.x ? If yes then how it can be done ?

1 Answer 1

0

Here is the method to add a custom Quote Attribute (programatically) in Magento 2.* using patch:

namespace Firewalls\ZipCheck\Setup\Patch\Data;

use Magento\Framework\DB\Ddl\Table;

use Magento\Framework\Setup\Patch\DataPatchInterface;

use Magento\Quote\Setup\QuoteSetup;

class SelectedShippingMethods implements DataPatchInterface
{
    private $quoteSetup;

    public function __construct(
        QuoteSetup $quoteSetup
    )
    {
        $this->quoteSetup = $quoteSetup;
    }

    public function apply()
    {
        $this->quoteSetup->addAttribute(
            'quote_item',
            'custom_attribute_code',
            [
                'type'=> Table::TYPE_TEXT,
                'nullable'=>true,
                'comment'=>'Selected Shipping Methods'
            ]
        );
    }

    public static function getDependencies()
    {
        return [];
    }

    public function getAliases()
    {
        return [];
    }


}

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.