Recent Topics

how can I fill the DB with dummy data?



  • I want to make multiple changes, but I don't know how to see it in working I just to want to create few cats and 1000-3000 products
    with DB seeding and faker


  • Banned

    Hi,

    1. To do for products you have to take a deep dive in productRepository class present in product package. It already have create and update methods inside it. To create a product you would be needed to select three things:
      a. SKU
      b. Attribute Family
      c. Select variants if you are creating congurable product.

    Both the methods create and update in productRepository should work simultaneously if you want to create a product at one go.

    To create products with faker you will just need to inject productRepository class and then create products with all necessary values used as it.

    1. For categories, you can refer this blog: https://bagisto.com/en/create-new-category-and-root-category-in-bagisto/

    Regards:
    Prashant.



  • 918e967e-6233-4afd-932f-87dbb928c427-image.png

    I created Categories in a seeder this way



  • And this is the Product seeder

    public function run()
        {
            $faker = \Faker\Factory::create();
    
            $product_repo = new \Webkul\Product\Repositories\ProductRepository(
                new AttributeRepository(new AttributeOptionRepository(app()), app()),
                new AttributeOptionRepository(app()),
                new ProductAttributeValueRepository(new AttributeRepository(new AttributeOptionRepository(app()), app()), app()),
                new ProductInventoryRepository(app()),
                new ProductImageRepository(app()),
                app()
            );
    
            $product_inv_repo = new ProductInventoryRepository(app());
            
            $categories = \App\Category::where('id', '!=', 1)->get()->pluck('id');
    
            for ($i = 0; $i < 2500; $i++){
                $product = $product_repo->create([
                    'type' => 'simple',
                    'attribute_family_id' => 1,
                    'sku' => $faker->slug(2)
                ]);
    
                $product_repo->updateVariant([
                    'sku' => $faker->uuid,
                    'name' => $faker->words(3, true),
                    'channel' => 'default',
                    'status' => 1,
                    'price' => rand(200, 90000),
                    'weight' => rand(200, 90000),
                    'locale' => 'en',
                    'url_key' => $faker->slug,
                    'new' => rand(0, 1),
                    'featured' => rand(0, 1),
                    'visible_individually' => 1,
                    'color' => rand(1, 3),
                    'size' => 5,
                    'short_description' => $faker->words(5, true),
                    'description' => $faker->words(45, true),
                    'meta_title' => $faker->words(2, true),
                    'meta_keywords' => implode(',', $faker->words(45)),
                    'meta_description' => $faker->words(45, true),
    
                ], $product->id);
    
                $product_repo->update(
                    [
                        'categories' => $categories [ rand(0, count($categories) - 1) ],
                    ],
                    $product->id, false, true );
    
    
                $product_inv_repo->saveInventories([
                    'inventories' => [
                            1 => rand(10, 1000)
                        ],
                ], $product);
    
                $product_repo->getProductImageRepository()->uploadImages([
                    'images' => [
                            'image_1' => $faker->image(),
                            'image_2' => $faker->image(),
                            'image_3' => $faker->image(),
                        ],
                ], $product, true);
    
    
    
                 ProductFlat::whereProductId($product->id)
                ->update([
                    'url_key' => $faker->slug,
                    'new' => rand(0, 1),
                    'featured' => rand(0, 1),
                    'visible_individually' => 1,
                    'color' => rand(1, 3),
                    'size' => 5,
                    'channel' => 'default',
                    'locale' => 'en',
                    'short_description' => $faker->words(5, true),
                    'description' => $faker->words(45, true),
                    'meta_title' => $faker->words(2, true),
                    'meta_keywords' => implode(',', $faker->words(45)),
                    'meta_description' => $faker->words(45, true),
                ]);
                 
                echo $i . PHP_EOL;
            }
    
        }
    


  • College Term Paper Services
    Custom Term Paper Service industry has grown steadily in provision of Legitimate Term Paper Services and high quality Custom Term Paper Writing Services which is preferred by scholars worldwide.
    https://researchpapers247.com/custom-term-paper-writing-service/



  • @alkhachatryan said in how can I fill the DB with dummy data?:

    $product_repo = new \Webkul\Product\Repositories\ProductRepository(
    new AttributeRepository(new AttributeOptionRepository(app()), app()),
    new AttributeOptionRepository(app()),
    new ProductAttributeValueRepository(new AttributeRepository(new AttributeOptionRepository(app()), app()), app()),
    new ProductInventoryRepository(app()),
    new ProductImageRepository(app()),
    app()
    );

    error

    Argument 2 passed to Webkul\Product\Repositories\ProductRepository::__construct() must be an instance of Illuminate\Container\Container, instan
    ce of Webkul\Attribute\Repositories\AttributeOptionRepository given, called in D:\laragon\www\ecom\database\seeds\ProductSeeder.php on line 30



  • Hi @nikul,

    Please check your arguments which you have passed in the constructor.


Log in to reply