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

Bagisto

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

Product update issue

Knowledge Base
3
10
655
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.
  • M
    Megalight last edited by 19 Oct 2020, 11:42

    Hi friends,
    I created custom product import logic for product insert via excel. But have some issues:
    I have created a custom Product, a custom ProductFlat, ProductInventory, and then have connected them. Product insert is working properly and I can see all changes in the admin section. But when i am trying to change something from admin to update the product it's not working. Here is the code:

     $pro = Product::firstOrCreate(
                        ['sku' => $row[0]],
                        ['attribute_family_id' => 1,
                        'type' => 'simple']
                    );
    
    
                    ProductInventory::updateOrCreate(
                        ['product_id' => $pro->id],
                        [
                            'qty' => $row[18],
                            'inventory_source_id' => 1,
                            'vendor_id' => 0
                        ]
                    );
    
                    $categories = explode("/", $row[1]);
    
                    $power_types = explode("/", $row[27]);
    
                    $color_ranges = explode("/", $row[29]);
                    $insulation_types = explode("/", $row[26]);
    
                    $lamp_type_id = AttributeOption::where('admin_name', $row[25])->with('translations')->get();
                    $voltage_type_id = AttributeOption::where('admin_name', $row[28])->with('translations')->get();
                    $brands_types=AttributeOption::where('admin_name', $row[5])->with('translations')->get();
    
    
                    /*Brands*/
                    $brands_types_translations=[];
                    foreach ($brands_types as $bran){
                        foreach ($bran->translations  as $trans) {
                            $brands_types_translations[$trans->locale]=$trans->label;
                        }
                    }
                    /*Brands*/
    
    
                    /*lamp_type*/
                    $lamp_type_translations=[];
                    foreach ($lamp_type_id as $and){
                        foreach ($and->translations  as $trans) {
                             $lamp_type_translations[$trans->locale]=$trans->label;
                        }
                    }
                    /*lamp_type*/
    
    
                    /* $voltage*/
                    $voltage_type_translations=[];
    
                    foreach ($voltage_type_id as $value){
                        foreach ($value->translations  as $trans) {
                            $voltage_type_translations[$trans->locale]=$trans->label;
                        }
                    }
                    /* $voltage*/
    
    
    
                    $crosses_products = array_map('trim', explode(',', $row[20]));
                    $related_products = array_map('trim', explode(',', $row[21]));
    
    
                    $imagesMul = array_map('trim', explode('/', $row[23]));
    
    
                    $products_array_cross[$key + 1][$pro->id] = $crosses_products;
                    $products_array_related[$key + 1][$pro->id] = $related_products;
    
    
                    $power = '';
    
                    $power_types_ids='';
                    $power_types_names=[];
                    foreach ($power_types as $type) {
    
                        $power_names = AttributeOption::where('admin_name', $type)->with('translations')->get();
    
                        foreach ($power_names[0]->translations as $tr){
                            if(! isset($power_types_names[$tr->locale])) {
                                $power_types_names[$tr->locale] = '';
                            }
                            $power_types_names[$tr->locale] .= $tr->label.',';
                        }
    
                        $power_types_ids .= AttributeOption::where('admin_name', $type)->pluck('id');
    
                    }
    
                    $power_types_ids = $this->triming($power_types_ids);
    
    
                    $color_rang_names = [];
                    $color_rang_id = '';
    
    
                    foreach ($color_ranges as $kay=>$color_range) {
                        $names= AttributeOption::where('admin_name', 'Լույս '.$color_range)->with('translations')->get();
    
                         foreach ($names[0]->translations as $tr){
                            if(! isset($color_rang_names[$tr->locale])) {
                                $color_rang_names[$tr->locale] = '';
                            }
                            $color_rang_names[$tr->locale] .= $tr->label.',';
                        }
                         $color_rang_id .= AttributeOption::where('admin_name', 'Լույս ' . $color_range)->pluck('id');
                    }
    
                    $color_rang_id = $this->triming($color_rang_id);
    
                    $insulation_type_id = '';
                    $insulation_type_names=[];
                    foreach ($insulation_types as $insulation_type) {
    
                        $insulation_type_name = AttributeOption::where('admin_name', $insulation_type)->with('translations')->get();
    
                        foreach ($insulation_type_name[0]->translations as $tr){
                            if(! isset($insulation_type_names[$tr->locale])) {
                                $insulation_type_names[$tr->locale] = '';
                            }
                            $insulation_type_names[$tr->locale] .= $tr->label.',';
                        }
                        $insulation_type_id .= AttributeOption::where('admin_name',  $insulation_type)->pluck('id');
                    }
    
    
                    $insulation_type_id = $this->triming($insulation_type_id);
    
    
                    foreach ($categories as $category) {
    
                        $cats = CategoryTranslation::where('name', $category)->where('locale', 'hy')->pluck('category_id');
                        $pro->categories()->attach($cats);
    
                    }
    
    
    
    
    
                    foreach (core()->getAllLocales() as $key => $locale) {
    
                        $pr = ProductFlat::create([
                            'product_id' => $pro->id,
                            'locale' => $locale->code,
                            'sku' => $row[0],
                            'name' => $row[2 + $key],
                            'url_key' => $row[11],
                            'new' => $row[16],
                            'featured' => $row[17],
                            'price' => $row[9],
                            'channel' => 'default',
                            'special_price' => $row[10],
    
                            "brands" => $brands_types[0]->id,
                            'Brands_label'=> $brands_types_translations[$locale->code],
    
                            'lamp_type' => $lamp_type_id[0]->id,
                            'lamp_type_label'=>$lamp_type_translations[$locale->code],
    
                            'cartridge' => $insulation_type_id,
                            'Cartridge_label'=>rtrim($insulation_type_names[$locale->code],','),
    
                            'voltage' => $voltage_type_id[0]->id,
                            'Voltage_label'=>$voltage_type_translations[$locale->code],
    
                            'color_range' => $color_rang_id,
                            'color_range_label'=>rtrim($color_rang_names[$locale->code],','),
    
    
                            'description' => $row[6],
                            'status' => $row[30],
                            'short_description' => $row[7],
                            'power' => $power_types_ids,
                            'Power_label' => rtrim($power_types_names[$locale->code],','),
    
    
    
                        ]);
    
                        $pr->created_at=$pro->created_at;
                        $pr->updated_at=$pro->updated_at;
    
                        $pr->save();
                    }
    
                $locale=app()->getLocale();
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 30,//lamp_type
                    'text_value' => $lamp_type_id[0]->id,
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 29,//brands
                    'text_value' => $brands_types[0]->id,
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 31,//cartridge
                    'text_value' => $insulation_type_id,
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 32,// voltage
                    'text_value' => $voltage_type_id[0]->id,//$voltage_type_translations[$locale->code],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 27,// color_range
                    'text_value' => $color_rang_id,
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 2,//name
                    'text_value' => $row[2 + $key],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 1,//sku
                    'text_value' => $row[0],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 28,//power
                    'text_value' => $power,
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 11,//price
                    'float_value' => $row[9],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 13,//special_price
                    'float_value' => $row[10],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 5,//new
                    'boolean_value' => $row[16],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 6,//featured
                    'boolean_value' => $row[17],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 8,//status
                    'boolean_value' => $row[30],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 3,//url_key
                    'text_value' => $row[11],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 10,//description
                    'text_value' => $row[6],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
                ProductAttributeValue::create([
                    'product_id' => $pro->id,
                    'attribute_id' => 9,//short_description
                    'text_value' => $row[7],
                    'locale' => $locale,
                    'channel' => 'default'
                ]);
    
                    $path = 'images/' . $row[15];
                    $in_product_path = 'app/public/images/' . $row[15];
    
    
                    if ($row[23]) {
    
                        foreach ($imagesMul as $im) {
    
                            $pathMu = 'images/' . $im;
    
                            if (Storage::exists($pathMu)) {
                                $ol = 'images/' . $im;
    
    
                                $url_d = 'product/' . $pro->id . '/' . $im;
                                $files = Storage::copy($ol, $url_d);
    
    
                                if ($files) {
                                    ProductImage::create([
                                        'product_id' => $pro->id,
                                        'path' => $url_d,
                                        'type' => null
    
                                    ]);
    
                                }
                            }
                        }
    
                    }
    
    
                    if (Storage::exists($path)) {
    
                        $old = 'images/' . $row[15];
                        $url_des = 'product/' . $pro->id . '/' . $row[15];
                        $files = Storage::copy($old, $url_des);
    
    
                        if ($files) {
                            ProductImage::create([
                                'product_id' => $pro->id,
                                'path' => $url_des,
                                'type' => null
    
                            ]);
    
    
                        }
    
    
                    }
    
    1 Reply Last reply Reply Quote 0
    • devansh-webkul
      devansh-webkul last edited by 19 Oct 2020, 13:56

      Hi @Megalight,

      Are you getting some error or something? can you share a screenshot so that I can understand?

      1 Reply Last reply Reply Quote 0
      • M
        Megalight last edited by 20 Oct 2020, 06:13

        No, can't see any errors, but wan a want to update products updating the only name, description

        1 Reply Last reply Reply Quote 0
        • devansh-webkul
          devansh-webkul last edited by 20 Oct 2020, 13:32

          @Megalight,

          I am not getting this, can you share with me some screenshots of the products listing on the admin panel and where you editing.

          Or can you give me the excel so that I can check on my instance?

          1 Reply Last reply Reply Quote 0
          • M
            Megalight last edited by Megalight 21 Oct 2020, 11:24 21 Oct 2020, 10:57

            It's my excel shite
            https://drive.google.com/file/d/1BEFU5id0WtQ-NNmn_425YNbGnBnat5AA/view?usp=sharing.

            and this is a video after import products from this shite.
            https://recordit.co/8vwwvp6uTq

            You can see in the video, success redirect after the update but nothing saved

            1 Reply Last reply Reply Quote 0
            • M
              Megalight last edited by 22 Oct 2020, 17:02

              Any news???

              1 Reply Last reply Reply Quote 0
              • devansh-webkul
                devansh-webkul last edited by 23 Oct 2020, 11:41

                Hi,

                According to your video, it looks like, there must be some linking problem. I am checking will let you know.

                1 Reply Last reply Reply Quote 0
                • devansh-webkul
                  devansh-webkul last edited by 23 Oct 2020, 11:51

                  Hi,

                  You can try this also, maybe this will help you.

                  Link: https://github.com/bagisto/bagisto-bulk-upload

                  1 Reply Last reply Reply Quote 0
                  • M
                    Megalight last edited by Megalight 23 Oct 2020, 14:29 23 Oct 2020, 14:27

                    What about custom attributes with multi-select vales ??
                    I have the power, voltage, lamp-type to multi-select type for each product, how to add these values to the excel file from bagisto-bulk-upload plugin???

                    1 Reply Last reply Reply Quote 0
                    • V
                      Vaishali Agarwal last edited by 28 Oct 2020, 06:35

                      @Megalight
                      multiselect value are not supported to import currently, you may raise the feature for this here https://github.com/bagisto/bagisto-bulk-upload/issues, so team will add this feature as per your requirement.

                      Thanks

                      1 Reply Last reply Reply Quote 0
                      5 out of 10
                      • First post
                        5/10
                        Last post