Пример #1
0
 public function upload($form_data)
 {
     $validator = Validator::make($form_data, Image::$rules, Image::$messages);
     if ($validator->fails()) {
         return Response::json(['error' => TRUE, 'message' => $validator->messages()->first(), 'code' => 400], 400);
     }
     $photo = $form_data['file'];
     $this->temp_name = $form_data['temp_key'];
     $this->module = $form_data['module'];
     if (!empty($this->module) && $this->module == 'products') {
         $originalName = $photo->getClientOriginalName();
         $originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - 4);
         if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
             $filename = iconv("UTF-8", "WINDOWS-1251", html_entity_decode(htmlentities(basename($originalNameWithoutExt), ENT_QUOTES, 'UTF-8')));
         } else {
             $filename = html_entity_decode(htmlentities(basename($originalNameWithoutExt), ENT_QUOTES, 'UTF-8'));
         }
         $filenameExt = $filename . '.jpg';
         $uploadSuccess1 = $this->original($photo, $filenameExt);
         $uploadSuccess2 = $this->sm_icon($photo, $filenameExt);
         $uploadSuccess3 = $this->md_icon($photo, $filenameExt);
         $uploadSuccess4 = $this->lg_icon($photo, $filenameExt);
         //If image is uploaded and thumbnails created
         if (!$uploadSuccess1 || !$uploadSuccess2 || !$uploadSuccess3 || !$uploadSuccess4) {
             //Store to database
             if (!empty($form_data['target'])) {
                 $image = ['img' => $filenameExt, 'position' => 0];
                 Model_Products::storeImages($image, $form_data['target']);
             }
             return Response::json(['error' => TRUE, 'message' => 'Server error while uploading', 'code' => 500], 500);
         }
     } elseif (!empty($this->module) && $this->module == 'tables') {
         $filename = basename($this->temp_name);
         $filenameExt = $filename . '.png';
         $uploadSuccess1 = $this->table_img($photo, $filenameExt);
         //If image is uploaded and thumbnails created
         if (!$uploadSuccess1) {
             return Response::json(['error' => TRUE, 'message' => 'Server error while uploading', 'code' => 500], 500);
         }
     } elseif (!empty($this->module) && $this->module == 'sliders') {
         $originalName = $photo->getClientOriginalName();
         $originalNameWithoutExt = substr($originalName, 0, strlen($originalName) - 4);
         $filename = basename($originalNameWithoutExt);
         $filenameExt = $filename . '.jpg';
         $uploadSuccess1 = $this->sliders($photo, $filenameExt);
         //If image is uploaded and thumbnails created
         if (!$uploadSuccess1) {
             return Response::json(['error' => TRUE, 'message' => 'Server error while uploading', 'code' => 500], 500);
         }
     }
     //		$sessionImage = new Image;
     //		$sessionImage->filename      = $allowed_filename;
     //		$sessionImage->original_name = $originalName;
     //		$sessionImage->save();
     return Response::json(['error' => FALSE, 'code' => 200], 200);
 }
 /**
  * Display form
  * @return \Illuminate\Http\Response
  */
 public function getIndex()
 {
     $response['pageTitle'] = trans('upcoming_product.upcoming_product');
     $data = Model_UpcomingProduct::getUpcomingProduct();
     if (!empty($data[0]) && is_array($data[0])) {
         foreach ($data[0] as $key => $val) {
             $response[$key] = $val;
         }
     }
     $response['blade_custom_css'] = ['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'];
     $response['blade_custom_js'] = ['global/plugins/bootstrap-switch/js/bootstrap-switch.min', 'admin/pages/scripts/components-dropdowns', 'global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min', 'global/plugins/bootstrap-select/bootstrap-select.min', 'global/plugins/select2/select2.min', 'global/plugins/jquery-multi-select/js/jquery.multi-select'];
     $response['products'] = Model_Products::getProducts(FALSE, ['title'], FALSE, 0, 0, TRUE);
     return Theme::view('upcoming_product.upcoming_product', $response);
 }
