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:
@@ -45,7 +45,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
// ProductBarcodesSeeder::class,
|
// ProductBarcodesSeeder::class,
|
||||||
// ProductPropertiesSeeder::class,
|
// ProductPropertiesSeeder::class,
|
||||||
// ProductPropertyValuesSeeder::class,
|
// ProductPropertyValuesSeeder::class,
|
||||||
ProductStocksSeeder::class,
|
// ProductStocksSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,24 +11,29 @@ class ProductStocksSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
//
|
DB::transaction(function () {
|
||||||
// DB::transaction(function () {
|
$items = Items::fromFile(
|
||||||
// $table = 'products';
|
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(
|
DB::table('inventory_product')
|
||||||
// database_path('data/items.json'),
|
->insert([
|
||||||
// ['decoder' => new ExtJsonDecoder(true)]
|
'product_id' => $data['item_id'],
|
||||||
// );
|
'inventory_id' => $data['warehouse_id'],
|
||||||
|
'stock' => $data['quantity'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
// foreach ($items as $data) {
|
DB::statement("
|
||||||
// DB::table($table)->insert([]);
|
SELECT setval('inventory_product_id_seq', (SELECT MAX(id) from inventory_product))
|
||||||
// }
|
");
|
||||||
|
});
|
||||||
// DB::statement("
|
|
||||||
// SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
|
||||||
// ");
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user