Ive tried to add 2 product attributes in Magento 2.3.5 programatically using install data. The attributes aren't being created and after some searching i found out that > 2.3.3 install and upgrade data where phased out for a declarative approach. Does anyone have any examples on how to do this outside of installdata/upgradedata? Here is what i was trying to add:
<?php
namespace XX\Pricing\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->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_price_tier');
$eavSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_price_tier', [
'group' => 'Product Price Tier',
'type' => 'int',
'sort_order' => 200,
'backend' => '',
'frontend' => '',
'label' => 'Custom Yes/No',
'input' => 'boolean',
'class' => '',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_price_family');
$eavSetup->addAttribute(\Magento\Catalog\Model\Product::ENTITY, 'product_price_family', [
'group' => 'Product Details',
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'sort_order' => 220,
'label' => 'Product Price Family',
'input' => 'text',
'class' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'unique' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'apply_to' => ''
]);
}
}