use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Webkul\Product\Helpers\Indexers\ElasticSearch;
use Webkul\Product\Repositories\ProductRepository;
class UpdateCreateIndex implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected $productIds)
{
$this->productIds = $productIds;
}
public function handle()
{
if (core()->getConfigData('catalog.products.storefront.search_mode') != 'elastic') {
return;
}
$ids = implode(',', $this->productIds);
$products = app(ProductRepository::class)
->whereIn('id', $this->productIds)
->orderByRaw("FIELD(id, $ids)")
->get();
app(ElasticSearch::class)->reindexRows($products);
}
}