Ejemplo n.º 1
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function getEdit($id = FALSE)
 {
     $customCSS = ['global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5', 'global/plugins/bootstrap-summernote/summernote', 'global/plugins/bootstrap-select/bootstrap-select.min', 'global/plugins/select2/select2', 'global/plugins/jquery-multi-select/css/multi-select', 'global/plugins/bootstrap-switch/css/bootstrap-switch.min', 'global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min', 'global/plugins/dropzone/css/dropzone'];
     $customJS = ['global/plugins/bootstrap-wysihtml5/wysihtml5-0.3.0', 'global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5', 'global/plugins/bootstrap-summernote/summernote.min', 'admin/pages/scripts/components-dropdowns', 'global/plugins/bootstrap-select/bootstrap-select.min', 'global/plugins/bootstrap-select/bootstrap-select.min', 'global/plugins/select2/select2.min', 'global/plugins/jquery-multi-select/js/jquery.multi-select', 'global/plugins/fuelux/js/spinner.min', 'global/plugins/bootstrap-switch/js/bootstrap-switch.min', 'global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min', 'global/plugins/dropzone/dropzone', 'admin/pages/scripts/form-dropzone', 'global/plugins/jquery-slugify/speakingurl', 'global/plugins/jquery-slugify/slugify.min'];
     $response['blade_custom_css'] = $customCSS;
     $response['blade_custom_js'] = $customJS;
     $response['categories'] = Model_Categories::getCategory(FALSE, ['title']);
     $response['related_categories'] = Model_Products::getProductToCategory($id);
     $response['products'] = Model_Products::getProducts(FALSE, ['title']);
     $response['groups'] = Model_Sizes::getSizes(TRUE);
     $response['colors'] = Model_Products::getColors();
     $response['related_colors'] = Model_Products::getColor($id);
     $response['dimensions_tables'] = Model_Tables::getTables();
     if (!empty($response['dimensions_tables']) && is_array($response['dimensions_tables'])) {
         foreach ($response['dimensions_tables'] as $key => $table) {
             if (isset($table['image'])) {
                 unset($response['dimensions_tables'][$key]['image']);
             }
         }
     }
     //Get product and it's data
     $product = Model_Products::getProducts($id);
     //Prepare product for response
     if (!empty($product[$id])) {
         $response['product'] = $product[$id];
         if (!empty($product[$id]['sizes'])) {
             $response['sizes'] = json_decode($product[$id]['sizes'], TRUE);
         }
         if (!empty($response['product']['discount_start']) && $response['product']['discount_start'] == '0000-00-00 00:00:00') {
             $response['product']['discount_start'] = '';
         }
         if (!empty($response['product']['discount_end']) && $response['product']['discount_end'] == '0000-00-00 00:00:00') {
             $response['product']['discount_end'] = '';
         }
     }
     //SEO Tab
     if (($slug = Model_Products::getURL($id)) != FALSE) {
         $response['seo']['friendly_url'] = $slug;
     }
     if (!empty($response['product']['page_title'])) {
         $response['seo']['page_title'] = $response['product']['page_title'];
         unset($response['product']['page_title']);
     }
     if (!empty($response['product']['meta_description'])) {
         $response['seo']['meta_description'] = $response['product']['meta_description'];
         unset($response['product']['meta_description']);
     }
     if (!empty($response['product']['meta_keywords'])) {
         $response['seo']['meta_keywords'] = $response['product']['meta_keywords'];
         unset($response['product']['meta_keywords']);
     }
     //Images Tab
     if (!empty($response['product']['images'])) {
         $response['product']['images'] = json_decode($response['product']['images'], TRUE);
         if (is_array($response['product']['images'])) {
             $response['thumbs_path'] = Config::get('system_settings.product_public_path') . $id . '/' . Config::get('images.sm_icon_size') . '/';
             uasort($response['product']['images'], function ($a, $b) {
                 if ($a == $b) {
                     return 0;
                 }
                 return $a < $b ? -1 : 1;
             });
         }
     }
     //Tags
     $tags = Model_Products::getTags($id);
     if (!empty($tags) && is_array($tags)) {
         foreach ($tags as $key => $tag) {
             $response['product']['tags'][] = $tag['title'];
         }
         $response['product']['tags'] = implode(',', $response['product']['tags']);
     }
     //Manufacturer
     $response['manufacturers'] = Model_Products::getManufacturers();
     $response['product']['manufacturer'] = Model_Products::getManufacturer($id);
     //Material
     $response['materials'] = Model_Products::getMaterials();
     $response['product']['material'] = Model_Products::getMaterial($id);
     if (!empty($response['product']['material'][0])) {
         $response['product']['material'] = $response['product']['material'][0];
     }
     //Related products
     if (!empty($response['product']['related_products'])) {
         $response['related_products'] = json_decode($response['product']['related_products'], TRUE);
         unset($response['product']['related_products']);
     }
     $response['pageTitle'] = trans('products.edit');
     return Theme::view('products.edit_product', $response);
 }
Ejemplo n.º 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function postDestroy($id = FALSE)
 {
     $response['status'] = 'error';
     $response['message'] = trans('tables.not_removed');
     if (!empty($id) && intval($id) > 0) {
         if (Model_Tables::removeTable($id) === TRUE) {
             $response['status'] = 'success';
             $response['message'] = trans('tables.removed');
         }
     }
     return response()->json($response);
 }