PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/catalog/controller/product/special.php

https://gitlab.com/shapcy/opencart
PHP | 286 lines | 224 code | 61 blank | 1 comment | 36 complexity | 144764a303226ad97ae86c4abcc38d8a MD5 | raw file
  1. <?php
  2. class ControllerProductSpecial extends Controller {
  3. public function index() {
  4. $this->load->language('product/special');
  5. $this->load->model('catalog/product');
  6. $this->load->model('tool/image');
  7. if (isset($this->request->get['sort'])) {
  8. $sort = $this->request->get['sort'];
  9. } else {
  10. $sort = 'p.sort_order';
  11. }
  12. if (isset($this->request->get['order'])) {
  13. $order = $this->request->get['order'];
  14. } else {
  15. $order = 'ASC';
  16. }
  17. if (isset($this->request->get['page'])) {
  18. $page = $this->request->get['page'];
  19. } else {
  20. $page = 1;
  21. }
  22. if (isset($this->request->get['limit'])) {
  23. $limit = (int)$this->request->get['limit'];
  24. } else {
  25. $limit = $this->config->get($this->config->get('config_theme') . '_product_limit');
  26. }
  27. $this->document->setTitle($this->language->get('heading_title'));
  28. $data['breadcrumbs'] = array();
  29. $data['breadcrumbs'][] = array(
  30. 'text' => $this->language->get('text_home'),
  31. 'href' => $this->url->link('common/home')
  32. );
  33. $url = '';
  34. if (isset($this->request->get['sort'])) {
  35. $url .= '&sort=' . $this->request->get['sort'];
  36. }
  37. if (isset($this->request->get['order'])) {
  38. $url .= '&order=' . $this->request->get['order'];
  39. }
  40. if (isset($this->request->get['page'])) {
  41. $url .= '&page=' . $this->request->get['page'];
  42. }
  43. if (isset($this->request->get['limit'])) {
  44. $url .= '&limit=' . $this->request->get['limit'];
  45. }
  46. $data['breadcrumbs'][] = array(
  47. 'text' => $this->language->get('heading_title'),
  48. 'href' => $this->url->link('product/special', $url)
  49. );
  50. $data['heading_title'] = $this->language->get('heading_title');
  51. $data['text_empty'] = $this->language->get('text_empty');
  52. $data['text_quantity'] = $this->language->get('text_quantity');
  53. $data['text_manufacturer'] = $this->language->get('text_manufacturer');
  54. $data['text_model'] = $this->language->get('text_model');
  55. $data['text_price'] = $this->language->get('text_price');
  56. $data['text_tax'] = $this->language->get('text_tax');
  57. $data['text_points'] = $this->language->get('text_points');
  58. $data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  59. $data['text_sort'] = $this->language->get('text_sort');
  60. $data['text_limit'] = $this->language->get('text_limit');
  61. $data['button_cart'] = $this->language->get('button_cart');
  62. $data['button_wishlist'] = $this->language->get('button_wishlist');
  63. $data['button_compare'] = $this->language->get('button_compare');
  64. $data['button_list'] = $this->language->get('button_list');
  65. $data['button_grid'] = $this->language->get('button_grid');
  66. $data['button_continue'] = $this->language->get('button_continue');
  67. $data['compare'] = $this->url->link('product/compare');
  68. $data['products'] = array();
  69. $filter_data = array(
  70. 'sort' => $sort,
  71. 'order' => $order,
  72. 'start' => ($page - 1) * $limit,
  73. 'limit' => $limit
  74. );
  75. $product_total = $this->model_catalog_product->getTotalProductSpecials();
  76. $results = $this->model_catalog_product->getProductSpecials($filter_data);
  77. foreach ($results as $result) {
  78. if ($result['image']) {
  79. $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'));
  80. } else {
  81. $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'));
  82. }
  83. if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
  84. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
  85. } else {
  86. $price = false;
  87. }
  88. if ((float)$result['special']) {
  89. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
  90. } else {
  91. $special = false;
  92. }
  93. if ($this->config->get('config_tax')) {
  94. $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
  95. } else {
  96. $tax = false;
  97. }
  98. if ($this->config->get('config_review_status')) {
  99. $rating = (int)$result['rating'];
  100. } else {
  101. $rating = false;
  102. }
  103. $data['products'][] = array(
  104. 'product_id' => $result['product_id'],
  105. 'thumb' => $image,
  106. 'name' => $result['name'],
  107. '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')) . '..',
  108. 'price' => $price,
  109. 'special' => $special,
  110. 'tax' => $tax,
  111. 'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
  112. 'rating' => $result['rating'],
  113. 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url)
  114. );
  115. }
  116. $url = '';
  117. if (isset($this->request->get['limit'])) {
  118. $url .= '&limit=' . $this->request->get['limit'];
  119. }
  120. $data['sorts'] = array();
  121. $data['sorts'][] = array(
  122. 'text' => $this->language->get('text_default'),
  123. 'value' => 'p.sort_order-ASC',
  124. 'href' => $this->url->link('product/special', 'sort=p.sort_order&order=ASC' . $url)
  125. );
  126. $data['sorts'][] = array(
  127. 'text' => $this->language->get('text_name_asc'),
  128. 'value' => 'pd.name-ASC',
  129. 'href' => $this->url->link('product/special', 'sort=pd.name&order=ASC' . $url)
  130. );
  131. $data['sorts'][] = array(
  132. 'text' => $this->language->get('text_name_desc'),
  133. 'value' => 'pd.name-DESC',
  134. 'href' => $this->url->link('product/special', 'sort=pd.name&order=DESC' . $url)
  135. );
  136. $data['sorts'][] = array(
  137. 'text' => $this->language->get('text_price_asc'),
  138. 'value' => 'ps.price-ASC',
  139. 'href' => $this->url->link('product/special', 'sort=ps.price&order=ASC' . $url)
  140. );
  141. $data['sorts'][] = array(
  142. 'text' => $this->language->get('text_price_desc'),
  143. 'value' => 'ps.price-DESC',
  144. 'href' => $this->url->link('product/special', 'sort=ps.price&order=DESC' . $url)
  145. );
  146. if ($this->config->get('config_review_status')) {
  147. $data['sorts'][] = array(
  148. 'text' => $this->language->get('text_rating_desc'),
  149. 'value' => 'rating-DESC',
  150. 'href' => $this->url->link('product/special', 'sort=rating&order=DESC' . $url)
  151. );
  152. $data['sorts'][] = array(
  153. 'text' => $this->language->get('text_rating_asc'),
  154. 'value' => 'rating-ASC',
  155. 'href' => $this->url->link('product/special', 'sort=rating&order=ASC' . $url)
  156. );
  157. }
  158. $data['sorts'][] = array(
  159. 'text' => $this->language->get('text_model_asc'),
  160. 'value' => 'p.model-ASC',
  161. 'href' => $this->url->link('product/special', 'sort=p.model&order=ASC' . $url)
  162. );
  163. $data['sorts'][] = array(
  164. 'text' => $this->language->get('text_model_desc'),
  165. 'value' => 'p.model-DESC',
  166. 'href' => $this->url->link('product/special', 'sort=p.model&order=DESC' . $url)
  167. );
  168. $url = '';
  169. if (isset($this->request->get['sort'])) {
  170. $url .= '&sort=' . $this->request->get['sort'];
  171. }
  172. if (isset($this->request->get['order'])) {
  173. $url .= '&order=' . $this->request->get['order'];
  174. }
  175. $data['limits'] = array();
  176. $limits = array_unique(array($this->config->get($this->config->get('config_theme') . '_product_limit'), 25, 50, 75, 100));
  177. sort($limits);
  178. foreach($limits as $value) {
  179. $data['limits'][] = array(
  180. 'text' => $value,
  181. 'value' => $value,
  182. 'href' => $this->url->link('product/special', $url . '&limit=' . $value)
  183. );
  184. }
  185. $url = '';
  186. if (isset($this->request->get['sort'])) {
  187. $url .= '&sort=' . $this->request->get['sort'];
  188. }
  189. if (isset($this->request->get['order'])) {
  190. $url .= '&order=' . $this->request->get['order'];
  191. }
  192. if (isset($this->request->get['limit'])) {
  193. $url .= '&limit=' . $this->request->get['limit'];
  194. }
  195. $pagination = new Pagination();
  196. $pagination->total = $product_total;
  197. $pagination->page = $page;
  198. $pagination->limit = $limit;
  199. $pagination->url = $this->url->link('product/special', $url . '&page={page}');
  200. $data['pagination'] = $pagination->render();
  201. $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));
  202. // http://googlewebmastercentral.blogspot.com/2011/09/pagination-with-relnext-and-relprev.html
  203. if ($page == 1) {
  204. $this->document->addLink($this->url->link('product/special', '', true), 'canonical');
  205. } elseif ($page == 2) {
  206. $this->document->addLink($this->url->link('product/special', '', true), 'prev');
  207. } else {
  208. $this->document->addLink($this->url->link('product/special', 'page='. ($page - 1), true), 'prev');
  209. }
  210. if ($limit && ceil($product_total / $limit) > $page) {
  211. $this->document->addLink($this->url->link('product/special', 'page='. ($page + 1), true), 'next');
  212. }
  213. $data['sort'] = $sort;
  214. $data['order'] = $order;
  215. $data['limit'] = $limit;
  216. $data['continue'] = $this->url->link('common/home');
  217. $data['column_left'] = $this->load->controller('common/column_left');
  218. $data['column_right'] = $this->load->controller('common/column_right');
  219. $data['content_top'] = $this->load->controller('common/content_top');
  220. $data['content_bottom'] = $this->load->controller('common/content_bottom');
  221. $data['footer'] = $this->load->controller('common/footer');
  222. $data['header'] = $this->load->controller('common/header');
  223. $this->response->setOutput($this->load->view('product/special', $data));
  224. }
  225. }