Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

unopim/unopim

7807 stars
1 code files
View unopim/unopim on GitHub

packages/Webkul/Product/src/Console/Commands/Indexer.php

Open in GitHub
use Illuminate\Console\Command;
use Webkul\Product\Helpers\Indexers\ElasticSearch;
 
class Indexer extends Command
{
protected $indexers = [
'elastic' => ElasticSearch::class,
];
 
protected $signature = 'indexer:index {--type=*} {--mode=*}';
 
protected $description = 'Automatically updates product price and inventory indices';
 
public function handle()
{
$start = microtime(true);
 
$indexerIds = ['elastic'];
 
if (! empty($this->option('type'))) {
$indexerIds = $this->option('type');
}
 
$mode = 'selective';
 
if (! empty($this->option('mode'))) {
$mode = current($this->option('mode'));
}
 
foreach ($indexerIds as $indexerId) {
if (
$indexerId == 'elastic'
&& core()->getConfigData('catalog.products.storefront.search_mode') != 'elastic'
) {
continue;
}
 
$indexer = app($this->indexers[$indexerId]);
 
if ($mode == 'full') {
$indexer->reindexFull();
} else {
if ($indexerId != 'inventory') {
$indexer->reindexSelective();
}
}
}
 
$end = microtime(true);
 
echo 'The code took '.($end - $start)." seconds to complete.\n";
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.