Comment out ProductStocksSeeder in DatabaseSeeder and implement stock updates in ProductStocksSeeder

- Commented out the ProductStocksSeeder in DatabaseSeeder for future adjustments.
- Implemented stock updates in ProductStocksSeeder to update product stock and inventory based on data from stocks.json.
- Enhanced transaction handling and ensured proper sequence setting for inventory_product table.
This commit is contained in:
Mekan1206
2026-02-11 03:42:54 +05:00
parent e2adf5e9da
commit e70ec773f9
2 changed files with 22 additions and 17 deletions

View File

@@ -45,7 +45,7 @@ class DatabaseSeeder extends Seeder
// ProductBarcodesSeeder::class,
// ProductPropertiesSeeder::class,
// ProductPropertyValuesSeeder::class,
ProductStocksSeeder::class,
// ProductStocksSeeder::class,
]);
}
}

View File

@@ -11,24 +11,29 @@ class ProductStocksSeeder extends Seeder
{
public function run()
{
//
// DB::transaction(function () {
// $table = 'products';
DB::transaction(function () {
$items = Items::fromFile(
database_path('data/stocks.json'),
['decoder' => new ExtJsonDecoder(true)]
);
// DB::table($table)->truncate();
// First we update stock in products table, then in inventory_product table
foreach ($items as $data) {
DB::table('products')->where('id', $data['item_id'])->update([
'stock' => $data['quantity'],
]);
// $items = Items::fromFile(
// database_path('data/items.json'),
// ['decoder' => new ExtJsonDecoder(true)]
// );
DB::table('inventory_product')
->insert([
'product_id' => $data['item_id'],
'inventory_id' => $data['warehouse_id'],
'stock' => $data['quantity'],
]);
}
// foreach ($items as $data) {
// DB::table($table)->insert([]);
// }
// DB::statement("
// SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
// ");
// });
DB::statement("
SELECT setval('inventory_product_id_seq', (SELECT MAX(id) from inventory_product))
");
});
}
}