I have to change the type of an attribute from text to decimal. I used upgrade script below. But it is not working
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
class UpgradeData implements UpgradeDataInterface
{
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '1.0.1', '<')) {
$entityType = $eavSetup->getEntityTypeId('catalog_product');
$eavSetup->updateAttribute($entityType, 'as_low_as', 'frontend_input','decimal', null);
}
}
}
How can we update the attribute type of an existing attribute?
Best Answer
Frontend input should be text
Backend type should be decimal
If wanting it to be a price, don't forget to add backend model:
Magento\Catalog\Model\Product\Attribute\Backend\Price
. Andfrontend_input
should beprice
,backend_type
should bedecimal
.[EDIT]
We can remove the old one, and add new one: