Bagisto Forum

    Bagisto

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

    Using ProductRepository to seed products

    General Discussion
    2
    4
    642
    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.
    • G
      gciliberti last edited by

      Hello,
      I'm trying to build a custom seeder that seeds configurable products, however I can't get it to work when I'm adding the "super_attributes" array inside the $data needed by the repository.

      $attributes = [
                  'type' => 'configurable',
                  'attribute_family_id' => '3',
                  'sku' => $card->CA_COMPTEUR,
                  'super_attributes' => array(
                      'color' => array(
                          0 => 1,
                          1 => 2,
                          2 => 3,
                      ),
                      'print_support' => array(
                          0 => 11,
                          1 => 12,
                      ),
                      'print_size' => array(
                          0 => 13,
                          1 => 14,
                          2 => 15,
                          3 => 16,
                      )
                  ),
                  'family' => '3'
              ];
      
      
              $product = app(ProductRepository::class)->create($attributes);
      

      I'm getting an array to string conversion error. I don't understand because when I'm duping the data sent from the backoffice this is the exact same array. What am I doing wrong ?
      When I'm deleting the "super_attributes" array from the data this work perfectly but then I can't have the variants.

      Have a nice day !

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        Hi @gciliberti,

        Can you share the full error or screenshot because the array looks fine to me?

        1 Reply Last reply Reply Quote 0
        • G
          gciliberti last edited by gciliberti

          @gciliberti said in Using ProductRepository to seed products:
          d71ef68f-8c25-40ee-814e-47baa478e1d5-image.png

          I get this error when i come to create() function of the Configurable type, to me the array look fine, I'm sending exactly the same thing as the backoffice. Maybe calling the repository from a seeder is the issue ?

                  $product = $this->productRepository->getModel()->create($data);
          
          

          ^
          The bug is produced by this line in the configurable type.

          I'm stuck on this issue for several hours and I can't find a solution, I'm desperate.

          Can i get around this by using the product factory ? Will it create the variants for me like the repository can do ?

          Thank you a lot !

          1 Reply Last reply Reply Quote 0
          • G
            gciliberti last edited by

            I found the solution !
            Laravel allow us to bypass $fillable property from the model when using a seeder, in my case I didn't want it.
            I simply had to use

            Model::reguard();
            

            and it worked !

            1 Reply Last reply Reply Quote 0
            • First post
              Last post