Files
postshop-backend/database/seeders/new/ProductBarcodesSeeder.php
Mekan1206 c48ad83548 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.
2026-02-09 03:29:21 +05:00

31 lines
894 B
PHP

<?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'],
]);
}
});
}
}