/** * @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; } }
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; } }
/** * 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); }