Update DatabaseSeeder to include MediaSeeder and enhance 404 error page localization
- Added MediaSeeder to DatabaseSeeder for improved data seeding. - Updated 404 error page to use localized string for "Page not found" and added links for navigation. - Added new translation for "Page not found" in tk.json.
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Ecommerce\Product\Order\Concerns\HasPayments;
|
|||||||
use App\Models\Ecommerce\Product\Order\Concerns\HasShipping;
|
use App\Models\Ecommerce\Product\Order\Concerns\HasShipping;
|
||||||
use App\Models\Ecommerce\Product\Order\Concerns\HasStatus;
|
use App\Models\Ecommerce\Product\Order\Concerns\HasStatus;
|
||||||
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||||
|
use App\Models\Concerns\HasSchemalessAttributes;
|
||||||
use App\Models\System\Settings\Location\Province;
|
use App\Models\System\Settings\Location\Province;
|
||||||
use App\Models\System\Settings\Payments\PaymentType;
|
use App\Models\System\Settings\Payments\PaymentType;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -22,6 +23,7 @@ class Order extends Model
|
|||||||
use HasShipping;
|
use HasShipping;
|
||||||
use HasStatus;
|
use HasStatus;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
use HasSchemalessAttributes;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
|
|||||||
@@ -126,15 +126,11 @@ class CategoryRepository
|
|||||||
*/
|
*/
|
||||||
public static function namesWithTaxes(): mixed
|
public static function namesWithTaxes(): mixed
|
||||||
{
|
{
|
||||||
return CacheRepository::make(
|
return static::maskParentName(
|
||||||
time: 5,
|
Category::tree()
|
||||||
name: 'cs-nova-models-categories',
|
->where('is_visible', true)
|
||||||
value: fn () => static::maskParentName(
|
->get(['id', 'slug', 'name', 'tax_percentage', 'parent_id', 'is_visible'])
|
||||||
Category::tree()
|
->toTree()
|
||||||
->where('is_visible', true)
|
|
||||||
->get(['id', 'slug', 'name', 'tax_percentage', 'parent_id', 'is_visible'])
|
|
||||||
->toTree()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ class CreateOrderService
|
|||||||
{
|
{
|
||||||
return DB::transaction(function () use ($user, $data) {
|
return DB::transaction(function () use ($user, $data) {
|
||||||
// 1. Create the order
|
// 1. Create the order
|
||||||
info(['service' => $data]);
|
|
||||||
$order = Order::create($data);
|
$order = Order::create($data);
|
||||||
|
|
||||||
// 2. Process Cart Items
|
// 2. Process Cart Items
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('orders', function (Blueprint $table) {
|
||||||
|
$table->jsonb('options')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('orders', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('options');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -8,6 +8,8 @@ use Database\Seeders\New\CategoriesTableSeeder;
|
|||||||
use Database\Seeders\New\CustomersTableSeeder;
|
use Database\Seeders\New\CustomersTableSeeder;
|
||||||
use Database\Seeders\New\FavoritesSeeder;
|
use Database\Seeders\New\FavoritesSeeder;
|
||||||
use Database\Seeders\New\MediaSeeder;
|
use Database\Seeders\New\MediaSeeder;
|
||||||
|
use Database\Seeders\New\OrderAddressSeeder;
|
||||||
|
use Database\Seeders\New\OrderSeeder;
|
||||||
use Database\Seeders\New\ProductBarcodesSeeder;
|
use Database\Seeders\New\ProductBarcodesSeeder;
|
||||||
use Database\Seeders\New\ProductCategoryRelationshipsSeeder;
|
use Database\Seeders\New\ProductCategoryRelationshipsSeeder;
|
||||||
use Database\Seeders\New\ProductPricesSeeder;
|
use Database\Seeders\New\ProductPricesSeeder;
|
||||||
@@ -31,6 +33,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$this->call([
|
$this->call([
|
||||||
|
// PaymentTypeSeeder::class,
|
||||||
// UsersTableSeeder::class,
|
// UsersTableSeeder::class,
|
||||||
// BrandsSeeder::class,
|
// BrandsSeeder::class,
|
||||||
// CustomersTableSeeder::class,
|
// CustomersTableSeeder::class,
|
||||||
@@ -47,7 +50,9 @@ class DatabaseSeeder extends Seeder
|
|||||||
// ProductPropertiesSeeder::class,
|
// ProductPropertiesSeeder::class,
|
||||||
// ProductPropertyValuesSeeder::class,
|
// ProductPropertyValuesSeeder::class,
|
||||||
// ProductStocksSeeder::class,
|
// ProductStocksSeeder::class,
|
||||||
MediaSeeder::class,
|
// MediaSeeder::class,
|
||||||
|
// OrderSeeder::class,
|
||||||
|
OrderAddressSeeder::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
database/seeders/PaymentTypeSeeder.php
Normal file
43
database/seeders/PaymentTypeSeeder.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\System\Settings\Payments\PaymentType;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
|
||||||
|
class PaymentTypeSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
collect([
|
||||||
|
[
|
||||||
|
'id' => 1,
|
||||||
|
'code' => 'cash',
|
||||||
|
'name' => ['en' => 'Cash', 'tk' => 'Nagt', 'ru' => 'Näliçni'],
|
||||||
|
'tax' => 0,
|
||||||
|
'is_enabled' => true,
|
||||||
|
'options' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 2,
|
||||||
|
'code' => 'atm',
|
||||||
|
'name' => ['en' => 'ATM', 'tk' => 'Terminal', 'ru' => 'ATM'],
|
||||||
|
'tax' => 0,
|
||||||
|
'is_enabled' => true,
|
||||||
|
'options' => null,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 3,
|
||||||
|
'code' => 'online_halkbank',
|
||||||
|
'name' => ['en' => 'Online (halkbank)', 'tk' => 'Onlaýn (halkbank)', 'ru' => 'Onlaýn (halkbank)'],
|
||||||
|
'tax' => 0,
|
||||||
|
'is_enabled' => true,
|
||||||
|
'options' => null,
|
||||||
|
],
|
||||||
|
])->each(fn($data) => PaymentType::create($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
31
database/seeders/new/OrderAddressSeeder.php
Normal file
31
database/seeders/new/OrderAddressSeeder.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders\New;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use JsonMachine\Items;
|
||||||
|
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||||
|
|
||||||
|
class OrderAddressSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
DB::transaction(function () {
|
||||||
|
$items = Items::fromFile(
|
||||||
|
database_path('data/order_address.json'),
|
||||||
|
['decoder' => new ExtJsonDecoder(true)]
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($items as $data) {
|
||||||
|
DB::table('orders')->where('id', $data['order_id'])->update([
|
||||||
|
'customer_address' => $data['address'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
120
database/seeders/new/OrderSeeder.php
Normal file
120
database/seeders/new/OrderSeeder.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders\New;
|
||||||
|
|
||||||
|
use App\Models\Ecommerce\Product\Order\Payment\OrderPayment;
|
||||||
|
use App\Models\Ecommerce\Product\Order\Shipping\OrderShipping;
|
||||||
|
use App\Models\Ecommerce\Product\Order\Status\OrderStatus;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use JsonMachine\Items;
|
||||||
|
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||||
|
|
||||||
|
class OrderSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$this->fillOrders();
|
||||||
|
$this->fillOrderItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillOrderItems()
|
||||||
|
{
|
||||||
|
DB::transaction(function () {
|
||||||
|
$table = 'order_items';
|
||||||
|
|
||||||
|
DB::table($table)->truncate();
|
||||||
|
|
||||||
|
$items = Items::fromFile(
|
||||||
|
database_path('data/order_items.json'),
|
||||||
|
['decoder' => new ExtJsonDecoder(true)]
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($items as $data) {
|
||||||
|
$channel_id = DB::table('channel_product')->where('product_id', $data['item_id'])->first()->channel_id ?? tmpostChannel()->id;
|
||||||
|
|
||||||
|
DB::table($table)->insert([
|
||||||
|
'id' => $data['id'],
|
||||||
|
'order_id' => $data['order_id'],
|
||||||
|
'product_id' => $data['item_id'],
|
||||||
|
'quantity' => $data['quantity'],
|
||||||
|
'unit_price_amount' => $data['price'],
|
||||||
|
|
||||||
|
'channel_id' => $channel_id,
|
||||||
|
|
||||||
|
'created_at' => $data['created_at'],
|
||||||
|
'updated_at' => $data['updated_at'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement("
|
||||||
|
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||||
|
");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function fillOrders()
|
||||||
|
{
|
||||||
|
DB::transaction(function () {
|
||||||
|
$table = 'orders';
|
||||||
|
|
||||||
|
DB::table($table)->truncate();
|
||||||
|
|
||||||
|
$items = Items::fromFile(
|
||||||
|
database_path('data/orders.json'),
|
||||||
|
['decoder' => new ExtJsonDecoder(true)]
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($items as $data) {
|
||||||
|
DB::table($table)->insert([
|
||||||
|
'id' => $data['id'],
|
||||||
|
'number' => Str::random(30),
|
||||||
|
'user_id' => $data['customer_id'],
|
||||||
|
'options' => sprintf('{"seller_id":"%s","warehouse_id":"%s"}', $data['seller_id'], $data['warehouse_id']),
|
||||||
|
'status' => $this->formatStatus($data['status']),
|
||||||
|
'shipping_method' => $this->formatShippingMethod($data['delivery_type']),
|
||||||
|
'payment_type_id' => $this->formatPaymentType($data['payment_type']),
|
||||||
|
'notes' => $data['note'],
|
||||||
|
'created_at' => $data['created_at'],
|
||||||
|
'updated_at' => $data['updated_at'],
|
||||||
|
'deleted_at' => $data['deleted_at'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::statement("
|
||||||
|
SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||||
|
");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatStatus(string $status): string
|
||||||
|
{
|
||||||
|
return match ($status) {
|
||||||
|
'DRAFT' => OrderStatus::PENDING,
|
||||||
|
'COMPLETED' => OrderStatus::COMPLETED,
|
||||||
|
'DELIVERED' => OrderStatus::COMPLETED,
|
||||||
|
'CANCELLED' => OrderStatus::CANCELLED,
|
||||||
|
default => OrderStatus::default(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatShippingMethod($shippingMethod): string
|
||||||
|
{
|
||||||
|
return match ($shippingMethod) {
|
||||||
|
'PICK_UP' => OrderShipping::SELF_PICKUP,
|
||||||
|
'EXPRESS_DELIVERY' => OrderShipping::EXPRESS,
|
||||||
|
'SELECTED_DELIVERY' => OrderShipping::STANDART,
|
||||||
|
default => OrderShipping::default(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatPaymentType($paymentType): int
|
||||||
|
{
|
||||||
|
return match ($paymentType) {
|
||||||
|
'CASH' => 1,
|
||||||
|
'CARD' => 2,
|
||||||
|
default => 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user