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:
@@ -7,10 +7,15 @@ use Database\Seeders\New\BrandsSeeder;
|
||||
use Database\Seeders\New\CategoriesTableSeeder;
|
||||
use Database\Seeders\New\CustomersTableSeeder;
|
||||
use Database\Seeders\New\FavoritesSeeder;
|
||||
use Database\Seeders\New\ProductCategoryRelationshipsSeeder;
|
||||
use Database\Seeders\New\ProductBarcodesSeeder;
|
||||
use Database\Seeders\New\ProductPricesSeeder;
|
||||
use Database\Seeders\New\ProductsTableSeeder;
|
||||
use Database\Seeders\New\PropertiesTableSeeder;
|
||||
use Database\Seeders\New\SectionsSeeder;
|
||||
use Database\Seeders\New\SellersTableSeeder;
|
||||
use Database\Seeders\New\ProductPropertiesSeeder;
|
||||
use Database\Seeders\New\ProductPropertyValuesSeeder;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -33,7 +38,12 @@ class DatabaseSeeder extends Seeder
|
||||
// CategoriesTableSeeder::class,
|
||||
// AddressSeeder::class,
|
||||
// PropertiesTableSeeder::class,
|
||||
FavoritesSeeder::class,
|
||||
// FavoritesSeeder::class,
|
||||
// SectionsSeeder::class,
|
||||
// ProductCategoryRelationshipsSeeder::class,
|
||||
// ProductBarcodesSeeder::class,
|
||||
// ProductPropertiesSeeder::class,
|
||||
ProductPropertyValuesSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,4 @@ class FavoritesSeeder extends Seeder
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
36
database/seeders/new/ProductCategoryRelationshipsSeeder.php
Normal file
36
database/seeders/new/ProductCategoryRelationshipsSeeder.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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 ProductCategoryRelationshipsSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$table = 'category_product';
|
||||
|
||||
DB::table($table)->truncate();
|
||||
|
||||
$items = Items::fromFile(
|
||||
database_path('data/categorizables.json'),
|
||||
['decoder' => new ExtJsonDecoder(true)]
|
||||
);
|
||||
|
||||
foreach ($items as $data) {
|
||||
if ($data['categorizable_type'] == 'Domain\\Item\\Models\\Item') {
|
||||
DB::table($table)->insert([
|
||||
'product_id' => $data['categorizable_id'],
|
||||
'category_id' => $data['category_id'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
33
database/seeders/new/ProductPropertiesSeeder.php
Normal file
33
database/seeders/new/ProductPropertiesSeeder.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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 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'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
33
database/seeders/new/ProductPropertyValuesSeeder.php
Normal file
33
database/seeders/new/ProductPropertyValuesSeeder.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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 ProductPropertyValuesSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$table = 'attribute_value_product_attribute';
|
||||
|
||||
DB::table($table)->truncate();
|
||||
|
||||
$items = Items::fromFile(
|
||||
database_path('data/item_property_values.json'),
|
||||
['decoder' => new ExtJsonDecoder(true)]
|
||||
);
|
||||
|
||||
foreach ($items as $data) {
|
||||
DB::table($table)->insert([
|
||||
'product_id' => $data['item_id'],
|
||||
'attribute_value_id' => $data['property_value_id'],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace Database\Seeders\New;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PropertiesTableSeeder extends Seeder
|
||||
{
|
||||
@@ -32,4 +31,4 @@ class PropertiesTableSeeder extends Seeder
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
database/seeders/new/SectionsSeeder.php
Normal file
37
database/seeders/new/SectionsSeeder.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\New;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SectionsSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
DB::transaction(function () {
|
||||
$datas = json_decode(File::get('database/data/sections.json'));
|
||||
$table = 'collections';
|
||||
|
||||
DB::table($table)->truncate();
|
||||
|
||||
foreach ($datas as $data) {
|
||||
DB::table($table)->insert([
|
||||
'id' => $data->id,
|
||||
'name' => str_replace('"tm"', '"tk"', $data->title),
|
||||
'slug' => Str::slug($data->title).'_'.$data->id,
|
||||
'is_visible' => ! $data->is_blocked,
|
||||
'sort_order' => $data->priority,
|
||||
'created_at' => $data->created_at,
|
||||
'updated_at' => $data->updated_at,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::statement("
|
||||
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user