/**
  * Delete a varian
  * 
  * @param pid, id
  * @return function
  */
 public function destroy($pid = null, $id = null)
 {
     //cek auth
     //get data
     $APIProduct = new APIProduct();
     $product = $APIProduct->getShow($pid);
     $varian = $this->VarianFindData($product['data']['varians'], $id);
     //delete varian
     unset($product['data']['varians'][$varian['key']]);
     //save
     $result = $APIProduct->postData($product['data']);
     //response
     if ($result['status'] != 'success') {
         $this->errors = $result['message'];
     }
     //return view
     $this->page_attributes->success = "Data Varian Telah Dihapus";
     return $this->generateRedirectRoute('goods.product.show', ['id' => $pid]);
 }
 /**
  * Store a product
  * 
  * 1. Store Price
  * 2. Store Image
  * 3. Store Label
  * 4. Store Tag
  * 5. Store Category
  * @param id
  * @return object view
  */
 public function store($id = "")
 {
     //1. Store Price
     $prices = json_decode(Input::get('prices'), true);
     if (is_null($prices)) {
         $prices = [];
     }
     $tmpPrice = ['id' => "", 'price' => str_replace('IDR ', '', str_replace('.', '', Input::get('price'))), 'promo_price' => str_replace('IDR ', '', str_replace('.', '', Input::get('promo_price'))), 'started_at' => date('Y-m-d H:i:s', strtotime(Input::get('started_at')))];
     array_push($prices, $tmpPrice);
     //2. Store Image
     $images = [];
     foreach (Input::get('thumbnail') as $key => $image) {
         $tmpImage = ['id' => "", 'thumbnail' => Input::get('thumbnail')[$key], 'image_xs' => Input::get('image_xs')[$key], 'image_sm' => Input::get('image_sm')[$key], 'image_md' => Input::get('image_md')[$key], 'image_lg' => Input::get('image_lg')[$key], 'is_default' => Input::get('default')[$key]];
         if (!empty($tmpImage['thumbnail']) || !empty($tmpImage['image_xs']) || !empty($tmpImage['image_sm']) || !empty($tmpImage['image_md']) || !empty($tmpImage['lg'])) {
             array_push($images, $tmpImage);
         }
         if (count($images) == 0) {
             $images[0] = ['id' => "", 'thumbnail' => "", 'image_xs' => "", 'image_sm' => "", 'image_md' => "", 'image_lg' => "", 'is_default' => ""];
         }
     }
     //3. Store Label
     $labels = [];
     $tmpLabel = explode(',', trim(Input::get('label'), ' '));
     foreach ($tmpLabel as $key => $tmp) {
         $labels[$key] = ['id' => "", 'product_id' => $id, 'value' => "", "label" => $tmp, "started_at" => date('Y-m-d H:i:s', strtotime('now')), "ended_at" => ""];
     }
     //4. Store Tag
     $tags = [];
     $tmpTag = explode(',', trim(Input::get('tag'), ' '));
     foreach ($tmpTag as $key => $tmp) {
         $tags[$key] = ['id' => $tmp, 'slug' => ""];
     }
     //5. Store Category
     $categories = [];
     $tmpCategory = explode(',', trim(Input::get('category'), ' '));
     foreach ($tmpCategory as $key => $tmp) {
         $categories[$key] = ['id' => $tmp, 'slug' => ""];
     }
     //6. Store Product
     $data = ['id' => $id, 'name' => Input::get('name'), 'upc' => Input::get('upc'), 'label' => Input::get('label'), 'description' => json_encode(['description' => Input::get('description'), 'fit' => Input::get('fit'), 'care' => Input::get('care')]), 'started_at' => Input::get('started_at'), 'images' => $images, 'prices' => $prices, 'labels' => $labels, 'categories' => $categories, 'tags' => $tags, 'slug' => NULL];
     //check is null image
     if (empty($data['images'])) {
         unset($data['images']);
     }
     //api
     $APIProduct = new APIProduct();
     $result = $APIProduct->postData($data);
     //result
     if ($result['status'] != 'success') {
         $this->errors = $result['message'];
     }
     //return view
     if (!empty($id)) {
         $this->page_attributes->success = "Data Produk Telah Diedit";
     } else {
         $this->page_attributes->success = "Data Produk Telah Ditambahkan";
     }
     return $this->generateRedirectRoute('goods.product.index');
 }