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
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 [];
}
}