Пример #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;
     //---------------------------------------------------------
 }
Пример #2
0
 public function excelAction($campaign_id = null)
 {
     $this->view->disable();
     //        mb_internal_encoding("Windows-1251");
     //        mb_internal_encoding("ISO-8859-1");
     //        mb_internal_encoding("UTF-8");
     //        mb_http_output('Windows-1251');
     //        mb_http_output('ISO-8859-1');
     //        mb_http_output("UTF-8");
     //        echo mb_internal_encoding();
     //        echo mb_http_output();
     //        $campaign = AdvCampaigns::findFirst($campaign_id);
     //        $campaign_products = AdvProducts::find("campaign_id=$campaign_id");
     //        $curr_rate = PCrosscurrency::findFirst("title='{$campaign->currencyCode}'")->currencyrate;
     //        $show_price_discount = $campaign->showPriceDiscount == 1 ? "<th>Цена со скидкой, {$campaign->currencyCode}</th>" : null;
     //        $show_coeff = $campaign->showCoeff == 1 ? "<th>Цена с наценкой, {$campaign->currencyCode}</th>" : null;
     //        $rnd = $campaign->currencyCode == 'UAH' || $campaign->currencyCode == 'RUB' ? 0 : 2;
     //        $text = "<table border='1'><tr><th>ID</th><th>Название</th><th>Цена, {$campaign->currencyCode}</th>{$show_price_discount}{$show_coeff}</tr>";
     //        foreach ($campaign_products as $prod) {
     ////            $title = htmlentities($prod->PProductMain->getsingleInfo("lang='{$campaign->langcode}'")->title, ENT_QUOTES);
     ////            $title = $this->enc($title);
     //            $text .= "<tr>";
     //            $text .= "<td>" . $prod->product_id . "</td>";
     ////            $text .= "<td>" . $title . "</td>";
     //            $text .= "<td>" . htmlspecialchars_decode($prod->PProductMain->getsingleInfo("lang='{$campaign->langcode}'")->title) . "</td>";
     //            $text .= "<td>" . round($prod->PProductMain->priceUSD * $curr_rate, $rnd) . "</td>";
     //            if ($campaign->showPriceDiscount == 1) {
     //                $text .= "<td>" . round((($prod->PProductMain->priceUSD - $prod->PProductMain->priceUSD / 100 * $campaign->discount) * $curr_rate), $rnd) . "</td>";
     //            }
     //            if ($campaign->showCoeff == 1) {
     //                $text .= "<td>" . round((($prod->PProductMain->priceUSD * $campaign->coeff) * $curr_rate), $rnd) . "</td>";
     //            }
     //            $text .= "</tr>";
     //        }
     //        $text .= "</table>";
     //        $text = mb_convert_encoding($text, "utf-8", "windows-1251");
     //        $text = mb_convert_encoding($text, "windows-1251", "utf-8");
     //        $text = iconv("ISO-8859-1", "windows-1251", $text);
     //        $text = iconv("utf-8", "windows-1251", $text);
     //        $text = iconv("windows-1251", "utf-8", $text);
     //        echo $text;
     //        $file_name = strtolower(preg_replace('/\s+/', '-',
     //            iconv("UTF-8", "ASCII//TRANSLIT//IGNORE",
     //                transliterator_transliterate('Any-Latin; Latin-ASCII', $campaign->title)
     //            )));
     //        header('Content-Type: text/html; charset=Windows-1251');
     //        header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
     //        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     //        header('Cache-Control: no-store, no-cache, must-revalidate');
     //        header('Cache-Control: post-check=0, pre-check=0', FALSE);
     //        header('Pragma: no-cache');
     //        header('Content-Transfer-Encoding: binary');
     //        header('Content-Disposition: attachment; filename='.$file_name.'.xls');
     //        header('Content-Type: application/vnd.ms-excel; charset=windows-1251');
     //        header('Content-Type: application/x-unknown');
     // Create files directory if it doesn't exist
     if (!file_exists(ROOT . "/public/files")) {
         mkdir(ROOT . "/public/files", 0777);
     }
     $campaign = AdvCampaigns::findFirst($campaign_id);
     $campaign_products = AdvProducts::find("campaign_id={$campaign_id}");
     $curr_rate = PCrosscurrency::findFirst("title='{$campaign->currencyCode}'")->currencyrate;
     $rnd = $campaign->currencyCode == 'UAH' || $campaign->currencyCode == 'RUB' ? 0 : 2;
     $list = [];
     $list[] = ['ID', 'Название', 'Категория 1', 'Категория 2', 'Категория 3', "Цена, {$campaign->currencyCode}"];
     if ($campaign->showMakerPrice == 1) {
         array_push($list[0], "Вход. цена, {$campaign->currencyCode}");
     }
     if ($campaign->showPriceDiscount == 1) {
         array_push($list[0], "Цена со скидкой, {$campaign->currencyCode}");
     }
     if ($campaign->showCoeff == 1) {
         array_push($list[0], "Цена с наценкой, {$campaign->currencyCode}");
     }
     if ($campaign->showMarkup == 1) {
         array_push($list[0], "Mark-up");
     }
     $i = 1;
     foreach ($campaign_products as $prod) {
         if ($prod->PProductMain->hold == 0) {
             $cats = PCategory::getProductCatTree($prod->product_id, $campaign->langcode)->toArray();
             $cat_title0 = isset($cats[0]['title0']) ? $cats[0]['title0'] : $prod->PProductMain->getcategory("lang='{$campaign->langcode}'")->title;
             $cat_title1 = isset($cats[0]['title1']) ? $cats[0]['title1'] : '';
             $cat_title2 = isset($cats[0]['title2']) ? $cats[0]['title2'] : '';
             $list[$i] = [$prod->product_id, htmlspecialchars_decode($prod->PProductMain->getsingleInfo("lang='{$campaign->langcode}'")->title), $cat_title0, $cat_title1, $cat_title2, round($prod->PProductMain->priceUSD * $curr_rate, $rnd)];
             if ($campaign->showMakerPrice == 1) {
                 $holdpriceusd = $prod->PProductMain->holdpriceusd;
                 if (isset($holdpriceusd)) {
                     array_push($list[$i], $holdpriceusd);
                 }
             }
             if ($campaign->showPriceDiscount == 1) {
                 array_push($list[$i], round(($prod->PProductMain->priceUSD - $prod->PProductMain->priceUSD / 100 * $campaign->discount) * $curr_rate, $rnd));
             }
             if ($campaign->showCoeff == 1) {
                 array_push($list[$i], round($prod->PProductMain->oneProductPrice * $campaign->coeff / $prod->PProductMain->maker->currency->currencyrate, $rnd));
             }
             if ($campaign->showMarkup == 1) {
                 if (isset($prod->PProductMain->maker_id) and isset($prod->PProductMain->priceUSD)) {
                     array_push($list[$i], round($prod->PProductMain->priceUSD * $curr_rate / ($prod->PProductMain->oneProductPrice / $prod->PProductMain->maker->currency->currencyrate * $curr_rate), 2));
                 } else {
                     array_push($list[$i], null);
                 }
             }
             $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);
     $file_name = strtolower(preg_replace("/[\\s\\,\\.\\:\\-\\(\\)\\&\\']+/", '_', iconv("UTF-8", "ASCII//TRANSLIT//IGNORE", transliterator_transliterate('Any-Latin; Latin-ASCII', $campaign->title))));
     readfile($excel_file);
     header('Content-Disposition: attachment; filename=' . $file_name . '.xls');
     unlink($csv_file);
     unlink($excel_file);
 }