I have a product attribute that have been added directly in the database threw a migration process.
I want to update that attribute to give him a source.
But this seems not to be working.
$attribute = $this->productAttributeRepositoryInterface->get('my_attribute_code');
$attributeId = $attribute->getAttributeId();
$this->eavSetupFactory->updateAttribute(
Product::ENTITY,
$attributeId,
[
'source' => 'Cpy\Module\Model\ResourceModel\MyAttribute\Options',
]
);
I have no error but the backend model in database seems to stay null.
Also tried :
try{
$attribute = $this->productAttributeRepositoryInterface->get('encombrement');
$attributeId = $attribute->getAttributeId();
$this->eavSetupFactory->updateAttribute(
4,
$attributeId,
'source',
'Cpy\Module\Model\ResourceModel\MyAttribute\Options'
);
}catch(Exception $e){
var_dump($e->getMessage());
}
Full method
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
if (version_compare($context->getVersion(), '0.0.2') < 0) {
// ....
}
if (version_compare($context->getVersion(), '0.0.3') < 0) {
try{
$attribute = $this->productAttributeRepositoryInterface->get('encombrement');
$attributeId = $attribute->getAttributeId();
$this->eavSetupFactory->updateAttribute(
4,
$attributeId,
'source',
'Cpy\Module\Model\ResourceModel\MyAttribute\Options'
);
}catch(Exception $e){
var_dump($e->getMessage());
}
}
$setup->endSetup();
}