app/Http/Controllers/ProviderProductController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
          if($request->isMethod('PUT')){
       			if($request->price_promo > $request->price){
        		$request->price_promo = null;
        		}
              $product = Product::find($id);
              if($product->company_id != Auth::user()->company_id){return redirect('/welcome')->with('danger', 'В доступе отказано!');}
              $your_self_parametrs_array = $request->your_self_parametr['parametr'];
              $default_parametrs_array = $request->default_parametr['parametr'];
              $code = $product->company_id.'-'.$request->code;
              $st_sp = self::createProductCheckSpetial($product->company_id);
              $array_for_deleting_from_s3_drive = json_decode($product->gallery);
              self::deleteImagesFromS3Drive($array_for_deleting_from_s3_drive);
              $gallery = $request->gallery;
              $galleryArray = explode(",", $gallery);
              $json_array_images = self::uploadImagesToS3Drive($galleryArray);
              ProductsItem::where('product_id', $product->id)->delete();
              $subcategory = Subcategory::find($request->subcategory);
              $product->category_id = $subcategory->category_id;
              $product->subcategory_id = $request->subcategory;
              $product->name = $request->name;
              $product->desc = $request->desc;
              $product->code = $code;
              $product->brand = $request->brand;
              $product->price = $request->price;
              $product->old_price = (isset($request->old_price)?$request->old_price:null);
			  $product->price_promo = (isset($request->price_promo)?$request->price_promo:null);
              $product->gallery = $json_array_images;
              $product->video_url = (isset($request->video)?$request->video:null);
              $product->status_spacial = $st_sp;
              $product->status_moderation = '0';
              $product->status_remod = '1';
              $product->save();
              if(($default_parametrs_array == null) && ($your_self_parametrs_array == null)){
              }elseif($your_self_parametrs_array == null){
                  self::storeProductItems('default', $product->id, $default_parametrs_array);
              }elseif($default_parametrs_array == null){
                  self::storeProductItems('your_self', $product->id, $your_self_parametrs_array);
              }elseif(($default_parametrs_array != null) && ($your_self_parametrs_array != null)){
                  self::storeProductItems('default', $product->id, $default_parametrs_array);
                  self::storeProductItems('your_self', $product->id, $your_self_parametrs_array);
              }
              return redirect('company/products')->with('success', 'Товар '.$product->name.' успешно изменен!')->withTitle('Товары');
          }else{
              return back()->with('warning', 'Ошибка сервера!');
          }
    }
public function update ( Request $ request , $ id ) { if ( $ request -> isMethod ( 'PUT' ) ) { if ( $ request -> price_promo > $ request -> price ) { $ request -> price_promo = null ; } $ product = Product :: find ( $ id ) ; if ( $ product -> company_id != Auth :: user ( ) -> company_id ) { return redirect ( '/welcome' ) -> with ( 'danger' , 'В доступе отказано!');} $ your_self_parametrs_array = $ request -> your_self_parametr [ 'parametr' ] ; $ default_parametrs_array = $ request -> default_parametr [ 'parametr' ] ; $ code = $ product -> company_id . '-' . $ request -> code ; $ st_sp = self :: createProductCheckSpetial ( $ product -> company_id ) ; $ array_for_deleting_from_s3_drive = json_decode ( $ product -> gallery ) ; self :: deleteImagesFromS3Drive ( $ array_for_deleting_from_s3_drive ) ; $ gallery = $ request -> gallery ; $ galleryArray = explode ( " , " , $ gallery ) ; $ json_array_images = self :: uploadImagesToS3Drive ( $ galleryArray ) ; ProductsItem :: where ( 'product_id' , $ product -> id ) -> delete ( ) ; $ subcategory = Subcategory :: find ( $ request -> subcategory ) ; $ product -> category_id = $ subcategory -> category_id ; $ product -> subcategory_id = $ request -> subcategory ; $ product -> name = $ request -> name ; $ product -> desc = $ request -> desc ; $ product -> code = $ code ; $ product -> brand = $ request -> brand ; $ product -> price = $ request -> price ; $ product -> old_price = ( isset ( $ request -> old_price ) ? $ request -> old_price : null ) ; $ product -> price_promo = ( isset ( $ request -> price_promo ) ? $ request -> price_promo : null ) ; $ product -> gallery = $ json_array_images ; $ product -> video_url = ( isset ( $ request -> video ) ? $ request -> video : null ) ; $ product -> status_spacial = $ st_sp ; $ product -> status_moderation = '0' ; $ product -> status_remod = '1' ; $ product -> save ( ) ; if ( ( $ default_parametrs_array == null ) && ( $ your_self_parametrs_array == null ) ) { } elseif ( $ your_self_parametrs_array == null ) { self :: storeProductItems ( 'default' , $ product -> id , $ default_parametrs_array ) ; } elseif ( $ default_parametrs_array == null ) { self :: storeProductItems ( 'your_self' , $ product -> id , $ your_self_parametrs_array ) ; } elseif ( ( $ default_parametrs_array != null ) && ( $ your_self_parametrs_array != null ) ) { self :: storeProductItems ( 'default' , $ product -> id , $ default_parametrs_array ) ; self :: storeProductItems ( 'your_self' , $ product -> id , $ your_self_parametrs_array ) ; } return redirect ( 'company/products' ) -> with ( 'success' , 'Товар '.$pro d u ct->nam e. ' ус п ешно изменен!')->withTitle('Товар ы ') ; } else { return back ( ) -> with ( 'warning' , 'Ошибка сервера!'); } }
Update the specified resource in storage.
Update the specified resource in storage .
//промоцена не может быть больше цены (апрель2020)