Add properties filtering and relationships in Product model
This commit is contained in:
47
app/Console/Commands/SyncProductPropertiesJson.php
Normal file
47
app/Console/Commands/SyncProductPropertiesJson.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ecommerce\Product\Product\Product;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class SyncProductPropertiesJson extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'products:sync-properties-json';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Syncs all product properties to the new JSON column';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Starting sync of product properties JSON...');
|
||||
|
||||
// Using cursor to be memory efficient
|
||||
$products = Product::cursor();
|
||||
$count = Product::count();
|
||||
|
||||
$bar = $this->output->createProgressBar($count);
|
||||
$bar->start();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$product->syncPropertiesJson();
|
||||
$bar->advance();
|
||||
}
|
||||
|
||||
$bar->finish();
|
||||
$this->newLine();
|
||||
$this->info('Sync completed successfully!');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user