/**
  * @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;
     //---------------------------------------------------------
 }
 /**
  * Save the order of currencies on the site
  */
 public function saveSiteOrderAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         $status = 1;
         $order = $this->request->get('order');
         foreach ($order as $pos => $title) {
             $crosscurr = PCrosscurrency::findFirst("title='{$title}'");
             $crosscurr->siteswitcher = $pos;
             if (!$crosscurr->save()) {
                 $status = 0;
             }
         }
         if ($status == 1) {
             $this->flash->success("Порядок сохранен!");
             $this->modelService->setStat('currency_manipulation', 'currencyrates', 'ru', 0, null, json_encode(['action' => 'currencies order on site saved', 'order' => $order]));
         }
         echo $status;
     }
 }
 /**
  * Makers list
  */
 public function indexAction()
 {
     $request = $this->request;
     $persistent = $this->persistent;
     // Reset
     $reset = $this->request->getQuery('reset', 'int');
     if (isset($reset)) {
         $persistent->makersParams = null;
     }
     // Persistent parameters
     if (!is_array($persistent->makersParams)) {
         $persistent->makersParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'updated DESC'], 'sort' => ['page' => 1, 'perpage' => 50]];
     }
     $parameters = $persistent->makersParams;
     $parameters['sort']['perpage'] = isset($parameters['sort']['perpage']) ? $parameters['sort']['perpage'] : 50;
     $parameters['sort']['page'] = isset($parameters['sort']['page']) ? $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_region'] = null;
         $parameters['search_approved'] = null;
         // Placer
         if (!empty($_POST['search_region'])) {
             $search_region_get = $request->getPost('search_region', 'int');
             $parameters['search_region'] = $search_region_get;
             $search_region = " AND geo_id = {$search_region_get}";
         } else {
             $search_region = null;
         }
         // Name or ID
         if (!empty($_POST['search_name'])) {
             $search_name_get = $request->getPost('search_name', 'string');
             if (preg_match('/^[0-9,\\s]+$/', $request->getPost('search_name', 'string'))) {
                 $search_split = preg_split('/[,\\s]/', $search_name_get, 0, PREG_SPLIT_NO_EMPTY);
                 $search_name = implode(', ', $search_split);
                 $search_name = " AND id IN ({$search_name})";
             } else {
                 $search_name = " AND name LIKE '%{$search_name_get}%'";
             }
         } else {
             $search_name_get = null;
             $search_name = null;
         }
         // Email
         if (!empty($_POST['search_email'])) {
             $search_email_get = $request->getPost('search_email', 'string');
             $search_email = " AND email LIKE '%{$search_email_get}%'";
         } else {
             $search_email_get = null;
             $search_email = null;
         }
         // Phone
         if (!empty($_POST['search_phone'])) {
             $search_phone_get = $request->getPost('search_phone', 'string');
             $search_phone = " AND phone LIKE '%{$search_phone_get}%' OR phone2 LIKE '%{$search_phone_get}%'";
         } else {
             $search_phone_get = null;
             $search_phone = null;
         }
         // Approved status
         if (!empty($_POST['search_approved'])) {
             $search_approved_get = $request->getPost('search_approved', 'int');
             $parameters['search_approved'] = $search_approved_get;
             $search_approved = " AND approved = {$search_approved_get}";
         } else {
             $search_approved = null;
         }
         // Search parameters
         $parameters['qry'] = ['conditions' => "id IS NOT NULL\n                    {$search_region}\n                    {$search_name}\n                    {$search_email}\n                    {$search_phone}\n                    {$search_approved}"];
     }
     // Other parameters
     $parameters['count'] = PMaker::count($parameters['qry']);
     $parameters['qry']['order'] = "updated DESC";
     $parameters['qry']['limit'] = 10000;
     $persistent->makersParams = $parameters;
     //        var_dump($parameters);
     $makers = PMaker::find($parameters['qry']);
     // Paginator
     $paginator = new Paginator(["data" => $makers, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]);
     $this->view->page = $paginator->getPaginate();
     // Set selected search values
     $this->view->selected_region = isset($parameters['search_region']) && !empty($parameters['search_region']) ? $parameters['search_region'] : null;
     $this->view->selected_approved = isset($parameters['search_approved']) && !empty($parameters['search_approved']) ? $parameters['search_approved'] : null;
     $this->view->makers_count = $parameters['count'];
     // All regions
     $this->view->regions_list = array_column(Geo::find(['order' => 'title ASC'])->toArray(), 'title', 'id');
     // Currencies
     $currencies_array = array_column(PCrosscurrency::find()->toArray(), 'title', 'title');
     $this->view->currencies_list = ['UAH' => $currencies_array['UAH']] + $currencies_array;
     // Countries
     $countries_array = array_column(Countries::find("active=1")->toArray(), 'title', 'id');
     $ukraine = array_search('Украина', $countries_array);
     $this->view->countries_list = [$ukraine => $countries_array[$ukraine]] + $countries_array;
     $this->view->users_list = Accounts::getUsersByRole(['researcher', 'mobilegroup'], false, 'name ASC');
     $this->view->can_edit = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=991 OR role_id=5)");
 }
Example #4
0
 public function autoplaceAction($seller_id = null, $product_id = null)
 {
     // Find languages for a marketplace
     $seller = Marketseller::findFirst($seller_id);
     $langs = $seller->Marketplace->prefs;
     $langs = preg_split('/[,\\s]/', $langs, 0, PREG_SPLIT_NO_EMPTY);
     $products = [];
     foreach ($langs as $lang) {
         // Check for placement
         if (!($placement = MPlacement::findFirst("marketseller_id={$seller_id} AND product_id={$product_id} AND langcode='{$lang}' AND (active=1 OR active IS NULL)"))) {
             // Check for product existence
             if ($prod = PSelectionSeller::findFirst("id={$product_id} AND lang='{$lang}' AND tmaterial_id={$seller->tmaterial_id} AND hold=0")) {
                 $products[$lang] = $prod;
             }
             // Set one product to represent product information
             if (!isset($product_info) and isset($products[$lang])) {
                 $product_info = $products[$lang];
             }
         }
     }
     if (empty($products)) {
         $this->flash->error("Все товары размещены!");
         return $this->response->redirect("seller/id/{$seller_id}/all");
     }
     $this->view->products = $products;
     $this->view->prod = $product_info;
     $this->view->seller_id = $seller_id;
     $this->view->crosscurr = array_column(PCrosscurrency::find()->toArray(), 'currencyrate', 'title');
     $this->view->delivery_zones = [0 => 'Восточная Азия, Африка, Южная и Центральная Америка', 1 => 'Северная Америка', 2 => 'Россия, Европа, Центральная Азия и Ближний Восток', 3 => 'Австралия и Океания'];
     $qrcodeimg = PProductMain::findFirst("id={$product_id}")->QRcode;
     $this->view->qrcodeimg = $qrcodeimg ? $qrcodeimg : null;
     $this->view->placed_today = $this->modelService->getStat('done', 'seller', 'all', 'day');
     $this->view->placed_month = $this->modelService->getStat('done', 'seller', 'all', 'month');
 }
 public function saveBulkAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         $status = 1;
         $list_of_ids = $this->request->get('list');
         $input = $this->request->get('input');
         $pernum = $this->request->get('pernum');
         $curr = $this->request->get('curr');
         $list_of_ids = json_decode($list_of_ids, true);
         $curr_rate = PCrosscurrency::findFirst("title='{$curr}'")->currencyrate;
         foreach ($list_of_ids as $id) {
             $products = PProductMain::find("id={$id} OR parent={$id}");
             foreach ($products as $product) {
                 $info = "{$product->oneProductPrice} {$product->holdpriceusd} {$product->priceUSD}";
                 if ($pernum == 'number') {
                     // Maker price in maker currency
                     $new_maker_price = round($product->oneProductPrice + $input);
                     // Maker price USD
                     $new_maker_price_usd = round($new_maker_price / $curr_rate, 2);
                     // Export price USD
                     $new_export_price_usd = $this->modelService->calcProductPrice($new_maker_price_usd);
                 } elseif ($pernum == 'percent') {
                     // Maker price in maker currency
                     $new_maker_price = round($product->oneProductPrice + $product->oneProductPrice / 100 * $input);
                     // Maker price USD
                     $new_maker_price_usd = round($new_maker_price / $curr_rate, 2);
                     // Export price USD
                     $new_export_price_usd = $this->modelService->calcProductPrice($new_maker_price_usd);
                 }
                 // Save new prices
                 $product->oneProductPrice = $new_maker_price;
                 $product->holdpriceusd = $new_maker_price_usd;
                 $product->priceUSD = $new_export_price_usd;
                 if (!$product->save()) {
                     $status = 0;
                 } else {
                     $this->modelService->setStat('price_changed', 'priceMaker', 'ru', $product->id, null, $info);
                     $this->modelService->syncElastic(['product_id' => $product->id]);
                 }
             }
         }
         $status == 1 ? $this->flash->success('Цены успешно изменены!') : $this->flash->error('Произошла ошибка при изменении цен!');
         echo $status;
     }
 }
Example #6
0
 /**
  * View all orders
  */
 public function indexAction()
 {
     $request = $this->request;
     $response = $this->response;
     $persistent = $this->persistent;
     // Reset
     $reset = $this->request->getQuery('reset', 'int');
     if (isset($reset)) {
         $persistent->searchOrderParams = null;
     }
     // Persistent parameters
     if (!is_array($persistent->searchOrderParams)) {
         $persistent->searchOrderParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'created DESC'], 'sort' => ['page' => 1, 'perpage' => 50, 'sortField' => 'created', 'sortOrder' => 'DESC']];
     }
     $parameters = $persistent->searchOrderParams;
     $parameters['sort']['perpage'] = isset($parameters['sort']['perpage']) ? $parameters['sort']['perpage'] : 50;
     $parameters['sort']['page'] = isset($parameters['sort']['page']) ? $parameters['sort']['page'] : 1;
     if ($request->getQuery('sort', 'string')) {
         $parameters['sort']['sortField'] = $request->getQuery('sort', 'string');
         $parameters['sort']['sortOrder'] = $request->getQuery('order', 'string');
     }
     if ($request->getQuery('page', 'int')) {
         $parameters['sort']['page'] = $request->getQuery('page', 'int');
     }
     if ($request->getQuery('perpage', 'int')) {
         $parameters['sort']['perpage'] = $request->getQuery('perpage', 'int');
     }
     $sortField = $parameters['sort']['sortField'];
     $sortOrder = $parameters['sort']['sortOrder'];
     // If this is a post request
     if ($request->isPost()) {
         $parameters['search_id'] = null;
         $parameters['search_country'] = null;
         $parameters['search_currency'] = null;
         $parameters['search_status'] = null;
         $parameters['search_date_from'] = null;
         $parameters['search_date_to'] = null;
         $parameters['search_active'] = null;
         // ID
         if (!empty($_POST['search_id'])) {
             $search_id_get = $request->getPost('search_id');
             if (preg_match('/^\\d+$/', $search_id_get)) {
                 $search_id = " AND id = {$search_id_get}";
             } elseif (preg_match('/@/', $search_id_get)) {
                 $search_id = " AND email LIKE '%{$search_id_get}%'";
             } else {
                 $search_id = null;
             }
             $parameters['search_id'] = $search_id_get;
         } else {
             $search_id = null;
         }
         // Country
         if (!empty($_POST['search_country'])) {
             $search_country_get = $request->getPost('search_country', 'int');
             $parameters['search_country'] = $search_country_get;
             $search_country = " AND countries_id = {$search_country_get}";
         } else {
             $search_country = null;
         }
         // Currency
         if (!empty($_POST['search_currency'])) {
             $search_currency_get = $request->getPost('search_currency', 'string');
             $parameters['search_currency'] = $search_currency_get;
             $search_currency = " AND currency = '{$search_currency_get}'";
         } else {
             $search_currency = null;
         }
         // Status
         if (!empty($_POST['search_status'])) {
             $search_status_get = $request->getPost('search_status', 'string');
             $parameters['search_status'] = $search_status_get;
             switch ($search_status_get) {
                 case 'y':
                     $search_status = " AND payed = 1";
                     break;
                 case 'n':
                     $search_status = " AND payed = 0";
                     break;
                 case 'c':
                     $search_status = " AND cancelled = 1";
                     break;
             }
         } else {
             $search_status = null;
         }
         // Date from
         if (!empty($_POST['search_date_from'])) {
             $search_date_from_get = strtotime($request->getPost('search_date_from', 'string'));
             $parameters['search_date_from'] = $search_date_from_get;
             $search_date_from = " AND created > {$search_date_from_get}";
         } else {
             $search_date_from = null;
         }
         // Date to
         if (!empty($_POST['search_date_to'])) {
             $search_date_to_get = strtotime($request->getPost('search_date_to', 'string')) + 86399;
             $parameters['search_date_to'] = $search_date_to_get;
             $search_date_to = " AND created < {$search_date_to_get}";
         } else {
             $search_date_to = null;
         }
         // Active
         if (!empty($_POST['search_active'])) {
             $search_active_get = (int) $request->getPost('search_active', 'int');
             $parameters['search_active'] = $search_active_get;
             $search_active = " AND deactivated IS NULL OR deactivated = 0";
         } else {
             $search_active = null;
         }
         // Search parameters
         $parameters['qry'] = ['conditions' => "id IS NOT NULL\n                    {$search_id}\n                    {$search_country}\n                    {$search_currency}\n                    {$search_status}\n                    {$search_date_from}\n                    {$search_date_to}\n                    {$search_active}"];
     }
     // Other parameters
     $parameters['count'] = POrder::count($parameters['qry']);
     $parameters['qry']['order'] = "{$sortField} {$sortOrder}";
     $parameters['qry']['limit'] = 1000;
     $persistent->searchOrderParams = $parameters;
     //        var_dump($parameters);
     // Find all products according to set parameters
     $orders = POrder::find($parameters['qry']);
     // Paginator
     $paginator = new Paginator(["data" => $orders, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]);
     // Sorting and table headers mapping
     $headMapping = ['id' => 'Номер', 'created' => 'Дата', 'firstName' => 'Имя', 'lastName' => 'Фамилия', '__country' => 'Страна', 'price' => 'Сумма', 'currency' => 'Валюта', '__payed' => 'Статус', 'paySystem' => 'Способ оплаты'];
     // Sorting header and order arrow
     $headings = array();
     foreach ($headMapping as $field => $name) {
         $headings[$field] = ['field' => $field, 'name' => $name, 'sort' => $sortField == $field ? $sortOrder == 'desc' ? 'asc' : 'desc' : false, 'arrow' => $sortField == $field ? $sortOrder == 'desc' ? '&nbsp;&#8595;' : '&nbsp;&#8593;' : false];
     }
     $this->view->headings = $headings;
     $this->view->page = $paginator->getPaginate();
     // Show total count
     $this->view->count = $parameters['count'];
     // Set selected search values
     $this->view->selected_id = isset($parameters['search_id']) && !empty($parameters['search_id']) ? $parameters['search_id'] : null;
     $this->view->selected_country = isset($parameters['search_country']) && !empty($parameters['search_country']) ? $parameters['search_country'] : null;
     $this->view->selected_currency = isset($parameters['search_currency']) && !empty($parameters['search_currency']) ? $parameters['search_currency'] : null;
     $this->view->selected_status = isset($parameters['search_status']) && !empty($parameters['search_status']) ? $parameters['search_status'] : null;
     $this->view->selected_date_from = isset($parameters['search_date_from']) && !empty($parameters['search_date_from']) ? $parameters['search_date_from'] : null;
     $this->view->selected_date_to = isset($parameters['search_date_to']) && !empty($parameters['search_date_to']) ? $parameters['search_date_to'] : null;
     $this->view->selected_active = isset($parameters['search_active']) && !empty($parameters['search_active']);
     // List of countries
     $this->view->countries = array_column(Countries::find(['order' => 'title'])->toArray(), 'title', 'id');
     // List of currencies
     $this->view->currencies = array_column(PCrosscurrency::find(['conditions' => 'siteswitcher != 0', 'order' => 'siteswitcher'])->toArray(), 'title', 'title');
 }
Example #7
-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);
 }