Пример #3
0
 /**
  * Used to display partials or do ajax requests
  *
  * @param id
  * @param $request
  *
  * @return \Illuminate\Http\Response
  * @internal param int $id
  */
 public function getShow($id = FALSE, $request = FALSE, $form_method = FALSE)
 {
     if ($request == 'add_product') {
         $response['blade_standalone'] = TRUE;
         $response['products'] = Model_Products::getProducts(FALSE, ['title']);
         return Theme::View('orders.add_product_partial', $response);
     } elseif ($request == 'add_product_info' && is_numeric($id)) {
         if ($product = Model_Products::getProducts($id, ['sizes'])) {
             $response['blade_standalone'] = TRUE;
             $response['total_quantity'] = 0;
             if (!empty($product[$id]) && is_array($product[$id])) {
                 $product = $product[$id];
             }
             //Sizes
             if (!empty($product['sizes']) && is_array($sizes = json_decode($product['sizes'], TRUE))) {
                 $response['sizes'] = $sizes;
                 foreach ($sizes as $key => $size) {
                     if (!empty($size['quantity'])) {
                         $response['total_quantity'] = $response['total_quantity'] + intval($size['quantity']);
                     }
                 }
             }
             $response['product_id'] = $id;
             return Theme::View('orders.add_product_info_partial', $response);
         } else {
             return FALSE;
         }
     } elseif ($request == 'products_table' && is_numeric($id)) {
         $response = [];
         $response['blade_standalone'] = TRUE;
         if ($order_products = Model_Orders::getOrderProducts($id)) {
             $products_list = [];
             $products_images = [];
             $response['thumbs_path'] = Config::get('system_settings.product_public_path');
             $response['icon_size'] = Config::get('images.sm_icon_size');
             $upload_path = Config::get('system_settings.product_upload_path');
             if (!empty($order_products) && is_array($order_products)) {
                 foreach ($order_products as $product) {
                     if (!in_array($product['product_id'], $products_list)) {
                         $products_list[] = $product['product_id'];
                     }
                 }
             }
             //Fetch images
             if (!empty($products_list) && is_array($products_list)) {
                 if ($products = Model_Products::getProducts($products_list, ['title', 'images'])) {
                     foreach ($products as $key => $product) {
                         if (!empty($product['images'])) {
                             $product['images'] = json_decode($product['images'], TRUE);
                             if (is_array($product['images'])) {
                                 uasort($product['images'], function ($a, $b) {
                                     if ($a == $b) {
                                         return 0;
                                     }
                                     return $a < $b ? -1 : 1;
                                 });
                                 reset($product['images']);
                                 $product['images'] = key($product['images']);
                                 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                                     if (file_exists(iconv("UTF-8", "WINDOWS-1251", $upload_path . $product['id'] . DIRECTORY_SEPARATOR . $response['icon_size'] . DIRECTORY_SEPARATOR . $product['images']))) {
                                         $products_images[$product['id']] = $product['images'];
                                     }
                                 } else {
                                     if (file_exists($upload_path . $product['id'] . DIRECTORY_SEPARATOR . $response['icon_size'] . DIRECTORY_SEPARATOR . $product['images'])) {
                                         $products_images[$product['id']] = $product['images'];
                                     }
                                 }
                             }
                         }
                     }
                     foreach ($order_products as $key => $product) {
                         if (array_key_exists($product['product_id'], $products_images)) {
                             $order_products[$key]['image'] = $products_images[$product['product_id']];
                             if (!empty($products[$product['product_id']]['title'])) {
                                 $order_products[$key]['title'] = $products[$product['product_id']]['title'];
                             }
                         }
                     }
                     $response['products'] = $order_products;
                 }
             }
         }
         $response['method'] = $form_method;
         return Theme::View('orders.products_list_partial', $response);
     } elseif (is_numeric($id) && $request == FALSE) {
         $response['method'] = 'locked';
         $order = Model_Orders::getOrders($id, FALSE);
         if (!empty($order[0]) && is_array($order[0])) {
             $response['order'] = $order[0];
             switch ($response['order']['status']) {
                 case 'pending':
                     $response['order']['status_color'] = 'bg-green-jungle';
                     break;
                 case 'confirmed':
                     $response['order']['status_color'] = 'bg-yellow-casablanca';
                     break;
                 case 'completed':
                     $response['order']['status_color'] = 'bg-blue-madison';
                     break;
                 case 'canceled':
                     $response['order']['status_color'] = 'bg-red-thunderbird';
                     break;
             }
         }
         foreach ($this->states as $state) {
             $response['states'][$state] = trans('orders.' . $state);
         }
         $response['pageTitle'] = trans('orders.preview_order');
         return Theme::view('orders.create_edit_order', $response);
     } else {
         return FALSE;
     }
 }
