From bd47b7dfbb4d5e56985f837fc6f451cb69c21d70 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Tue, 7 Jun 2022 15:46:22 -0700 Subject: [PATCH 01/10] adds declrative schema and remove scripts --- Setup/InstallData.php | 99 ----- Setup/InstallSchema.php | 128 ------- Setup/Patch/Data/AddCustomerAttribute.php | 94 +++++ .../Data/AddProductCategoryAttributes.php | 349 ++++++++++++++++++ Setup/Uninstall.php | 99 ----- Setup/UpgradeData.php | 347 ----------------- Setup/db_schema.xml | 28 ++ 7 files changed, 471 insertions(+), 673 deletions(-) delete mode 100644 Setup/InstallData.php delete mode 100755 Setup/InstallSchema.php create mode 100644 Setup/Patch/Data/AddCustomerAttribute.php create mode 100644 Setup/Patch/Data/AddProductCategoryAttributes.php delete mode 100644 Setup/Uninstall.php delete mode 100644 Setup/UpgradeData.php create mode 100644 Setup/db_schema.xml diff --git a/Setup/InstallData.php b/Setup/InstallData.php deleted file mode 100644 index 6924b093..00000000 --- a/Setup/InstallData.php +++ /dev/null @@ -1,99 +0,0 @@ -customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); - - $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); - $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - - /** @var $attributeSet AttributeSet */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - $attributeCode = 'affirm_customer_mfp'; - - $customerSetup->addAttribute(Customer::ENTITY, $attributeCode, [ - 'type' => 'varchar', - 'input' => 'text', - 'required' => 0, - 'label' => 'Multiple Financing Program value', - 'global' => 1, - 'visible' => 1, - 'user_defined' => 1, - 'sort_order' => 1000, - 'position' => 1000, - 'system' => 0 - ]); - - $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $attributeCode) - ->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId, - 'used_in_forms' => ['adminhtml_customer'], - ]); - - $attribute->save(); - } -} diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php deleted file mode 100755 index 1bec95ff..00000000 --- a/Setup/InstallSchema.php +++ /dev/null @@ -1,128 +0,0 @@ -startSetup(); - - $table = $installer - ->getConnection() - ->newTable($installer->getTable('astound_affirm_rule')) - ->addColumn( - 'rule_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true] - ) - ->addColumn( - 'for_admin', - \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, - null, - ['nullable' => false, 'unsigned' => true, 'default' => 0] - ) - ->addColumn( - 'is_active', - \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, - null, - ['nullable' => false, 'unsigned' => true, 'default' => 0] - ) - ->addColumn( - 'all_stores', - \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, - null, - ['nullable' => false, 'unsigned' => true, 'default' => 0] - ) - ->addColumn( - 'all_groups', - \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN, - null, - ['nullable' => false, 'unsigned' => true, 'default' => 0] - ) - ->addColumn( - 'name', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['default' => null, 'nullable' => false] - ) - ->addColumn( - 'stores', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['default' => '', 'nullable' => false] - ) - ->addColumn( - 'cust_groups', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['default' => '', 'nullable' => false] - ) - ->addColumn( - 'message', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - null, - ['default' => '', 'nullable' => false] - ) - ->addColumn( - 'methods', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - null, - ['default' => null, 'nullable' => true] - ) - ->addColumn( - 'conditions_serialized', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - null, - ['default' => null, 'nullable' => true] - ); - - $installer->getConnection()->createTable($table); - - $table = $installer - ->getConnection() - ->newTable($installer->getTable('astound_affirm_attribute')) - ->addColumn( - 'attr_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true] - ) - ->addColumn( - 'rule_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['unsigned' => true, 'nullable' => false] - ) - ->addColumn( - 'code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - ['default' => null, 'nullable' => true] - ) - ->addIndex('rule_id', 'rule_id') - ->addForeignKey( - $installer->getFkName( - 'astound_affirm_attribute', - 'rule_id', - 'astound_affirm_rule', - 'rule_id' - ), - 'rule_id', - $installer->getTable('astound_affirm_rule'), - 'rule_id', - \Magento\Framework\DB\Ddl\Table::ACTION_CASCADE - ); - - $installer->getConnection()->createTable($table); - - $installer->endSetup(); - } -} \ No newline at end of file diff --git a/Setup/Patch/Data/AddCustomerAttribute.php b/Setup/Patch/Data/AddCustomerAttribute.php new file mode 100644 index 00000000..2e87fb18 --- /dev/null +++ b/Setup/Patch/Data/AddCustomerAttribute.php @@ -0,0 +1,94 @@ +moduleDataSetup = $moduleDataSetup; + $this->customerSetupFactory = $customerSetupFactory; + $this->attributeSetFactory = $attributeSetFactory; + $this->eavSetupFactory = $eavSetupFactory; + } + + /** + * Do Upgrade + * + * @return void + */ + public function apply() + { + + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); + + /** @var $attributeSet AttributeSet */ + $attributeSet = $this->attributeSetFactory->create(); + $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); + $attributeCode = 'affirm_customer_mfp'; + + $eavSetup->addAttribute(Customer::ENTITY, $attributeCode, [ + 'type' => 'varchar', + 'input' => 'text', + 'required' => 0, + 'label' => 'Multiple Financing Program value', + 'global' => 1, + 'visible' => 1, + 'user_defined' => 1, + 'sort_order' => 1000, + 'position' => 1000, + 'system' => 0 + ]); + + $eavSetup->getAttribute(Customer::ENTITY, $attributeCode) + ->addData([ + 'attribute_set_id' => $attributeSetId, + 'attribute_group_id' => $attributeGroupId, + 'used_in_forms' => ['adminhtml_customer'], + ]); + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } +} diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php new file mode 100644 index 00000000..78f123a8 --- /dev/null +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -0,0 +1,349 @@ +moduleDataSetup = $moduleDataSetup; + $this->eavSetupFactory = $eavSetupFactory; + $this->context = $context; + } + + /** + * Do Upgrade + * + * @return void + */ + public function apply() + { + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + + if (version_compare($context->getVersion(), '0.4.2', '<')) { + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp', + [ + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program value', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); + + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp', + [ + 'type' => 'varchar', + 'label' => 'Multiple Financing Program value', + 'input' => 'text', + 'required' => 0, + 'sort_order' => 100, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); + } + + if (version_compare($context->getVersion(), '0.4.3', '<')) { + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_type', + [ + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program type', + 'input' => 'select', + 'class' => '', + 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_priority', + [ + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program priority', + 'input' => 'text', + 'class' => 'validate-number', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); + + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_type', + [ + 'type' => 'int', + 'label' => 'Multiple Financing Program type', + 'input' => 'select', + 'required' => 0, + 'sort_order' => 101, + 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_priority', + [ + 'type' => 'int', + 'label' => 'Multiple Financing Program priority', + 'input' => 'text', + 'class' => 'validate-number', + 'required' => 0, + 'sort_order' => 102, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); + } + + if (version_compare($context->getVersion(), '1.0.2', '<')) { + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_start_date', + [ + 'type' => 'datetime', + 'backend' => '', + 'frontend' => '', + 'label' => 'Start date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_end_date', + [ + 'type' => 'datetime', + 'backend' => '', + 'frontend' => '', + 'label' => 'End date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_start_date', + [ + 'type' => 'datetime', + 'label' => 'Start date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'required' => 0, + 'sort_order' => 103, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + 'used_in_product_listing' => 1, + ] + ); + + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_end_date', + [ + 'type' => 'datetime', + 'label' => 'End date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'required' => 0, + 'sort_order' => 104, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + 'used_in_product_listing' => 1, + ] + ); + } + + if (version_compare($context->getVersion(), '1.0.3', '<')) { + + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_promo_id', + [ + 'type' => 'varchar', + 'label' => 'Affirm Promo ID', + 'input' => 'text', + 'required' => 0, + 'sort_order' => 105, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); + + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_promo_id', + [ + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Affirm Promo ID', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); + } + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } +} diff --git a/Setup/Uninstall.php b/Setup/Uninstall.php deleted file mode 100644 index a153effa..00000000 --- a/Setup/Uninstall.php +++ /dev/null @@ -1,99 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - $this->customerSetupFactory = $customerSetupFactory; - $this->setup = $setup; - } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function uninstall(SchemaSetupInterface $schemaSetup, ModuleContextInterface $context) - { - /** @var CustomerSetup $customerSetup */ - $attributeCode = 'affirm_customer_mfp'; - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->setup]); - $customerSetup->removeAttribute(Customer::ENTITY, $attributeCode); - - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->setup]); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_type'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_priority'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_type'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_priority'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_start_date'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_end_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_start_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_end_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_promo_id'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_promo_id'); - - // Drop tables - $schemaSetup->startSetup(); - $this->dropTable($schemaSetup, 'astound_affirm_rule'); - $this->dropTable($schemaSetup, 'astound_affirm_attribute'); - $schemaSetup->endSetup(); - - } - - /** - * @param SchemaSetupInterface $schemaSetup - * @param string $tableName - */ - private function dropTable(SchemaSetupInterface $schemaSetup, $tableName) - { - $connection = $schemaSetup->getConnection(); - $connection->dropTable($schemaSetup->getTable($tableName)); - } -} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php deleted file mode 100644 index e2dfb292..00000000 --- a/Setup/UpgradeData.php +++ /dev/null @@ -1,347 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - } - - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - ; - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); - - if (version_compare($context->getVersion(), '0.4.2', '<')) { - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp', - [ - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program value', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); - - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp', - [ - 'type' => 'varchar', - 'label' => 'Multiple Financing Program value', - 'input' => 'text', - 'required' => 0, - 'sort_order' => 100, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - } - - if (version_compare($context->getVersion(), '0.4.3', '<')) { - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program type', - 'input' => 'select', - 'class' => '', - 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_priority', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program priority', - 'input' => 'text', - 'class' => 'validate-number', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); - - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_type', - [ - 'type' => 'int', - 'label' => 'Multiple Financing Program type', - 'input' => 'select', - 'required' => 0, - 'sort_order' => 101, - 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_priority', - [ - 'type' => 'int', - 'label' => 'Multiple Financing Program priority', - 'input' => 'text', - 'class' => 'validate-number', - 'required' => 0, - 'sort_order' => 102, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - } - - if (version_compare($context->getVersion(), '1.0.2', '<')) { - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_start_date', - [ - 'type' => 'datetime', - 'backend' => '', - 'frontend' => '', - 'label' => 'Start date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_end_date', - [ - 'type' => 'datetime', - 'backend' => '', - 'frontend' => '', - 'label' => 'End date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_start_date', - [ - 'type' => 'datetime', - 'label' => 'Start date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'required' => 0, - 'sort_order' => 103, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - 'used_in_product_listing' => 1, - ] - ); - - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_end_date', - [ - 'type' => 'datetime', - 'label' => 'End date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'required' => 0, - 'sort_order' => 104, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - 'used_in_product_listing' => 1, - ] - ); - } - - if (version_compare($context->getVersion(), '1.0.3', '<')) { - - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_promo_id', - [ - 'type' => 'varchar', - 'label' => 'Affirm Promo ID', - 'input' => 'text', - 'required' => 0, - 'sort_order' => 105, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_promo_id', - [ - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Affirm Promo ID', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); - } - } -} diff --git a/Setup/db_schema.xml b/Setup/db_schema.xml new file mode 100644 index 00000000..c6e27cba --- /dev/null +++ b/Setup/db_schema.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + + + +
+
From df0432d788056b5fba262ae363e66229e8f0c144 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Tue, 7 Jun 2022 15:56:03 -0700 Subject: [PATCH 02/10] move directory for db_schema --- {Setup => etc}/db_schema.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {Setup => etc}/db_schema.xml (100%) diff --git a/Setup/db_schema.xml b/etc/db_schema.xml similarity index 100% rename from Setup/db_schema.xml rename to etc/db_schema.xml From 52e8338fc50f32944d6a459c482773031480a6e9 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Tue, 7 Jun 2022 15:56:24 -0700 Subject: [PATCH 03/10] generated db_schema allowlist --- etc/db_schema_whitelist.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 etc/db_schema_whitelist.json diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json new file mode 100644 index 00000000..15097f21 --- /dev/null +++ b/etc/db_schema_whitelist.json @@ -0,0 +1,31 @@ +{ + "astound_affirm_rule": { + "column": { + "rule_id": true, + "for_admin": true, + "is_active": true, + "all_stores": true, + "all_groups": true, + "name": true, + "stores": true, + "cust_groups": true, + "message": true, + "methods": true, + "conditions_serialized": true + }, + "constraint": { + "PRIMARY": true + } + }, + "astound_affirm_attribute": { + "column": { + "attr_id": true, + "rule_id": true, + "code": true + }, + "constraint": { + "PRIMARY": true, + "ASTOUND_AFFIRM_ATTRIBUTE_RULE_ID_ASTOUND_AFFIRM_RULE_RULE_ID": true + } + } +} \ No newline at end of file From 691e4ab3ad09de40bece82fcfb42c52ccc8504c0 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Wed, 8 Jun 2022 13:08:56 -0700 Subject: [PATCH 04/10] patch revert --- .../Data/AddProductCategoryAttributes.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php index 78f123a8..47c2cc53 100644 --- a/Setup/Patch/Data/AddProductCategoryAttributes.php +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -6,15 +6,19 @@ declare(strict_types=1); namespace Astound\Affirm\Setup\Patch\Data; + use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; +use Magento\Framework\Setup\Patch\PatchRevertableInterface; /** * Patch is mechanism, that allows to do atomic upgrade data changes */ -class AddProductCategoryAttributes implements DataPatchInterface +class AddProductCategoryAttributes implements + DataPatchInterface, + PatchRevertableInterface { /** * @var ModuleDataSetupInterface $moduleDataSetup @@ -41,8 +45,10 @@ public function __construct( */ public function apply() { + $this->moduleDataSetup->getConnection()->startSetup(); + /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->$moduleDataSetup]); if (version_compare($context->getVersion(), '0.4.2', '<')) { /** @@ -329,8 +335,36 @@ public function apply() ] ); } + $this->moduleDataSetup->getConnection()->endSetup(); + } + + /** + * @inheritdoc + */ + public function revert() + { + $this->moduleDataSetup->getConnection()->startSetup(); + + /** @var EavSetup $eavSetup */ + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->$moduleDataSetup]); + + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp'); + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_type'); + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_priority'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_type'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_priority'); + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_start_date'); + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_end_date'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_start_date'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_end_date'); + $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_promo_id'); + $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_promo_id'); + + $this->moduleDataSetup->getConnection()->endSetup(); } + /** * @inheritdoc */ From dddc5cb9a9d3629c995c374c1642b83465d90c04 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Wed, 8 Jun 2022 13:09:22 -0700 Subject: [PATCH 05/10] remove unused mpf configs --- Setup/Patch/Data/AddCustomerAttribute.php | 94 ----------------------- 1 file changed, 94 deletions(-) delete mode 100644 Setup/Patch/Data/AddCustomerAttribute.php diff --git a/Setup/Patch/Data/AddCustomerAttribute.php b/Setup/Patch/Data/AddCustomerAttribute.php deleted file mode 100644 index 2e87fb18..00000000 --- a/Setup/Patch/Data/AddCustomerAttribute.php +++ /dev/null @@ -1,94 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - $this->eavSetupFactory = $eavSetupFactory; - } - - /** - * Do Upgrade - * - * @return void - */ - public function apply() - { - - /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - - /** @var $attributeSet AttributeSet */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - $attributeCode = 'affirm_customer_mfp'; - - $eavSetup->addAttribute(Customer::ENTITY, $attributeCode, [ - 'type' => 'varchar', - 'input' => 'text', - 'required' => 0, - 'label' => 'Multiple Financing Program value', - 'global' => 1, - 'visible' => 1, - 'user_defined' => 1, - 'sort_order' => 1000, - 'position' => 1000, - 'system' => 0 - ]); - - $eavSetup->getAttribute(Customer::ENTITY, $attributeCode) - ->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId, - 'used_in_forms' => ['adminhtml_customer'], - ]); - } - - /** - * @inheritdoc - */ - public function getAliases() - { - return []; - } - - /** - * @inheritdoc - */ - public static function getDependencies() - { - return []; - } -} From af63db8c9b53f4126a1b5f8fb2b50b51522954f3 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Wed, 8 Jun 2022 23:45:46 -0700 Subject: [PATCH 06/10] remove context->getVersion --- .../Data/AddProductCategoryAttributes.php | 549 +++++++++--------- 1 file changed, 269 insertions(+), 280 deletions(-) diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php index 47c2cc53..c53d0457 100644 --- a/Setup/Patch/Data/AddProductCategoryAttributes.php +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -8,7 +8,6 @@ namespace Astound\Affirm\Setup\Patch\Data; use Magento\Eav\Setup\EavSetupFactory; -use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; @@ -30,12 +29,10 @@ class AddProductCategoryAttributes implements */ public function __construct( ModuleDataSetupInterface $moduleDataSetup, - ModuleContextInterface $context, EavSetupFactory $eavSetupFactory ) { $this->moduleDataSetup = $moduleDataSetup; $this->eavSetupFactory = $eavSetupFactory; - $this->context = $context; } /** @@ -48,293 +45,285 @@ public function apply() $this->moduleDataSetup->getConnection()->startSetup(); /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->$moduleDataSetup]); + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - if (version_compare($context->getVersion(), '0.4.2', '<')) { - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp', - [ - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program value', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp', + [ + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program value', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp', - [ - 'type' => 'varchar', - 'label' => 'Multiple Financing Program value', - 'input' => 'text', - 'required' => 0, - 'sort_order' => 100, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - } + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp', + [ + 'type' => 'varchar', + 'label' => 'Multiple Financing Program value', + 'input' => 'text', + 'required' => 0, + 'sort_order' => 100, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); - if (version_compare($context->getVersion(), '0.4.3', '<')) { - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_type', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program type', - 'input' => 'select', - 'class' => '', - 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_priority', - [ - 'type' => 'int', - 'backend' => '', - 'frontend' => '', - 'label' => 'Multiple Financing Program priority', - 'input' => 'text', - 'class' => 'validate-number', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 0, - 'unique' => 0, - 'apply_to' => '', - ] - ); + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_type', + [ + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program type', + 'input' => 'select', + 'class' => '', + 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_priority', + [ + 'type' => 'int', + 'backend' => '', + 'frontend' => '', + 'label' => 'Multiple Financing Program priority', + 'input' => 'text', + 'class' => 'validate-number', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 0, + 'unique' => 0, + 'apply_to' => '', + ] + ); - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_type', - [ - 'type' => 'int', - 'label' => 'Multiple Financing Program type', - 'input' => 'select', - 'required' => 0, - 'sort_order' => 101, - 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_priority', - [ - 'type' => 'int', - 'label' => 'Multiple Financing Program priority', - 'input' => 'text', - 'class' => 'validate-number', - 'required' => 0, - 'sort_order' => 102, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); - } + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_type', + [ + 'type' => 'int', + 'label' => 'Multiple Financing Program type', + 'input' => 'select', + 'required' => 0, + 'sort_order' => 101, + 'source' => 'Astound\Affirm\Model\Entity\Attribute\Source\FinancingProgramType', + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_priority', + [ + 'type' => 'int', + 'label' => 'Multiple Financing Program priority', + 'input' => 'text', + 'class' => 'validate-number', + 'required' => 0, + 'sort_order' => 102, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); - if (version_compare($context->getVersion(), '1.0.2', '<')) { - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_start_date', - [ - 'type' => 'datetime', - 'backend' => '', - 'frontend' => '', - 'label' => 'Start date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_start_date', + [ + 'type' => 'datetime', + 'backend' => '', + 'frontend' => '', + 'label' => 'Start date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_mfp_end_date', - [ - 'type' => 'datetime', - 'backend' => '', - 'frontend' => '', - 'label' => 'End date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_mfp_end_date', + [ + 'type' => 'datetime', + 'backend' => '', + 'frontend' => '', + 'label' => 'End date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_start_date', - [ - 'type' => 'datetime', - 'label' => 'Start date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'required' => 0, - 'sort_order' => 103, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - 'used_in_product_listing' => 1, - ] - ); + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_start_date', + [ + 'type' => 'datetime', + 'label' => 'Start date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'required' => 0, + 'sort_order' => 103, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + 'used_in_product_listing' => 1, + ] + ); - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_mfp_end_date', - [ - 'type' => 'datetime', - 'label' => 'End date for time based Financing Program value', - 'input' => 'date', - 'class' => '', - 'required' => 0, - 'sort_order' => 104, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - 'used_in_product_listing' => 1, - ] - ); - } + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_mfp_end_date', + [ + 'type' => 'datetime', + 'label' => 'End date for time based Financing Program value', + 'input' => 'date', + 'class' => '', + 'required' => 0, + 'sort_order' => 104, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + 'used_in_product_listing' => 1, + ] + ); - if (version_compare($context->getVersion(), '1.0.3', '<')) { + /** + * Add attributes to the category eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Category::ENTITY, + 'affirm_category_promo_id', + [ + 'type' => 'varchar', + 'label' => 'Affirm Promo ID', + 'input' => 'text', + 'required' => 0, + 'sort_order' => 105, + 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, + 'group' => 'General Information', + 'is_used_in_grid' => 0, + 'is_visible_in_grid' => 0, + 'is_filterable_in_grid' => 0, + ] + ); - /** - * Add attributes to the category eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Category::ENTITY, - 'affirm_category_promo_id', - [ - 'type' => 'varchar', - 'label' => 'Affirm Promo ID', - 'input' => 'text', - 'required' => 0, - 'sort_order' => 105, - 'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_WEBSITE, - 'group' => 'General Information', - 'is_used_in_grid' => 0, - 'is_visible_in_grid' => 0, - 'is_filterable_in_grid' => 0, - ] - ); + /** + * Add attributes to the product eav/attribute + */ + $eavSetup->addAttribute( + \Magento\Catalog\Model\Product::ENTITY, + 'affirm_product_promo_id', + [ + 'type' => 'varchar', + 'backend' => '', + 'frontend' => '', + 'label' => 'Affirm Promo ID', + 'input' => 'text', + 'class' => '', + 'source' => '', + 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, + 'group' => 'General', + 'visible' => 1, + 'required' => 0, + 'user_defined' => 0, + 'searchable' => 0, + 'filterable' => 0, + 'comparable' => 0, + 'visible_on_front' => 0, + 'used_in_product_listing' => 1, + 'unique' => 0, + 'apply_to' => '', + ] + ); - /** - * Add attributes to the product eav/attribute - */ - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - 'affirm_product_promo_id', - [ - 'type' => 'varchar', - 'backend' => '', - 'frontend' => '', - 'label' => 'Affirm Promo ID', - 'input' => 'text', - 'class' => '', - 'source' => '', - 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE, - 'group' => 'General', - 'visible' => 1, - 'required' => 0, - 'user_defined' => 0, - 'searchable' => 0, - 'filterable' => 0, - 'comparable' => 0, - 'visible_on_front' => 0, - 'used_in_product_listing' => 1, - 'unique' => 0, - 'apply_to' => '', - ] - ); - } $this->moduleDataSetup->getConnection()->endSetup(); } @@ -346,7 +335,7 @@ public function revert() $this->moduleDataSetup->getConnection()->startSetup(); /** @var EavSetup $eavSetup */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $this->$moduleDataSetup]); + $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp'); $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp'); From 9ce8bc31a6eda85dcacca9661f67f37462d8169c Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Thu, 9 Jun 2022 12:15:22 -0700 Subject: [PATCH 07/10] add revert --- .../Data/AddProductCategoryAttributes.php | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php index c53d0457..7ec2fa27 100644 --- a/Setup/Patch/Data/AddProductCategoryAttributes.php +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -11,13 +11,16 @@ use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; +use Magento\Framework\Setup\Patch\PatchVersionInterface; + /** * Patch is mechanism, that allows to do atomic upgrade data changes */ class AddProductCategoryAttributes implements DataPatchInterface, - PatchRevertableInterface + PatchRevertableInterface, + PatchVersionInterface { /** * @var ModuleDataSetupInterface $moduleDataSetup @@ -327,8 +330,9 @@ public function apply() $this->moduleDataSetup->getConnection()->endSetup(); } - /** - * @inheritdoc + /** + * Do revert. + * @return void */ public function revert() { @@ -337,18 +341,18 @@ public function revert() /** @var EavSetup $eavSetup */ $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_type'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_priority'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_type'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_priority'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_start_date'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_mfp_end_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_start_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_mfp_end_date'); - $eavSetup->removeAttribute(Category::ENTITY, 'affirm_category_promo_id'); - $eavSetup->removeAttribute(Product::ENTITY, 'affirm_product_promo_id'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_mfp'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_mfp'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_mfp_type'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_mfp_priority'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_mfp_type'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_mfp_priority'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_mfp_start_date'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_mfp_end_date'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_mfp_start_date'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_mfp_end_date'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Category::ENTITY, 'affirm_category_promo_id'); + $eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'affirm_product_promo_id'); $this->moduleDataSetup->getConnection()->endSetup(); } @@ -362,6 +366,14 @@ public function getAliases() return []; } + /** + * Get the version for the data patch + */ + public static function getVersion() + { + return '1.0.3'; + } + /** * @inheritdoc */ From 510195bc514c2c594d514c2f9ad746a95ec84464 Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Thu, 9 Jun 2022 12:15:40 -0700 Subject: [PATCH 08/10] version bump 3.1.3 --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 3005c0bd..f60f413f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "affirm/magento2", "description": "Affirm's extension for the Magento 2 https://www.affirm.com/", "type": "magento2-module", - "version": "3.1.2", + "version": "3.1.3", "license": [ "BSD-3-Clause" ], diff --git a/etc/module.xml b/etc/module.xml index 7840feb1..747f9103 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -10,7 +10,7 @@ */ --> - + From 0663f1a81b8e5c0467f738a7963a177197bba8ec Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Thu, 9 Jun 2022 12:34:33 -0700 Subject: [PATCH 09/10] version bump 3.1.3 --- Setup/Patch/Data/AddProductCategoryAttributes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php index 7ec2fa27..d3c215e2 100644 --- a/Setup/Patch/Data/AddProductCategoryAttributes.php +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -371,7 +371,7 @@ public function getAliases() */ public static function getVersion() { - return '1.0.3'; + return '3.1.3'; } /** From cf2b583898f22e66208fcaf57677b8f0112230df Mon Sep 17 00:00:00 2001 From: taehyunlim Date: Thu, 9 Jun 2022 12:40:47 -0700 Subject: [PATCH 10/10] remove patch version --- Setup/Patch/Data/AddProductCategoryAttributes.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Setup/Patch/Data/AddProductCategoryAttributes.php b/Setup/Patch/Data/AddProductCategoryAttributes.php index d3c215e2..f4118743 100644 --- a/Setup/Patch/Data/AddProductCategoryAttributes.php +++ b/Setup/Patch/Data/AddProductCategoryAttributes.php @@ -11,7 +11,6 @@ use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\Patch\DataPatchInterface; use Magento\Framework\Setup\Patch\PatchRevertableInterface; -use Magento\Framework\Setup\Patch\PatchVersionInterface; /** @@ -19,8 +18,7 @@ */ class AddProductCategoryAttributes implements DataPatchInterface, - PatchRevertableInterface, - PatchVersionInterface + PatchRevertableInterface { /** * @var ModuleDataSetupInterface $moduleDataSetup @@ -366,14 +364,6 @@ public function getAliases() return []; } - /** - * Get the version for the data patch - */ - public static function getVersion() - { - return '3.1.3'; - } - /** * @inheritdoc */