Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSTALL DATA PHP
- <?php
- namespace Vaimo\Brand\Setup;
- use Magento\Eav\Setup\EavSetup;
- use Magento\Eav\Setup\EavSetupFactory;
- use Magento\Framework\Setup\InstallDataInterface;
- use Magento\Framework\Setup\ModuleContextInterface;
- use Magento\Framework\Setup\ModuleDataSetupInterface;
- class InstallData implements InstallDataInterface
- {
- private $eavSetupFactory;
- public function __construct(EavSetupFactory $eavSetupFactory)
- {
- $this->eavSetupFactory = $eavSetupFactory;
- }
- public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
- $eavSetup->addAttribute(
- \Magento\Catalog\Model\Product::ENTITY,
- 'trainee_brand_attribute',
- [
- 'type' => 'text',
- 'backend' => '',
- 'frontend' => '',
- 'label' => 'Trainee Brand Attribute',
- 'input' => 'select',
- 'class' => '',
- 'source' => 'Vaimo\Brand\Model\Config\Source\Options',
- 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
- 'visible' => true,
- 'required' => true,
- 'user_defined' => false,
- 'default' => '',
- 'searchable' => false,
- 'filterable' => false,
- 'comparable' => false,
- 'visible_on_front' => false,
- 'used_in_product_listing' => true,
- 'unique' => false,
- 'apply_to' => ''
- ]
- );
- }
- }
- UPGRADE DATA PHP
- <?php
- namespace Vaimo\Brand\Setup;
- use Magento\Framework\Setup\UpgradeDataInterface;
- use Magento\Framework\Setup\ModuleDataSetupInterface;
- use Magento\Framework\Setup\ModuleContextInterface;
- class UpgradeData implements UpgradeDataInterface
- {
- protected $_postFactory;
- public function __construct(\Vaimo\Brand\Model\PostFactory $postFactory)
- {
- $this->_postFactory = $postFactory;
- }
- public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
- {
- if (version_compare($context->getVersion(), '1.0.0', '<')) {
- $data = [
- 'brand_id' => "455867895467",
- 'brand_title' => "Absolutely Awesome Brand",
- 'brand_origin' => 'United Kingdom'
- ];
- $post = $this->_postFactory->create();
- $post->addData($data)->save();
- }
- }
- }
- INSTALL SCHEMA PHP
- namespace Vaimo\Brand\Setup;
- class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
- {
- public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
- {
- $installer = $setup;
- $installer->startSetup();
- if (!$installer->tableExists('vaimo_brand')) {
- $table = $installer->getConnection()->newTable(
- $installer->getTable('vaimo_brand')
- )
- ->addColumn(
- 'brand_id',
- \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
- null,
- [
- 'identity' => true,
- 'nullable' => false,
- 'primary' => true,
- 'unsigned' => true,
- ],
- 'Brand Id'
- )
- ->addColumn(
- 'brand_title',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 255,
- ['nullable => false'],
- 'Brand Title'
- )
- ->addColumn(
- 'brand_сountry',
- \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
- 255,
- [],
- 'Brand Country'
- )
- ->setComment('Trainee Brand Table');
- $installer->getConnection()->createTable($table);
- }
- $installer->endSetup();
- }
- }
- UPGRADE SCHEMA PHP
- namespace Vaimo\Brand\Setup;
- use Magento\Framework\Setup\UpgradeSchemaInterface;
- use Magento\Framework\Setup\SchemaSetupInterface;
- use Magento\Framework\Setup\ModuleContextInterface;
- class UpgradeSchema implements UpgradeSchemaInterface
- {
- public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
- $installer = $setup;
- $installer->startSetup();
- if(version_compare($context->getVersion(), '1.0.0', '<')) {
- $installer->getConnection()->addColumn(
- $installer->getTable( 'vaimo_brand' ),
- 'test',
- [
- 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
- 'nullable' => true,
- 'length' => '12,4',
- 'comment' => 'test',
- 'after' => 'brand_title'
- ]
- );
- }
- $installer->endSetup();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement