Ejemplo n.º 1
0
 /**
  * @Get("/{product_id:[0-9]+}/{params:[0-9a-zA-Z\-\_\.\:\,]+}", name="show-product")
  */
 public function indexAction()
 {
     $product_id = $this->filter->sanitize($this->dispatcher->getParam('product_id'), 'int');
     $lang = $this->filter->sanitize($this->dispatcher->getParam("lang"), 'string');
     // Selected product
     // Check if the product exists. Redirect to page 404 if not
     if (!($this->view->product = $product = PProductMain::findFirst($product_id))) {
         return $this->response->redirect('route404');
     }
     // Currency rate for selected currency
     $this->view->curr_rate = $curr_rate = PCrosscurrency::findFirst("title='{$this->currency}'")->currencyrate;
     // Delivery
     $expected_delivery = $product->oneProductTime + 25;
     $this->view->expected_delivery = date("d.m.Y", strtotime("now + {$expected_delivery} days"));
     //        $this->view->delivery = $delivery = $this->prodInfoService->deliveryCost($product, $delivery_zone);
     // List of categories to which the product belongs to
     $cat_tree = PCategory::getProductCatTree($product_id, $this->lang)->toArray();
     $cats = [];
     foreach ($cat_tree as $cat) {
         $cats[] = ['title' => $cat['title0'], 'catid' => $cat['catid0'], 'uri' => $cat['uri0']];
         $cats[] = ['title' => $cat['title1'], 'catid' => $cat['catid1'], 'uri' => $cat['uri1']];
         if (isset($cat['title2'])) {
             $cats[] = ['title' => $cat['title2'], 'catid' => $cat['catid2'], 'uri' => $cat['uri2']];
         }
         break;
     }
     $this->view->categories = $cats;
     // More from maker
     $params = ['index' => 'mhdev_' . $lang, 'type' => 'products', 'body' => ['query' => ['function_score' => ['query' => ['match' => ['maker_id' => $product->maker_id]], 'random_score' => new stdClass()]], 'size' => 6]];
     $this->view->maker_products = $this->elasticsearch->search($params)['hits']['hits'];
     // Most saleable
     $params = ['index' => 'mhdev_' . $lang, 'type' => 'products', 'body' => ['size' => 6, 'sort' => ['rating' => ['order' => 'desc']]]];
     $this->view->most_saleable = $this->elasticsearch->search($params)['hits']['hits'];
     $this->view->productId = "/" . $product_id;
     // Discount rate
     $this->view->discount = isset($product->productdiscount) ? $product->productdiscount : null;
     // URL of the page
     $this->view->current_url = $current_url = $this->request->getScheme() . '://' . $this->request->getHttpHost() . $this->request->getURI();
     // Shortened URL (goo.gl)
     $this->view->short_url = $this->prodInfoService->shortUrl($current_url);
     // Product title in respective language
     $this->view->prod_title = $product->getsingleInfo("lang='{$lang}'")->title;
     // Product availability (hold=1)
     $this->view->is_available = $product->hold == 1;
     //---------------------------------------------------------
     $router = $this->di['router'];
     $router->handle();
     //        var_dump($router->getMatchedRoute()->getpaths());
     $routeName = $router->getMatchedRoute()->getname();
     //        $langsAct = PLangs::find(["act=1 AND alias != '{$lang}'", 'order' => 'id']);
     $catUrls = PProdInfo::find("product_id={$product_id} AND coder_status=5 AND lang != '{$lang}'");
     $langsUrls = [];
     foreach ($catUrls as $l) {
         $langsUrls[$l->lang] = $this->url->get(array('for' => $routeName, 'lang' => $l->lang, 'product_id' => $product_id, 'params' => $l->url . '.html'));
     }
     $this->view->langs = $langsUrls;
     //---------------------------------------------------------
 }
Ejemplo n.º 2
0
 public function productsAction()
 {
     $request = $this->request;
     $persistent = $this->persistent;
     // Reset
     $reset = $this->request->getQuery('reset', 'int');
     if (isset($reset)) {
         $persistent->productsParams = null;
     }
     // Persistent parameters
     if (!is_array($persistent->productsParams)) {
         $persistent->productsParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'id ASC'], 'sort' => ['page' => 1, 'perpage' => 50]];
     }
     $parameters = $persistent->productsParams;
     $parameters['sort']['perpage'] = 50;
     $parameters['sort']['page'] = 1;
     if ($request->getQuery('page', 'int')) {
         $parameters['sort']['page'] = $request->getQuery('page', 'int');
     }
     if ($request->getQuery('perpage', 'int')) {
         $parameters['sort']['perpage'] = $request->getQuery('perpage', 'int');
     }
     // ----------------------------------------
     // Search
     if ($request->isPost()) {
         $parameters['search_cat'] = null;
         $parameters['search_virtcat'] = null;
         $parameters['search_maker'] = null;
         $parameters['search_material'] = null;
         $parameters['search_hold'] = null;
         $parameters['search_id'] = null;
         // Category
         if (!empty($_POST['search_cat'])) {
             $search_cat_get = $request->getPost('search_cat', 'int');
             $parameters['search_cat'] = $search_cat_get;
             $search_cats = PCategory::getCatTree($search_cat_get);
             $search_cat = " AND category_id IN ({$search_cats})";
         } else {
             $search_cat = null;
         }
         // Virtual category
         if (!empty($_POST['search_virtcat'])) {
             $search_virtcat_get = $request->getPost('search_virtcat', 'int');
             $parameters['search_virtcat'] = $search_virtcat_get;
             $search_virtcat = " AND tmaterial_id = {$search_virtcat_get}";
         } else {
             $search_virtcat = null;
         }
         // Maker
         if (!empty($_POST['search_maker'])) {
             $search_maker_get = $request->getPost('search_maker', 'int');
             $parameters['search_maker'] = $search_maker_get;
             $search_maker = " AND maker_id = {$search_maker_get}";
         } else {
             $search_maker = null;
         }
         // Material
         if (!empty($_POST['search_material'])) {
             $search_material_get = $request->getPost('search_material', 'int');
             $parameters['search_material'] = $search_material_get;
             $search_material = " AND cmaterial_id = {$search_material_get}";
         } else {
             $search_material = null;
         }
         // Hold
         if (!empty($_POST['search_hold'])) {
             $search_hold_get = $request->getPost('search_hold', 'int');
             $parameters['search_hold'] = $search_hold_get;
             $search_hold = $search_hold_get == 1 ? " AND hold = 1" : " AND hold = 0";
         } else {
             $search_hold = null;
         }
         // ID
         if (!empty($_POST['search_id'])) {
             $parameters['search_id'] = $request->getPost('search_id', 'string');
             $search_id_get = preg_split('/[,\\s]/', $request->getPost('search_id', 'string'), null, PREG_SPLIT_NO_EMPTY);
             $search_id = join(', ', $search_id_get);
             $search_id = " AND id IN ({$search_id})";
         } else {
             $search_id = null;
         }
         // Search parameters
         $parameters['qry'] = ['conditions' => "id IS NOT NULL\n                    {$search_cat}\n                    {$search_virtcat}\n                    {$search_maker}\n                    {$search_material}\n                    {$search_hold}\n                    {$search_id}"];
     }
     // Other parameters
     $parameters['query_count'] = PProductMain::count($parameters['qry']);
     $parameters['qry']['order'] = "id ASC";
     $parameters['qry']['limit'] = 10000;
     $persistent->productsParams = $parameters;
     //        var_dump($parameters);
     // Find all placements that correspond to set parameters
     $products = PProductMain::find($parameters['qry']);
     // Paginator
     $paginator = new Paginator(["data" => $products, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]);
     $this->view->page = $paginator->getPaginate();
     // Set selected search values
     $this->view->selected_cat = isset($parameters['search_cat']) && !empty($parameters['search_cat']) ? $parameters['search_cat'] : null;
     $this->view->selected_virtcat = isset($parameters['search_virtcat']) && !empty($parameters['search_virtcat']) ? $parameters['search_virtcat'] : null;
     $this->view->selected_maker = isset($parameters['search_maker']) && !empty($parameters['search_maker']) ? $parameters['search_maker'] : null;
     $this->view->selected_material = isset($parameters['search_material']) && !empty($parameters['search_material']) ? $parameters['search_material'] : null;
     $this->view->selected_hold = isset($parameters['search_hold']) && !empty($parameters['search_hold']) ? $parameters['search_hold'] : null;
     $this->view->selected_id = isset($parameters['search_id']) && !empty($parameters['search_id']) ? $parameters['search_id'] : null;
     // Products count (overall or filtered)
     $this->view->products_count = $parameters['query_count'];
     // All categories
     $this->view->cats_list = PCategory::getCatList();
     // All virtual categories
     $virtcats = PCategoryGroup::find(['order' => 'title ASC']);
     foreach ($virtcats as $virtcat) {
         $virtcats_array[$virtcat->id] = $virtcat->title;
     }
     $this->view->virtcats_list = $virtcats_array;
     // All makers
     //        $makers = PMaker::find(["name IS NOT NULL AND isseller=1 AND approved=1 AND banned=0", 'order' => 'name ASC']);
     $makers = PMaker::find(["name IS NOT NULL AND isseller=1", 'order' => 'name ASC']);
     foreach ($makers as $maker) {
         $makers_array[$maker->id] = $maker->name;
     }
     $this->view->makers_list = $makers_array;
     // All materials
     $materials = PProdMaterial::find(['order' => 'title ASC']);
     foreach ($materials as $material) {
         $materials_array[$material->id] = $material->title;
     }
     $this->view->materials_list = $materials_array;
     // Langs stat
     $langs = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']);
     foreach ($langs as $lang) {
         $langs_stat[$lang->lang] = $lang->rowcount;
     }
     $this->view->langs_stat = $langs_stat;
     // Check if user can put products on hold
     $this->view->can_hold = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=5 OR role_id=1000)");
 }
