Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.71 KB | None | 0 0
  1. /catalog/controller/product/special.php
  2. /catalog/language/YOURLANGUAGE/product/special.php
  3. /catalog/view/theme/YOURTHEME/template/product/special.tpl
  4.  
  5. class ControllerProductNovinki extends Controller {
  6. public function index() {
  7. $this->load->language('product/novinki');
  8.  
  9. $this->load->model('catalog/product');
  10.  
  11. $this->load->model('tool/image');
  12.  
  13. if (isset($this->request->get['sort'])) {
  14. $sort = $this->request->get['sort'];
  15. } else {
  16. $sort = 'p.sort_order';
  17. }
  18.  
  19. if (isset($this->request->get['order'])) {
  20. $order = $this->request->get['order'];
  21. } else {
  22. $order = 'ASC';
  23. }
  24.  
  25. if (isset($this->request->get['page'])) {
  26. $page = $this->request->get['page'];
  27. } else {
  28. $page = 1;
  29. }
  30.  
  31. if (isset($this->request->get['limit'])) {
  32. $limit = (int)$this->request->get['limit'];
  33. } else {
  34. $limit = $this->config->get($this->config->get('config_theme') . '_product_limit');
  35. }
  36.  
  37. $this->document->setTitle($this->language->get('heading_title'));
  38.  
  39. $data['breadcrumbs'] = array();
  40.  
  41. $data['breadcrumbs'][] = array(
  42. 'text' => $this->language->get('text_home'),
  43. 'href' => $this->url->link('common/home')
  44. );
  45.  
  46. $url = '';
  47.  
  48. if (isset($this->request->get['sort'])) {
  49. $url .= '&sort=' . $this->request->get['sort'];
  50. }
  51.  
  52. if (isset($this->request->get['order'])) {
  53. $url .= '&order=' . $this->request->get['order'];
  54. }
  55.  
  56. if (isset($this->request->get['page'])) {
  57. $url .= '&page=' . $this->request->get['page'];
  58. }
  59.  
  60. if (isset($this->request->get['limit'])) {
  61. $url .= '&limit=' . $this->request->get['limit'];
  62. }
  63.  
  64. $data['breadcrumbs'][] = array(
  65. 'text' => $this->language->get('heading_title'),
  66. 'href' => $this->url->link('product/novinki', $url)
  67. );
  68.  
  69. $data['heading_title'] = $this->language->get('heading_title');
  70.  
  71. $data['text_empty'] = $this->language->get('text_empty');
  72. $data['text_quantity'] = $this->language->get('text_quantity');
  73. $data['text_manufacturer'] = $this->language->get('text_manufacturer');
  74. $data['text_model'] = $this->language->get('text_model');
  75. $data['text_price'] = $this->language->get('text_price');
  76. $data['text_tax'] = $this->language->get('text_tax');
  77. $data['text_points'] = $this->language->get('text_points');
  78. $data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  79. $data['text_sort'] = $this->language->get('text_sort');
  80. $data['text_limit'] = $this->language->get('text_limit');
  81.  
  82. $data['button_cart'] = $this->language->get('button_cart');
  83. $data['button_wishlist'] = $this->language->get('button_wishlist');
  84. $data['button_compare'] = $this->language->get('button_compare');
  85. $data['button_list'] = $this->language->get('button_list');
  86. $data['button_grid'] = $this->language->get('button_grid');
  87. $data['button_continue'] = $this->language->get('button_continue');
  88.  
  89. $data['compare'] = $this->url->link('product/compare');
  90.  
  91. $data['products'] = array();
  92.  
  93. $filter_data = array(
  94. 'sort' => $sort,
  95. 'order' => $order,
  96. 'start' => ($page - 1) * $limit,
  97. 'limit' => $limit
  98. );
  99.  
  100. $product_total = $this->model_catalog_product->getTotalProductSpecials($filter_data);
  101.  
  102. $results = $this->model_catalog_product->getLatestProducts($filter_data);
  103.  
  104. foreach ($results as $result) {
  105. if ($result['image']) {
  106. $image = $this->model_tool_image->resize($result['image'], $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
  107. } else {
  108. $image = $this->model_tool_image->resize('placeholder.png', $this->config->get($this->config->get('config_theme') . '_image_product_width'), $this->config->get($this->config->get('config_theme') . '_image_product_height'));
  109. }
  110.  
  111. if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
  112. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
  113. } else {
  114. $price = false;
  115. }
  116.  
  117. if ((float)$result['special']) {
  118. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
  119. } else {
  120. $special = false;
  121. }
  122.  
  123. if ($this->config->get('config_tax')) {
  124. $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
  125. } else {
  126. $tax = false;
  127. }
  128.  
  129. if ($this->config->get('config_review_status')) {
  130. $rating = (int)$result['rating'];
  131. } else {
  132. $rating = false;
  133. }
  134.  
  135. $data['products'][] = array(
  136. 'product_id' => $result['product_id'],
  137. 'thumb' => $image,
  138. 'name' => $result['name'],
  139. 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
  140. 'price' => $price,
  141. 'special' => $special,
  142. 'tax' => $tax,
  143. 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
  144. 'rating' => $result['rating'],
  145. 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url)
  146. );
  147. }
  148.  
  149. $url = '';
  150.  
  151. if (isset($this->request->get['limit'])) {
  152. $url .= '&limit=' . $this->request->get['limit'];
  153. }
  154.  
  155. $data['sorts'] = array();
  156.  
  157. $data['sorts'][] = array(
  158. 'text' => $this->language->get('text_default'),
  159. 'value' => 'p.sort_order-ASC',
  160. 'href' => $this->url->link('product/novinki', 'sort=p.sort_order&order=ASC' . $url)
  161. );
  162.  
  163. $data['sorts'][] = array(
  164. 'text' => $this->language->get('text_name_asc'),
  165. 'value' => 'pd.name-ASC',
  166. 'href' => $this->url->link('product/novinki', 'sort=pd.name&order=ASC' . $url)
  167. );
  168.  
  169. $data['sorts'][] = array(
  170. 'text' => $this->language->get('text_name_desc'),
  171. 'value' => 'pd.name-DESC',
  172. 'href' => $this->url->link('product/novinki', 'sort=pd.name&order=DESC' . $url)
  173. );
  174.  
  175. $data['sorts'][] = array(
  176. 'text' => $this->language->get('text_price_asc'),
  177. 'value' => 'ps.price-ASC',
  178. 'href' => $this->url->link('product/novinki', 'sort=ps.price&order=ASC' . $url)
  179. );
  180.  
  181. $data['sorts'][] = array(
  182. 'text' => $this->language->get('text_price_desc'),
  183. 'value' => 'ps.price-DESC',
  184. 'href' => $this->url->link('product/novinki', 'sort=ps.price&order=DESC' . $url)
  185. );
  186.  
  187. if ($this->config->get('config_review_status')) {
  188. $data['sorts'][] = array(
  189. 'text' => $this->language->get('text_rating_desc'),
  190. 'value' => 'rating-DESC',
  191. 'href' => $this->url->link('product/novinki', 'sort=rating&order=DESC' . $url)
  192. );
  193.  
  194. $data['sorts'][] = array(
  195. 'text' => $this->language->get('text_rating_asc'),
  196. 'value' => 'rating-ASC',
  197. 'href' => $this->url->link('product/novinki', 'sort=rating&order=ASC' . $url)
  198. );
  199. }
  200.  
  201. $data['sorts'][] = array(
  202. 'text' => $this->language->get('text_model_asc'),
  203. 'value' => 'p.model-ASC',
  204. 'href' => $this->url->link('product/novinki', 'sort=p.model&order=ASC' . $url)
  205. );
  206.  
  207. $data['sorts'][] = array(
  208. 'text' => $this->language->get('text_model_desc'),
  209. 'value' => 'p.model-DESC',
  210. 'href' => $this->url->link('product/novinki', 'sort=p.model&order=DESC' . $url)
  211. );
  212.  
  213. $url = '';
  214.  
  215. if (isset($this->request->get['sort'])) {
  216. $url .= '&sort=' . $this->request->get['sort'];
  217. }
  218.  
  219. if (isset($this->request->get['order'])) {
  220. $url .= '&order=' . $this->request->get['order'];
  221. }
  222.  
  223. $data['limits'] = array();
  224.  
  225. $limits = array_unique(array($this->config->get($this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100));
  226.  
  227. sort($limits);
  228.  
  229. foreach($limits as $value) {
  230. $data['limits'][] = array(
  231. 'text' => $value,
  232. 'value' => $value,
  233. 'href' => $this->url->link('product/novinki', $url . '&limit=' . $value)
  234. );
  235. }
  236.  
  237. $url = '';
  238.  
  239. if (isset($this->request->get['sort'])) {
  240. $url .= '&sort=' . $this->request->get['sort'];
  241. }
  242.  
  243. if (isset($this->request->get['order'])) {
  244. $url .= '&order=' . $this->request->get['order'];
  245. }
  246.  
  247. if (isset($this->request->get['limit'])) {
  248. $url .= '&limit=' . $this->request->get['limit'];
  249. }
  250.  
  251. $pagination = new Pagination();
  252. $pagination->total = $product_total;
  253. $pagination->page = $page;
  254. $pagination->limit = $limit;
  255. $pagination->url = $this->url->link('product/novinki', $url . '&page={page}');
  256.  
  257. $data['pagination'] = $pagination->render();
  258.  
  259. $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($product_total - $limit)) ? $product_total : ((($page - 1) * $limit) + $limit), $product_total, ceil($product_total / $limit));
  260.  
  261. // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
  262. if ($page == 1) {
  263. $this->document->addLink($this->url->link('product/novinki', '', true), 'canonical');
  264. } elseif ($page == 2) {
  265. $this->document->addLink($this->url->link('product/novinki', '', true), 'prev');
  266. } else {я
  267. $this->document->addLink($this->url->link('product/novinki', 'page='. ($page - 1), true), 'prev');
  268. }
  269.  
  270. if ($limit && ceil($product_total / $limit) > $page) {
  271. $this->document->addLink($this->url->link('product/novinki', 'page='. ($page + 1), true), 'next');
  272. }
  273.  
  274. $data['sort'] = $sort;
  275. $data['order'] = $order;
  276. $data['limit'] = $limit;
  277.  
  278. $data['continue'] = $this->url->link('common/home');
  279.  
  280. $data['column_left'] = $this->load->controller('common/column_left');
  281. $data['column_right'] = $this->load->controller('common/column_right');
  282. $data['content_top'] = $this->load->controller('common/content_top');
  283. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  284. $data['footer'] = $this->load->controller('common/footer');
  285. $data['header'] = $this->load->controller('common/header');
  286.  
  287. $this->response->setOutput($this->load->view('product/novinki', $data));
  288. }
  289. }
  290.  
  291. $sort_data = array(
  292. 'pd.name',
  293. 'p.model',
  294. 'p.quantity',
  295. 'p.price',
  296. 'rating',
  297. 'p.sort_order',
  298. 'p.date_added'
  299. );
  300.  
  301. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  302. if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
  303. $sql .= " ORDER BY p.sort_order ASC, LCASE(" . $data['sort'] . ")";
  304. } elseif ($data['sort'] == 'p.price') {
  305. $sql .= " ORDER BY (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
  306. } elseif ($data['sort'] == 'p.date_added') {
  307. $sql .= " ORDER BY p.date_added";
  308. } else {
  309. $sql .= " ORDER BY p.sort_order ASC, " . $data['sort'];
  310. }
  311. } else {
  312. $sql .= " ORDER BY p.sort_order";
  313. };
  314.  
  315. $sort_data = array(
  316. 'pd.name',
  317. 'p.model',
  318. 'p.quantity',
  319. 'p.price',
  320. 'rating',
  321. 'p.sort_order',
  322. );
  323.  
  324. $sql = " ORDER BY p.date_added DESC, ";
  325. // добавляется мультисорт с обязательной сортировкой по дате (ORDER BY далее режутся)
  326.  
  327. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  328. if ($data['sort'] == 'pd.name' || $data['sort'] == 'p.model') {
  329. $sql .= " p.sort_order ASC, LCASE(" . $data['sort'] . ")";
  330. } elseif ($data['sort'] == 'p.price') {
  331. $sql .= " (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END)";
  332. } elseif ($data['sort'] == 'p.date_added') {
  333. $sql .= " p.date_added";
  334. } else {
  335. $sql .= " p.sort_order ASC, " . $data['sort'];
  336. }
  337. } else {
  338. $sql .= " p.sort_order";
  339. }
  340.  
  341. $results = $this->model_catalog_product->getLatestProducts($filter_data);
  342.  
  343. $results = $this->model_catalog_product->getLatestProductsCategory($filter_data);
  344.  
  345. INSERT INTO `ваш_префикс_url_alias`(`query`, `keyword`) VALUES (`product/novinki`,`novinki`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement