- Reorganized imports in DatabaseSeeder for better structure. - Enabled ProductCategoryRelationshipsSeeder and ProductBarcodesSeeder in DatabaseSeeder. - Updated ProductPropertyValuesSeeder to enhance property value handling and added a new method for filling product property values. - Removed unused imports from ProductBarcodesSeeder, ProductCategoryRelationshipsSeeder, and ProductPropertiesSeeder. - Ensured consistent formatting by adding missing newlines at the end of files.
33 lines
802 B
PHP
33 lines
802 B
PHP
<?php
|
|
|
|
namespace Database\Seeders\New;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use JsonMachine\Items;
|
|
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
|
|
|
class ProductPropertiesSeeder extends Seeder
|
|
{
|
|
public function run()
|
|
{
|
|
DB::transaction(function () {
|
|
$table = 'product_attributes';
|
|
|
|
DB::table($table)->truncate();
|
|
|
|
$items = Items::fromFile(
|
|
database_path('data/item_properties.json'),
|
|
['decoder' => new ExtJsonDecoder(true)]
|
|
);
|
|
|
|
foreach ($items as $data) {
|
|
DB::table($table)->insert([
|
|
'product_id' => $data['item_id'],
|
|
'attribute_id' => $data['property_id'],
|
|
]);
|
|
}
|
|
});
|
|
}
|
|
}
|