Skip to content

Instantly share code, notes, and snippets.

@0-Sony
Created October 12, 2020 08:13
Show Gist options
  • Save 0-Sony/7a1089fc392f1850ce650dc4bf868630 to your computer and use it in GitHub Desktop.
Save 0-Sony/7a1089fc392f1850ce650dc4bf868630 to your computer and use it in GitHub Desktop.
Magento 2 : Add Quote Item / Order Item attribute (Patch/Schema)
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]>
* @copyright Copyright (c) 2020 Men In Code Ltd (https://www.menincode.com)
*/
namespace MyNamespace\MyModule\Setup\Patch\Schema;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
class AddCustomQuoteItemOrderItemAttribute implements SchemaPatchInterface
{
/**
* @var \Magento\Quote\Setup\QuoteSetup
*/
private $quoteSetup;
/**
* @var \Magento\Sales\Setup\SalesSetup
*/
private $salesSetup;
/**
* AddCustomQuoteItemOrderItemAttribute constructor.
* @param \Magento\Quote\Setup\QuoteSetup $quoteSetup
* @param \Magento\Sales\Setup\SalesSetup $salesSetup
*/
public function __construct(
\Magento\Quote\Setup\QuoteSetup $quoteSetup,
\Magento\Sales\Setup\SalesSetup $salesSetup
) {
$this->quoteSetup = $quoteSetup;
$this->salesSetup = $salesSetup;
}
/**
* @return string[]
*/
public static function getDependencies()
{
return [];
}
/**
* @return string[]
*/
public function getAliases()
{
return [];
}
/**
* @return AddCustomQuoteItemOrderItemAttribute|void
*/
public function apply()
{
$this->quoteSetup->addAttribute(
'quote_item',
'custom_attribute',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'comment' => 'custom attribute'
]
);
$this->salesSetup->addAttribute(
'order_item',
'custom_attribute',
[
'type' => Table::TYPE_TEXT,
'nullable' => true,
'comment' => 'custom attribute'
]
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment