1

Points:

1.In my case i created a 'Customer Provident' product using upgradeData.php with version 1.0.3 and module version also 1.0.3 and it's created successfully.

2.Second time i wrote the code to update the table column using Upgradeschema.php with version 1.0.5 and module version 1.0.5 worked successfully.

3.Now i deleted the product 'Customer Provident' from magento backend and i want to create same product if we upgrade once.Is this possible one this time i don't change module.xml version it's as it is 1.0.5 but this product not created

  1. But this time i want to create the product

Is there any way to achieve it,if anyone have idea please guide me.

  • @All, RecurringData.php made this scenario awesome way – hitesh balpande May 16 at 14:07
4

@Hitesh,

when you run upgrade command it will run UpgradeData.php file and in that it will compare the version based on that version it will execute the code,

Since the product creation code is not present in the current version. That will not create the product for you.

Better approach is use RecurringData.php

The recurring scripts are executed after any module setup. They also execute on each and every setup:upgrade command, regardless of the schema_version or data_version logged against the setup_module table.

Note: You need to check if the Product created is exist already, otherwise you mayget constraint error

I hope this will help in your scenario.

0

Please check RecurringData.php worked for me.

<?php
    namespace Vendor\Module\Setup;
    use Magento\Framework\Setup\InstallDataInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\ModuleDataSetupInterface;
    use Magento\Customer\Model\GroupFactory;


    class RecurringData implements InstallDataInterface
    {

        protected $_indexerFactory;
        public $indexerIds = array(
                'catalog_category_product',
                'catalog_product_category',
                'catalog_product_price',
                'catalog_product_attribute',
                'cataloginventory_stock',
                'catalogrule_product',
                'catalogsearch_fulltext',
            );


        public function __construct(
            \Magento\Indexer\Model\IndexerFactory $indexerFactory
        ) {
            $this->_indexerFactory = $indexerFactory;
        }

        public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        {
            $this->reindexAll();
        }

        public function reindexAll() {
            foreach ($this->indexerIds as $indexerId) {
                $indexer = $this->_indexerFactory->create();
                $indexer->load($indexerId);
                $indexer->reindexAll();
            }
        }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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