/catalog/controller/product/special.php

https://github.com/smadi/arabian-land · PHP · 297 lines · 237 code · 60 blank · 0 comment · 32 complexity · dd8a20c3cc1232d8a34a99a6d403c56f MD5 · raw file

  1. <?php
  2. class ControllerProductSpecial extends Controller {
  3. public function index() {
  4. $this->language->load('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 = $this->request->get['limit'];
  24. } else {
  25. $limit = $this->config->get('config_catalog_limit');
  26. }
  27. $this->document->setTitle($this->language->get('heading_title'));
  28. $this->data['breadcrumbs'] = array();
  29. $this->data['breadcrumbs'][] = array(
  30. 'text' => $this->language->get('text_home'),
  31. 'href' => $this->url->link('common/home'),
  32. 'separator' => false
  33. );
  34. $url = '';
  35. if (isset($this->request->get['sort'])) {
  36. $url .= '&sort=' . $this->request->get['sort'];
  37. }
  38. if (isset($this->request->get['order'])) {
  39. $url .= '&order=' . $this->request->get['order'];
  40. }
  41. if (isset($this->request->get['page'])) {
  42. $url .= '&page=' . $this->request->get['page'];
  43. }
  44. if (isset($this->request->get['limit'])) {
  45. $url .= '&limit=' . $this->request->get['limit'];
  46. }
  47. $this->data['breadcrumbs'][] = array(
  48. 'text' => $this->language->get('heading_title'),
  49. 'href' => $this->url->link('product/special', $url),
  50. 'separator' => $this->language->get('text_separator')
  51. );
  52. $this->data['heading_title'] = $this->language->get('heading_title');
  53. $this->data['text_empty'] = $this->language->get('text_empty');
  54. $this->data['text_quantity'] = $this->language->get('text_quantity');
  55. $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
  56. $this->data['text_model'] = $this->language->get('text_model');
  57. $this->data['text_price'] = $this->language->get('text_price');
  58. $this->data['text_tax'] = $this->language->get('text_tax');
  59. $this->data['text_points'] = $this->language->get('text_points');
  60. $this->data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  61. $this->data['text_display'] = $this->language->get('text_display');
  62. $this->data['text_list'] = $this->language->get('text_list');
  63. $this->data['text_grid'] = $this->language->get('text_grid');
  64. $this->data['text_sort'] = $this->language->get('text_sort');
  65. $this->data['text_limit'] = $this->language->get('text_limit');
  66. $this->data['button_cart'] = $this->language->get('button_cart');
  67. $this->data['button_wishlist'] = $this->language->get('button_wishlist');
  68. $this->data['button_compare'] = $this->language->get('button_compare');
  69. $this->data['compare'] = $this->url->link('product/compare');
  70. $this->data['products'] = array();
  71. $data = array(
  72. 'sort' => $sort,
  73. 'order' => $order,
  74. 'start' => ($page - 1) * $limit,
  75. 'limit' => $limit
  76. );
  77. $product_total = $this->model_catalog_product->getTotalProductSpecials($data);
  78. $results = $this->model_catalog_product->getProductSpecials($data);
  79. foreach ($results as $result) {
  80. if ($result['image']) {
  81. $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  82. } else {
  83. $image = false;
  84. }
  85. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  86. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  87. } else {
  88. $price = false;
  89. }
  90. if ((float)$result['special']) {
  91. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  92. } else {
  93. $special = false;
  94. }
  95. if ($this->config->get('config_tax')) {
  96. $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
  97. } else {
  98. $tax = false;
  99. }
  100. if ($this->config->get('config_review_status')) {
  101. $rating = (int)$result['rating'];
  102. } else {
  103. $rating = false;
  104. }
  105. $this->data['products'][] = array(
  106. 'product_id' => $result['product_id'],
  107. 'thumb' => $image,
  108. 'name' => $result['name'],
  109. 'description' => substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
  110. 'price' => $price,
  111. 'special' => $special,
  112. 'tax' => $tax,
  113. 'rating' => $result['rating'],
  114. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  115. 'href' => $this->url->link('product/product', $url . '&product_id=' . $result['product_id'])
  116. );
  117. }
  118. $url = '';
  119. if (isset($this->request->get['limit'])) {
  120. $url .= '&limit=' . $this->request->get['limit'];
  121. }
  122. $this->data['sorts'] = array();
  123. $this->data['sorts'][] = array(
  124. 'text' => $this->language->get('text_default'),
  125. 'value' => 'p.sort_order-ASC',
  126. 'href' => $this->url->link('product/special', 'sort=p.sort_order&order=ASC' . $url)
  127. );
  128. $this->data['sorts'][] = array(
  129. 'text' => $this->language->get('text_name_asc'),
  130. 'value' => 'pd.name-ASC',
  131. 'href' => $this->url->link('product/special', 'sort=pd.name&order=ASC' . $url)
  132. );
  133. $this->data['sorts'][] = array(
  134. 'text' => $this->language->get('text_name_desc'),
  135. 'value' => 'pd.name-DESC',
  136. 'href' => $this->url->link('product/special', 'sort=pd.name&order=DESC' . $url)
  137. );
  138. $this->data['sorts'][] = array(
  139. 'text' => $this->language->get('text_price_asc'),
  140. 'value' => 'ps.price-ASC',
  141. 'href' => $this->url->link('product/special', 'sort=ps.price&order=ASC' . $url)
  142. );
  143. $this->data['sorts'][] = array(
  144. 'text' => $this->language->get('text_price_desc'),
  145. 'value' => 'special-DESC',
  146. 'href' => $this->url->link('product/special', 'sort=special&order=DESC' . $url)
  147. );
  148. $this->data['sorts'][] = array(
  149. 'text' => $this->language->get('text_rating_desc'),
  150. 'value' => 'rating-DESC',
  151. 'href' => $this->url->link('product/special', 'sort=rating&order=DESC' . $url)
  152. );
  153. $this->data['sorts'][] = array(
  154. 'text' => $this->language->get('text_rating_asc'),
  155. 'value' => 'rating-ASC',
  156. 'href' => $this->url->link('product/special', 'sort=rating&order=ASC' . $url)
  157. );
  158. $this->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. $this->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. $this->data['limits'] = array();
  176. $this->data['limits'][] = array(
  177. 'text' => $this->config->get('config_catalog_limit'),
  178. 'value' => $this->config->get('config_catalog_limit'),
  179. 'href' => $this->url->link('product/special', $url . '&limit=' . $this->config->get('config_catalog_limit'))
  180. );
  181. $this->data['limits'][] = array(
  182. 'text' => 25,
  183. 'value' => 25,
  184. 'href' => $this->url->link('product/special', $url . '&limit=25')
  185. );
  186. $this->data['limits'][] = array(
  187. 'text' => 50,
  188. 'value' => 50,
  189. 'href' => $this->url->link('product/special', $url . '&limit=50')
  190. );
  191. $this->data['limits'][] = array(
  192. 'text' => 75,
  193. 'value' => 75,
  194. 'href' => $this->url->link('product/special', $url . '&limit=75')
  195. );
  196. $this->data['limits'][] = array(
  197. 'text' => 100,
  198. 'value' => 100,
  199. 'href' => $this->url->link('product/special', $url . '&limit=100')
  200. );
  201. $url = '';
  202. if (isset($this->request->get['sort'])) {
  203. $url .= '&sort=' . $this->request->get['sort'];
  204. }
  205. if (isset($this->request->get['order'])) {
  206. $url .= '&order=' . $this->request->get['order'];
  207. }
  208. if (isset($this->request->get['limit'])) {
  209. $url .= '&limit=' . $this->request->get['limit'];
  210. }
  211. $pagination = new Pagination();
  212. $pagination->total = $product_total;
  213. $pagination->page = $page;
  214. $pagination->limit = $limit;
  215. $pagination->text = $this->language->get('text_pagination');
  216. $pagination->url = $this->url->link('product/special', $url . '&page={page}');
  217. $this->data['pagination'] = $pagination->render();
  218. $this->data['sort'] = $sort;
  219. $this->data['order'] = $order;
  220. $this->data['limit'] = $limit;
  221. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/special.tpl')) {
  222. $this->template = $this->config->get('config_template') . '/template/product/special.tpl';
  223. } else {
  224. $this->template = 'default/template/product/special.tpl';
  225. }
  226. $this->children = array(
  227. 'common/column_left',
  228. 'common/column_right',
  229. 'common/content_top',
  230. 'common/content_bottom',
  231. 'common/footer',
  232. 'common/header'
  233. );
  234. $this->response->setOutput($this->render());
  235. }
  236. }
  237. ?>