In custom module, I have InstallSchema.php
and a InstallData.php
files.
InstallSchema.php
seems to be running fine, both tables declared in file are created.
But with the InstallData.php
nothing happens.
InstallData.php
<?php
namespace VVV\Comercial\Setup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Catalog\Setup\CategorySetupFactory;
class InstallData implements InstallDataInterface
{
protected $customerSetupFactory;
private $attributeSetFactory;
private $categorySetupFactory;
private $eavSetupFactory;
public function __construct(
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory,
EavSetupFactory $eavSetupFactory,
CategorySetupFactory $categorySetupFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
$this->eavSetupFactory = $eavSetupFactory;
$this->categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
/** @var CustomerSetup $customerSetup */
//$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Customer::ENTITY,
'is_commercial',
[
'type' => 'int',
'label' => __('Commercial user'),
'input' => 'boolean',
'required' => false,
'sort_order' => 100,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
//'group' => 'General Information',
//'is_used_in_grid' => true,
//'is_visible_in_grid' => false,
//'is_filterable_in_grid' => true,
]
);
$setup->endSetup();
/*$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'is_commercial', [
'type' => 'int',
'label' => __('Commercial user'),
"default" => 0,
'input' => 'boolean',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'is_commercial')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['adminhtml_customer'],
]);
$attribute->save();*/
}
}
The attribute is not created in eav_attribute
table, also setup_module
table not filled data_version
columna when running setup:upgrade.
There is a way to debug a bit more this kind of stuff?
Why InstallData.php
does not seems to be running.
For tests, I delete the row in setup_table
then run setup:upgrade.
I have to do something else to be able to run the InstallData.php
?
data_version
in thesetup_module
on setup:upgrade?