2

I created custom entity type which existing in eav_entity_type table.

But, I want to update value of entity_model, attribute_model & etc.

How to update it?

Any help would be appreciated.

1 Answer 1

1

You can create UpgradeData.php script and update value using below code :

<?php
namespace VendorName\ModuleName\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Eav\Setup\EavSetupFactory;
use VendorName\ModuleName\Setup\ModuleNameSetup;

class UpgradeData implements UpgradeDataInterface
{
    /**
     * @var EavSetupFactory
     */
    protected $eavSetupFactory;

    /**
     * [__construct description]
     * @param EavSetupFactory $eavSetupFactory [description]
     */
    public function __construct(
        EavSetupFactory $eavSetupFactory
    )
    {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {

        $setup->startSetup();

        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        if (version_compare($context->getVersion(), '1.0.1', '<')) {
            $entityType = $eavSetup->getEntityTypeId(ModuleNameSetup::ENTITY_TYPE_CODE);

            $data = [
                'entity_type_code' => ModuleNameSetup::ENTITY_TYPE_CODE, //your entity_type_code
                'entity_model' => \VendorName\ModuleName\Model\ResourceModel\ModuleName::class,
                'attribute_model' => \VendorName\ModuleName\Model\ResourceModel\Eav\Attribute::class,
                'entity_table' => ModuleNameSetup::ENTITY_TYPE_CODE, //your entity_table name
                'entity_attribute_collection' => \VendorName\ModuleName\Model\ResourceModel\Attribute\Collection::class
                // add fields which you want to update value
            ];
            $eavSetup->updateEntityType(ModuleNameSetup::ENTITY_TYPE_CODE, $data);
        }
        $setup->endSetup();
    }
}

Note : Make sure before upgrade, your module's setup_version is 1.0.1

Hope, It will helpful for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.