Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     ProductImage::create(['title' => 'Product 3 - image title', 'url' => 'zamkniecie-kasetowe-do-skrzynek-narzedziowych-k-o.jpg', 'product_id' => 3, 'published' => 1, 'main' => 1]);
     ProductImage::create(['title' => 'Product 4 - image title', 'url' => 'zawias-do-burt-aluminiowych.jpg', 'product_id' => 4, 'published' => 1, 'main' => 1]);
     ProductImage::create(['title' => 'Product 5 - image title', 'url' => 'zawias-drzwi-bocznych-k-o-l-155-kpl.jpg', 'product_id' => 5, 'published' => 1, 'main' => 1]);
 }
Exemplo n.º 2
0
 public function postDestroy()
 {
     $product_image = ProductImage::find(Input::get('id'));
     if ($product_image) {
         File::delete('img/products/' . $product_image->url);
         File::delete('img/products/thumb/' . $product_image->url);
         $product_image->delete();
         return Redirect::back();
     }
     return Redirect::back()->with('message', 'Ошибка удаления');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     ProductImage::truncate();
     //For each product we will be inserting random number of keywords
     foreach (range(1, 50) as $product_index) {
         $num_entries = rand(0, 3);
         $i = 1;
         foreach (range(0, $num_entries) as $entries) {
             ProductImage::create(['product_id' => $product_index, 'image_path' => 'image_' . $i . '.jpeg']);
             $i++;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductImage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'last_update' => $this->last_update, 'product_id' => $this->product_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductImage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith('product');
     $query->andFilterWhere(['product_image_id' => $this->product_image_id, 'flag_cover' => $this->flag_cover, 'position' => $this->position, 'flag_active' => $this->flag_active, 'date_added' => $this->date_added, 'date_update' => $this->date_update]);
     $query->andFilterWhere(['like', 'product_name', $this->product_id])->andFilterWhere(['like', 'thumb_url', $this->thumb_url])->andFilterWhere(['like', 'mid_size_url', $this->mid_size_url])->andFilterWhere(['like', 'ori_size_url', $this->ori_size_url]);
     return $dataProvider;
 }
Exemplo n.º 6
0
 /**
  * Finds the ProductImage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ProductImage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ProductImage::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Fungsi untuk menghapus gambar produk berdasarkan id produknya
  * @param  [type] $product_id [description]
  * @return [type]             [description]
  */
 public function destroyByProduct($product_id)
 {
     $product_images = ProductImage::where('product_id', $product_id)->get();
     if ($product_images) {
         $config = config('amtekcommerce.product_image');
         foreach ($product_images as $product_image) {
             $product = Product::find($product_image->product_id);
             $supplier = $product->supplier;
             $upload_dir = $config['dir'] . '/sup_' . $supplier->id;
             $deleteImage = unlink($upload_dir . '/' . $product_image->name);
             if ($deleteImage) {
                 $product_image->delete();
             }
         }
         $check_product_images = ProductImage::where('product_id', $product_id)->get();
         if (count($check_product_images) > 0) {
             return ['status' => 'failed', 'message' => 'Tidak semua gambar produk berhasil dihapus.', 'product_images' => $check_product_images];
         } else {
             return ['status' => 'success', 'message' => 'Gambar produk berhasil dihapus.', 'product_images' => null];
         }
     } else {
         return ['status' => 'failed', 'message' => 'Gambar produk tidak tersedia.', 'product_images' => null];
     }
 }
 public function actionProductview($id)
 {
     $product = Product::findOne($id);
     $productImages = ProductImage::find()->where(['product_id' => $id])->orderBy('id DESC')->all();
     return $this->render('//Frontend/ProductView', ['product' => $product, 'productImages' => $productImages]);
 }