Esempio n. 1
0
 /**
  * Get data formatted for JSON output
  *
  * @param Array $attach Optional: sub-resources to attach to the base data, if available. Possible values: options, images, custom_fields
  * @return Array $output The formatted data
  */
 public function getOutput($attach = [])
 {
     $output = array('id' => $this->id, 'name' => $this->name, 'sku' => $this->sku, 'description' => $this->description, 'price' => $this->price, 'cost_price' => $this->cost_price, 'retail_price' => $this->retail_price, 'sale_price' => $this->sale_price, 'calculated_price' => $this->calculated_price, 'warranty' => $this->warranty, 'custom_url' => $this->custom_url);
     if (in_array('options', $attach) && isset($this->_options)) {
         $output['options'] = unserialize($this->_options);
     }
     if (in_array('images', $attach)) {
         $images = Image::where('product_id', $this->id)->get();
         $output['images'] = [];
         if (count($images)) {
             foreach ($images as $image) {
                 $output['images'][] = $image->mapData();
             }
         }
     }
     if (in_array('custom_fields', $attach)) {
         $custom_fields = CustomField::where('product_id', $this->id)->get();
         $output['custom_fields'] = [];
         if (count($custom_fields)) {
             foreach ($custom_fields as $custom_field) {
                 $output['custom_fields'][] = $custom_field->mapData();
             }
         }
     }
     return $output;
 }
Esempio n. 2
0
 /** 
  * observe image event saved
  * 1. check default image and make sure it's the only default
  * 2. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saved($model)
 {
     //1. check default image event
     if (isset($model->imageable_id) && $model->is_default == 1) {
         $images = Image::where('imageable_id', $model->imageable_id)->where('imageable_type', $model->imageable_type)->where('is_default', 1)->where('id', '!=', $model->id)->get();
         foreach ($images as $image) {
             //1a. set is_default to false for other image
             $image->fill(['is_default' => 0]);
             if (!$image->save()) {
                 $model['errors'] = $image->geterror();
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Delete Image From Session folder, based on server created filename
  */
 public function delete($filename)
 {
     $full_size_dir = public_path('images/full_size/');
     $icon_size_dir = public_path('images/icon_size/');
     $sessionImage = Image::where('filename', 'like', $filename)->first();
     if (empty($sessionImage)) {
         return Response::json(['error' => true, 'code' => 400], 400);
     }
     $full_path1 = $full_size_dir . $sessionImage->filename;
     $full_path2 = $icon_size_dir . $sessionImage->filename;
     if (File::exists($full_path1)) {
         File::delete($full_path1);
     }
     if (File::exists($full_path2)) {
         File::delete($full_path2);
     }
     if (!empty($sessionImage)) {
         $sessionImage->delete();
     }
     return Response::json(['error' => false, 'code' => 200], 200);
 }
 /**
  * Delete Image From Session folder, based on original filename
  */
 public function delete($originalFilename)
 {
     $full_size_dir = Config::get('images.full_size');
     $icon_size_dir = Config::get('images.icon_size');
     $sessionImage = Image::where('original_name', 'like', $originalFilename)->first();
     if (empty($sessionImage)) {
         return Response::json(['error' => true, 'code' => 400], 400);
     }
     $full_path1 = $full_size_dir . $sessionImage->filename . '.jpg';
     $full_path2 = $icon_size_dir . $sessionImage->filename . '.jpg';
     if (File::exists($full_path1)) {
         File::delete($full_path1);
     }
     if (File::exists($full_path2)) {
         File::delete($full_path2);
     }
     if (!empty($sessionImage)) {
         $sessionImage->delete();
     }
     return Response::json(['error' => false, 'code' => 200], 200);
 }
 /** 
  * observe product extension event deleting
  * 1. check transaction
  * 2. delete image
  * 3. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function deleting($model)
 {
     $errors = new MessageBag();
     //1. check transaction
     $transaction = TransactionExtension::productextensionid($model->id)->first();
     if ($transaction) {
         $errors->add('Product', 'Tidak dapat menghapus produk yang sudah pernah dibeli.');
     }
     //2. delete product extension's image
     $images = Image::where('imageable_type', 'App\\Models\\ProductExtension')->where('imageable_id', $model->id)->get();
     foreach ($images as $image) {
         if (!$image->delete()) {
             $errors->add('image', $image->getError());
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
Esempio n. 6
0
 public function view($sha1)
 {
     $image = Image::where(['sha1' => $sha1])->firstOrFail();
     return Redirect::away($image->getRealUrl());
 }
Esempio n. 7
0
 public function view($id)
 {
     $property = Property::find($id);
     $images = Image::where('propertyId', $property->id)->get();
     return view('property.view')->with('name', Auth::user()->name)->with('propertyName', $property->name)->with('propertyLocation', $property->location)->with('images', $images);
 }
 /**
  * Delete Image From Session folder, based on original filename
  */
 public function delete($originalFilename)
 {
     Log::info(__CLASS__ . "::" . __METHOD__ . "::" . "Original filename is      " . $originalFilename);
     $full_size_dir = Config::get('images.path');
     Log::info(__CLASS__ . "::" . __METHOD__ . "::" . "Full size dir is     " . $full_size_dir);
     $sessionImage = Image::where('path', 'like', $originalFilename)->first();
     if (empty($sessionImage)) {
         return Response::json(['error' => true, 'code' => 400], 400);
     }
     $full_path1 = $full_size_dir . $sessionImage->path . '.jpg';
     Log::info(__CLASS__ . "::" . __METHOD__ . "::" . "session image filename is " . $sessionImage->path . " full path is " . $full_path1);
     if (File::exists($full_path1)) {
         File::delete($full_path1);
         Log::info(__CLASS__ . "::" . __METHOD__ . "::" . "Deleted file    " . $full_path1);
     }
     if (!empty($sessionImage)) {
         $sessionImage->delete();
         Log::info(__CLASS__ . "::" . __METHOD__ . "::" . "Deleted session image    " . $full_path1);
     }
     return Response::json(['error' => false, 'code' => 200], 200);
 }
Esempio n. 9
0
 /** 
  * observe product event deleting
  * 1. delete varian
  * 2. delete price
  * 3. delete category(and tag)
  * 4. delete label
  * 5. delete image
  * 6. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function deleting($model)
 {
     $errors = new MessageBag();
     //1. delete product's varian
     $varians = Varian::where('product_id', $model->id)->get();
     foreach ($varians as $varian) {
         if (!$varian->delete()) {
             $errors->add('varian', $varian->getError());
         }
     }
     //2. delete product's price
     $prices = Price::where('product_id', $model->id)->get();
     foreach ($prices as $price) {
         if (!$price->delete()) {
             $errors->add('price', $price->getError());
         }
     }
     //3. delete product's categories
     $categories = CategoryProduct::where('product_id', $model->id)->get();
     foreach ($categories as $category) {
         if (!$category->delete()) {
             $errors->add('category', $category->getError());
         }
     }
     //4. delete product's label
     $labels = ProductLabel::where('product_id', $model->id)->get();
     foreach ($labels as $label) {
         if (!$label->delete()) {
             $errors->add('label', $label->getError());
         }
     }
     //5. delete product's image
     $images = Image::where('imageable_type', 'App\\Models\\Product')->where('imageable_id', $model->id)->get();
     foreach ($images as $image) {
         if (!$image->delete()) {
             $errors->add('image', $image->getError());
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }