Update DatabaseSeeder to include additional seeders and comment out FavoritesSeeder
- Added ProductCategoryRelationshipsSeeder, ProductBarcodesSeeder, SectionsSeeder, ProductPropertiesSeeder, and ProductPropertyValuesSeeder to DatabaseSeeder. - Commented out FavoritesSeeder and SectionsSeeder for future adjustments.
This commit is contained in:
31
database/seeders/new/ProductBarcodesSeeder.php
Normal file
31
database/seeders/new/ProductBarcodesSeeder.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\New;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use JsonMachine\Items;
|
||||
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||
|
||||
class ProductBarcodesSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$table = 'products';
|
||||
|
||||
$items = Items::fromFile(
|
||||
database_path('data/item_barcodes.json'),
|
||||
['decoder' => new ExtJsonDecoder(true)]
|
||||
);
|
||||
|
||||
foreach ($items as $data) {
|
||||
// item_id is product id, I need to find product and update price_amount to $data['value'] and cost_amount to $data['cost_value']
|
||||
DB::table($table)->where('id', $data['item_id'])->update([
|
||||
'barcode' => $data['barcode'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user