• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

how can I fill the DB with dummy data?

General Discussion
7
11
1.9k
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S
    sanjana singh last edited by 6 Jul 2019, 09:49

    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

    1 Reply Last reply Reply Quote 0
    • B
      bagisto-mogul Banned last edited by admin 6 Jul 2019, 10:22 6 Jul 2019, 10:07

      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.

      1 Reply Last reply Reply Quote 0
      • A
        alkhachatryan last edited by 6 Jul 2019, 17:10

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

        I created Categories in a seeder this way

        1 Reply Last reply Reply Quote 0
        • A
          alkhachatryan last edited by 7 Jul 2019, 19:23

          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;
                  }
          
              }
          
          N 1 Reply Last reply 5 Oct 2020, 05:11 Reply Quote 0
          • about a year later
          • N
            nikul @alkhachatryan last edited by 5 Oct 2020, 05:11

            @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

            Y 1 Reply Last reply 30 Jun 2021, 17:00 Reply Quote 0
            • devansh-webkul
              devansh-webkul last edited by 7 Oct 2020, 06:00

              Hi @nikul,

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

              Y 1 Reply Last reply 30 Jun 2021, 17:01 Reply Quote 0
              • 9 months later
              • Y
                yiara @nikul last edited by 30 Jun 2021, 17:00

                @nikul did you find a solution to this?

                1 Reply Last reply Reply Quote 0
                • Y
                  yiara @devansh-webkul last edited by 30 Jun 2021, 17:01

                  @devansh-webkul got the same issue can and I checked, everything is passed successfully any idea how to fix it?

                  1 Reply Last reply Reply Quote 0
                  • devansh-webkul
                    devansh-webkul last edited by 1 Jul 2021, 05:00

                    Hi @yiara,

                    I am not getting this, what he is trying to do. I just answered the error which he caused.

                    If you want help then first elaborate on what you are trying to do and the implementation steps.

                    So that I can further check.

                    1 Reply Last reply Reply Quote 0
                    • Y
                      yiara last edited by 7 Jul 2021, 03:15

                      I tried the above steps to import dummy data in my database, I got the same issue as this

                      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
                      

                      regardless that I checked the arguments I passed in the instructor and everything is fine

                      1 Reply Last reply Reply Quote 0
                      • devansh-webkul
                        devansh-webkul last edited by 7 Jul 2021, 03:59

                        So your issue is resolved now.

                        1 Reply Last reply Reply Quote 0
                        4 out of 11
                        • First post
                          4/11
                          Last post