Guest User

Controller file

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