Ejemplo n.º 3
0
 public function removeAction()
 {
     $this->view->disable();
     if ($this->request->isPost()) {
         $category_id = $this->request->get('category_id');
     }
     $status = 1;
     // Cannot delete a category that has children
     if ($has_children = PCategory::count("_parent={$category_id}")) {
         $status = 0;
     }
     if ($cats = PCategory::find("category_id={$category_id}")) {
         foreach ($cats as $cat) {
             if (!$cat->delete()) {
                 $status = 0;
             }
         }
     }
     echo $status;
 }
Ejemplo n.º 4
-1
 /**
  * Export selected category in Excel
  *
  * @param $category
  * @param $lang
  * @param $currency
  * @param $location
  */
 public function exportAction($category, $lang, $currency, $location)
 {
     $this->view->disable();
     $cats = PCategory::getCatTree($category, $lang);
     $currency = strtoupper($currency);
     $rate = PCrosscurrency::findFirst("title='{$currency}'")->currencyrate;
     $prods = PProductMain::find(["hold = 0\n            AND notforsale = 0\n            AND category_id IN ({$cats})"]);
     //        var_dump($prods->toArray());
     // Create files directory if it doesn't exist
     if (!file_exists(ROOT . "/public/files")) {
         mkdir(ROOT . "/public/files", 0777);
     }
     $rnd = $currency == 'UAH' || $currency == 'RUB' ? 0 : 2;
     $list = [];
     $list[] = ['ID', 'Название', "Цена, {$currency}", "Доставка, {$currency}", 'URL'];
     $i = 1;
     foreach ($prods as $prod) {
         $list[$i] = [$prod->id, htmlspecialchars_decode($prod->getsingleInfo("lang='{$lang}'")->title), round($prod->priceUSD * $rate, $rnd), $this->unitConvert->deliveryCost($prod, $location) * $rate, "https://madeheart.com/{$lang}/{$prod->id}/" . htmlspecialchars_decode($prod->getsingleInfo("lang='{$lang}'")->url) . ".html"];
         $i++;
     }
     //        var_dump($list);
     $random = rand(111111, 999999);
     $csv_file = "files/csv_{$random}.csv";
     $excel_file = "files/excel_{$random}.xls";
     $csv = fopen($csv_file, 'w');
     foreach ($list as $item) {
         fputcsv($csv, $item);
     }
     fclose($csv);
     $excel = new SimpleExcel('csv');
     $excel->parser->loadFile($csv_file);
     $excel->convertTo('xml');
     $excel->writer->saveFile('file', $excel_file);
     readfile($excel_file);
     header('Content-Disposition: attachment; filename=list.xls');
     unlink($csv_file);
     unlink($excel_file);
 }