Skip to content

Commit

Permalink
Merge pull request #13 from ConvertGroupsAS/invalidate-category-flat-…
Browse files Browse the repository at this point in the history
…index

Invalidate category flat index
  • Loading branch information
amenk authored Oct 17, 2019
2 parents a7cd18c + 636843e commit f7b5de4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
29 changes: 26 additions & 3 deletions Setup/InstallData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Mestrona\CategoryRedirect\Setup;

use Magento\Catalog\Model\Indexer\Category\Flat\State;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Indexer\IndexerRegistry;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
Expand All @@ -17,13 +20,29 @@ class InstallData implements InstallDataInterface
private $eavSetupFactory;

/**
* Init
* Flat category indexer state
*
* @var State
*/
protected $flatState;

/**
* Indexer registry
*
* @var IndexerRegistry
*/
protected $indexerRegistry;

/**
* @param EavSetupFactory $eavSetupFactory
* @param State $flatState
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(EavSetupFactory $eavSetupFactory)
public function __construct(EavSetupFactory $eavSetupFactory, State $flatState, IndexerRegistry $indexerRegistry)
{
$this->eavSetupFactory = $eavSetupFactory;
$this->flatState = $flatState;
$this->indexerRegistry = $indexerRegistry;
}

/**
Expand Down Expand Up @@ -56,5 +75,9 @@ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface
'visible_on_front' => true,
]
);

if ($this->flatState->isFlatEnabled()) {
$this->indexerRegistry->get(State::INDEXER_ID)->invalidate();
}
}
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "mestrona/magento-module-categoryredirect",
"description": "Magento 2 Module to simply customize the menu with additional URLs: Create a category, enter the redirect, done.",
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0|~7.1.0",
"magento/module-catalog": "^100.0.0|^101.0.0|^102.0.0"
"php": "^7.0",
"magento/module-catalog": "^100.0.0 || ^101.0.0 || ^102.0.0 || ^103.0"
},
"type": "magento2-module",
"license": [
Expand Down

0 comments on commit f7b5de4

Please sign in to comment.