Пример #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function postDestroy($id)
 {
     $response['status'] = 'error';
     $response['message'] = trans('products.not_removed');
     if (!empty($id) && intval($id) > 0) {
         if (Model_Products::removeProduct($id) === TRUE) {
             $response['status'] = 'success';
             $response['message'] = trans('products.removed');
         }
     }
     return response()->json($response);
 }
Пример #5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function getEdit($id)
 {
     $response['pageTitle'] = trans('carousels.edit');
     $response['blade_custom_css'] = ['global/plugins/select2/select2', 'global/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min'];
     $response['blade_custom_js'] = ['global/plugins/bootstrap-select/bootstrap-select.min', 'global/plugins/select2/select2.min', 'admin/pages/scripts/components-dropdowns', 'global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min'];
     $response['categories'] = Model_Categories::getCategory(FALSE, ['title']);
     $response['pages'] = Model_Pages::getPage(FALSE, ['id', 'title']);
     $response['products'] = Model_Products::getProducts(FALSE, ['title']);
     $response['carousel'] = Model_Carousels::getCarousels($id, FALSE);
     if (!empty($response['carousel']) && !empty($response['carousel'][0])) {
         $response['carousel'] = $response['carousel'][0];
     }
     if (!empty($response['carousel']['products']) && $response['carousel']['products'] == 'newest' || $response['carousel']['products'] == 'discounted') {
         $response['carousel']['slider_type'] = $response['carousel']['products'];
     } else {
         $response['carousel']['slider_type'] = 'others';
     }
     if (!empty($response['carousel']['products']) && $response['carousel']['slider_type'] == 'others') {
         $response['carousel']['products'] = is_array(json_decode(',', $response['carousel']['products'], TRUE)) ? json_decode(',', $response['carousel']['products'], TRUE) : explode(',', $response['carousel']['products']);
     }
     if (!empty($response['carousel']['active_from']) && $response['carousel']['active_from'] == '0000-00-00 00:00:00') {
         $response['carousel']['active_from'] = '';
     }
     if (!empty($response['carousel']['active_to']) && $response['carousel']['active_to'] == '0000-00-00 00:00:00') {
         $response['carousel']['active_to'] = '';
     }
     return Theme::view('carousels.create_edit_carousel', $response);
 }
Пример #6
0
 public static function returnProduct($record_id)
 {
     //Get record id
     $record = DB::table('order_products')->where('id', '=', $record_id)->get();
     if (!empty($record[0]) && is_array($record[0]) && !empty($record[0]['product_id'])) {
         $product_id = $record[0]['product_id'];
         $product = Model_Products::getProducts($product_id, ['sizes']);
         if (!empty($product[$product_id]['sizes']) && is_array(json_decode($product[$product_id]['sizes'], TRUE))) {
             $sizes = json_decode($product[$product_id]['sizes'], TRUE);
             $pr_quantity = $product[$product_id]['quantity'];
             foreach ($sizes as $key => $size) {
                 if ($record[0]['size'] == $size['name']) {
                     $sizes[$key]['quantity'] = intval($sizes[$key]['quantity']) + intval($record[0]['quantity']);
                     $pr_quantity = intval($pr_quantity) + intval($record[0]['quantity']);
                 }
             }
         }
         $sizes = json_encode($sizes);
         return self::manageQuantities($product_id, $sizes, $pr_quantity);
     } else {
         return FALSE;
     }
 }
Пример #7
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function getEdit($id = FALSE)
 {
     $response['related_categories'] = Model_Products::getProductToCategory($id);
     $response['blade_standalone'] = TRUE;
     //Sizes load
     $response['size'] = Model_Sizes::getSizes(FALSE, $id);
     return Theme::view('sizes.show_size_partial', $response);
 }