Example #1
0
 /** @depends testStore */
 public function testDestroy($photo)
 {
     $this->delete(route('api.admin.product.photo.item', [$this->fetch('product'), $photo]));
     $this->assertResponseStatus(204);
     $check = ProductPhoto::find($photo->id);
     $this->assertNull($check);
     $check = UploadFile::find($photo->file_id);
     $this->assertNull($check);
     $this->assertFalse(Storage::exists($photo->file->file_path));
     $this->clear();
 }
Example #2
0
 protected static function boot()
 {
     parent::boot();
     // static::updating(function ($product) {
     //     $changed = $product->isDirty() ? $product->getDirty() : false;
     //     if ($changed && $changed['options']) {
     //         // maintain stock
     //         print_r($changed['options']);
     //     }
     // });
     static::deleting(function ($product) {
         $ids = ProductPhoto::select()->where('product_id', '=', $product->id)->lists('id');
         ProductPhoto::destroy($ids->toArray());
     });
 }
 /**
  * Execute the job.
  *
  * @param Request $request
  */
 public function handle(Request $request)
 {
     $insertQuery = [];
     //preview images
     for ($i = 1; $i <= $this->count; $i++) {
         $fileName = $this->saveCroppedImage($request, $i);
         //DELETE COLOUR IMAGES THAT ARE BEING DELETED IN CMS
         $delete_colour_image_ids = $request->get("delete_colour_images");
         if ($delete_colour_image_ids) {
             $delete_colour_image_ids_array = explode(",", $delete_colour_image_ids);
             ProductPhoto::whereIn("id", $delete_colour_image_ids_array)->delete();
         }
         $edit_image_id = $request->get("edit_colour_img_" . $i);
         if ($edit_image_id) {
             $product_photo = ProductPhoto::find($edit_image_id);
             if ($fileName) {
                 $product_photo->img = $fileName;
                 $product_photo->is_colour_img = 1;
                 $this->product->product_photos()->save($product_photo);
                 DB::table('photos_colours')->where("photo_id", "=", $product_photo->id)->update(['photo_id' => $product_photo->id, 'colour_id' => (int) $request->get("product_colour_code_input_" . $i)]);
             }
         } else {
             $product_photo = new ProductPhoto();
             if ($fileName) {
                 $product_photo->img = $fileName;
                 $product_photo->is_colour_img = 1;
                 $this->product->product_photos()->save($product_photo);
                 $insertQuery[] = ['photo_id' => $product_photo->id, 'colour_id' => (int) $request->get("product_colour_code_input_" . $i)];
             }
         }
     }
     if (count($insertQuery) > 0) {
         DB::table('photos_colours')->insert($insertQuery);
     }
     //        dd("STOP");
 }
 /**
  * Execute the job.
  *
  * @param Request $request
  */
 public function handle(Request $request)
 {
     for ($i = 1; $i <= 4; $i++) {
         $fileName = $this->saveCroppedImage($request, $i);
         $edit_preview_img = $request->get("edit_product_preview_img_" . $i);
         if ($edit_preview_img) {
             $product_photo = ProductPhoto::find($edit_preview_img);
         } else {
             $product_photo = new ProductPhoto();
         }
         //cropped image
         if ($fileName[0]) {
             $this->rmFile($product_photo->img);
             //orignal size image
             if ($fileName[1]) {
                 $this->rmFile($product_photo->img_orig);
                 $product_photo->img_orig = $fileName[1];
             }
             $product_photo->img = $fileName[0];
             $product_photo->is_detail_preview = 1;
             $this->product->product_photos()->save($product_photo);
         }
     }
 }
Example #5
0
 public function delete(Product $product)
 {
     //DELETE all related photos
     $product_photos = ProductPhoto::where("product_id", "=", $product->id)->get();
     foreach ($product_photos as $photo) {
         $this->rmFile($photo->img);
         $this->rmFile($photo->img_orig);
     }
     $product->delete();
     return redirect('cms/product/product');
 }