🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 DemoDataSeeder.php

📁 Path: /home/skhata/new.chandrapharma.com/database/seeders/DemoDataSeeder.php
📊 Size: 8 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php

namespace Database\Seeders;

use App\Modules\Catalog\Models\Category;
use App\Modules\Catalog\Models\Product;
use App\Modules\Vendor\Models\Vendor;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class DemoDataSeeder extends Seeder
{
    public function run(): void
    {
        $vendor = Vendor::where('email', 'vendor@stpecommerce.com')->first();

        if (! $vendor) {
            $this->command->error('Run TestUsersSeeder first: php artisan db:seed --class=TestUsersSeeder');
            return;
        }

        $categories = Category::whereNull('parent_id')->pluck('id', 'slug');

        $products = [
            [
                'name'             => 'Wireless Bluetooth Headphones',
                'category_slug'    => 'electronics',
                'price'            => 2499.00,
                'compare_price'    => 3499.00,
                'stock_quantity'   => 50,
                'short_description'=> 'Premium sound quality with 30-hour battery life and noise cancellation.',
                'description'      => 'Experience crystal-clear audio with these premium wireless headphones. Features active noise cancellation, 30-hour battery, and foldable design for easy travel.',
                'sku'              => 'ELEC-WBH-001',
                'weight'           => 0.25,
            ],
            [
                'name'             => 'Smart LED Desk Lamp',
                'category_slug'    => 'electronics',
                'price'            => 1299.00,
                'compare_price'    => 1799.00,
                'stock_quantity'   => 30,
                'short_description'=> 'Touch-controlled LED lamp with USB charging port and adjustable brightness.',
                'description'      => 'Modern desk lamp with 5 brightness levels, 3 color temperatures, built-in USB charging port, and memory function.',
                'sku'              => 'ELEC-SDL-002',
                'weight'           => 0.5,
            ],
            [
                'name'             => 'Men\'s Slim Fit T-Shirt',
                'category_slug'    => 'fashion',
                'price'            => 599.00,
                'compare_price'    => 899.00,
                'stock_quantity'   => 100,
                'short_description'=> '100% cotton premium slim-fit t-shirt. Available in multiple colors.',
                'description'      => 'Crafted from 100% premium combed cotton. Pre-shrunk fabric, reinforced stitching, and a flattering slim fit for everyday wear.',
                'sku'              => 'FASH-MST-001',
                'weight'           => 0.2,
            ],
            [
                'name'             => 'Women\'s Casual Kurti',
                'category_slug'    => 'fashion',
                'price'            => 799.00,
                'compare_price'    => 1199.00,
                'stock_quantity'   => 80,
                'short_description'=> 'Elegant cotton kurti with traditional embroidery. Perfect for everyday wear.',
                'description'      => 'Beautiful hand-embroidered cotton kurti with a relaxed fit. Machine washable. Available in sizes S to XXL.',
                'sku'              => 'FASH-WCK-002',
                'weight'           => 0.3,
            ],
            [
                'name'             => 'Non-Stick Cookware Set (5 Piece)',
                'category_slug'    => 'home-living',
                'price'            => 3499.00,
                'compare_price'    => 4999.00,
                'stock_quantity'   => 25,
                'short_description'=> 'Premium granite-coated non-stick cookware set. Induction compatible.',
                'description'      => 'Complete 5-piece cookware set including 20cm/24cm fry pans, 18cm saucepan, 20cm casserole, and a glass lid. PFOA-free granite coating.',
                'sku'              => 'HOME-NCS-001',
                'weight'           => 2.5,
            ],
            [
                'name'             => 'Bamboo Cutting Board Set',
                'category_slug'    => 'home-living',
                'price'            => 899.00,
                'compare_price'    => 1299.00,
                'stock_quantity'   => 60,
                'short_description'=> 'Eco-friendly bamboo cutting boards. Set of 3 different sizes.',
                'description'      => 'Sustainable bamboo cutting boards with juice grooves and non-slip feet. Naturally antibacterial. Set includes small (20x15cm), medium (30x20cm), and large (40x25cm).',
                'sku'              => 'HOME-BCB-002',
                'weight'           => 1.2,
            ],
            [
                'name'             => 'Atomic Habits — James Clear',
                'category_slug'    => 'books',
                'price'            => 499.00,
                'compare_price'    => 699.00,
                'stock_quantity'   => 200,
                'short_description'=> 'The #1 bestseller on building good habits and breaking bad ones.',
                'description'      => 'Atomic Habits by James Clear is a comprehensive guide to changing your habits and getting 1% better every day. Includes proven frameworks for improvement.',
                'sku'              => 'BOOK-AH-001',
                'weight'           => 0.35,
            ],
            [
                'name'             => 'Yoga Mat — Anti-Slip 6mm',
                'category_slug'    => 'sports',
                'price'            => 1499.00,
                'compare_price'    => 1999.00,
                'stock_quantity'   => 45,
                'short_description'=> 'Professional 6mm yoga mat with alignment lines. Eco-friendly TPE material.',
                'description'      => 'High-density TPE yoga mat with double-sided non-slip surface, body alignment lines, and carrying strap. Lightweight at 900g. Dimensions: 183cm x 61cm.',
                'sku'              => 'SPRT-YM-001',
                'weight'           => 0.9,
            ],
        ];

        $count = 0;
        // Disable TNTSearch indexing during seed — avoids mb_strtolower(array) error
        // on translatable fields. Run `php artisan scout:import` after seeding if needed.
        Product::withoutSyncingToSearch(function () use ($products, $categories, $vendor, &$count) {
        foreach ($products as $data) {
            $categoryId = $categories[$data['category_slug']] ?? null;

            // Translatable fields must be arrays keyed by locale
            $product = Product::firstOrCreate(
                ['sku' => $data['sku']],
                [
                    'vendor_id'         => $vendor->id,
                    'category_id'       => $categoryId,
                    'name'              => ['en' => $data['name']],
                    'slug'              => Str::slug($data['name']) . '-' . Str::random(4),
                    'short_description' => ['en' => $data['short_description']],
                    'description'       => ['en' => $data['description']],
                    'price'             => $data['price'],
                    'compare_price'     => $data['compare_price'],
                    'cost_price'        => $data['price'] * 0.6,
                    'currency'          => 'NPR',
                    'stock_quantity'    => $data['stock_quantity'],
                    'track_inventory'   => true,
                    'weight'            => $data['weight'],
                    'status'            => 'active',
                    'is_featured'       => $count < 4,
                    'published_at'      => now(),
                    'product_type'      => 'simple',
                    'requires_shipping' => true,
                ]
            );

            // Storefront category browsing queries the product_category pivot.
            if ($categoryId) {
                $product->categories()->syncWithoutDetaching([$categoryId]);
            }

            $count++;
        }
        }); // end withoutSyncingToSearch

        $this->command->info("✅ {$count} demo products created for Test Store.");
        $this->command->info('   Visit /products to see them on the storefront.');
    }
}
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