Guest User

Untitled

a guest
Oct 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.70 KB | None | 0 0
  1. <?php
  2. class ControllerProductCategory extends Controller {
  3. public function index() {
  4. $this->language->load('product/category');
  5.  
  6. $this->document->breadcrumbs = array();
  7.  
  8. $this->document->breadcrumbs[] = array(
  9. 'href' => HTTP_SERVER . 'index.php?route=common/home',
  10. 'text' => $this->language->get('text_home'),
  11. 'separator' => FALSE
  12. );
  13.  
  14. $this->load->model('catalog/category');
  15. $this->load->model('tool/seo_url');
  16.  
  17. if (isset($this->request->get['path'])) {
  18. $path = '';
  19.  
  20. $parts = explode('_', $this->request->get['path']);
  21.  
  22. foreach ($parts as $path_id) {
  23. $category_info = $this->model_catalog_category->getCategory($path_id);
  24.  
  25. if ($category_info) {
  26. if (!$path) {
  27. $path = $path_id;
  28. } else {
  29. $path .= '_' . $path_id;
  30. }
  31.  
  32. $this->document->breadcrumbs[] = array(
  33. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
  34. 'text' => $category_info['name'],
  35. 'separator' => $this->language->get('text_separator')
  36. );
  37. }
  38. }
  39.  
  40. $category_id = array_pop($parts);
  41. } else {
  42. $category_id = 0;
  43. }
  44.  
  45. $category_info = $this->model_catalog_category->getCategory($category_id);
  46.  
  47. if ($category_info) {
  48. $this->document->title = $category_info['name'];
  49.  
  50. $this->document->keywords = $category_info['meta_keywords'];
  51.  
  52. $this->document->description = $category_info['meta_description'];
  53.  
  54. $this->data['heading_title'] = $category_info['name'];
  55.  
  56. $this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  57.  
  58. $this->data['text_sort'] = $this->language->get('text_sort');
  59.  
  60. $this->load->model('tool/image');
  61.  
  62. if ($category_info['image']) {
  63. $image = $category_info['image'];
  64. } else {
  65. $image = '';
  66. }
  67.  
  68. $this->data['thumb'] = $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
  69.  
  70. if (isset($this->request->get['page'])) {
  71. $page = $this->request->get['page'];
  72. } else {
  73. $page = 1;
  74. }
  75.  
  76. if (isset($this->request->get['sort'])) {
  77. $sort = $this->request->get['sort'];
  78. } else {
  79. $sort = 'p.sort_order';
  80. }
  81.  
  82. if (isset($this->request->get['order'])) {
  83. $order = $this->request->get['order'];
  84. } else {
  85. $order = 'ASC';
  86. }
  87.  
  88. $url = '';
  89.  
  90. if (isset($this->request->get['sort'])) {
  91. $url .= '&sort=' . $this->request->get['sort'];
  92. }
  93.  
  94. if (isset($this->request->get['order'])) {
  95. $url .= '&order=' . $this->request->get['order'];
  96. }
  97.  
  98. $this->load->model('catalog/product');
  99.  
  100. $category_total = $this->model_catalog_category->getTotalCategoriesByCategoryId($category_id);
  101. $product_total = $this->model_catalog_product->getTotalProductsByCategoryId($category_id);
  102.  
  103. if ($category_total || $product_total) {
  104. $this->data['categories'] = array();
  105.  
  106. $results = $this->model_catalog_category->getCategories($category_id);
  107.  
  108. foreach ($results as $result) {
  109. if ($result['image']) {
  110. $image = $result['image'];
  111. } else {
  112. $image = 'no_image.jpg';
  113. }
  114.  
  115. $this->data['categories'][] = array(
  116. 'name' => $result['name'],
  117. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
  118. 'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'))
  119. );
  120. }
  121.  
  122. $this->load->model('catalog/review');
  123.  
  124. $this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
  125.  
  126. $this->data['products'] = array();
  127.  
  128. $results = $this->model_catalog_product->getProductsByCategoryId($category_id, $sort, $order, ($page - 1) * $this->config->get('config_catalog_limit'), $this->config->get('config_catalog_limit'));
  129.  
  130. foreach ($results as $result) {
  131. if ($result['image']) {
  132. $image = $result['image'];
  133. } else {
  134. $image = 'no_image.jpg';
  135. }
  136.  
  137. if ($this->config->get('config_review')) {
  138. $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
  139. } else {
  140. $rating = false;
  141. }
  142.  
  143. $special = FALSE;
  144.  
  145. $discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
  146.  
  147. if ($discount) {
  148. $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
  149. } else {
  150. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  151.  
  152. $special = $this->model_catalog_product->getProductSpecial($result['product_id']);
  153.  
  154. if ($special) {
  155. $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
  156. }
  157. }
  158. $options = $this->model_catalog_product->getProductOptions($result['product_id']);
  159.  
  160. if ($options) {
  161. $add = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']);
  162. } else {
  163. $add = HTTPS_SERVER . 'index.php?route=checkout/cart&product_id=' . $result['product_id'];
  164. }
  165.  
  166. $this->data['products'][] = array(
  167. 'name' => $result['name'],
  168. 'model' => $result['model'],
  169. 'rating' => $rating,
  170. 'stars' => sprintf($this->language->get('text_stars'), $rating),
  171. 'thumb' => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
  172. 'price' => $price,
  173. 'meta_description' => $result['meta_description'],
  174. 'options' => $options,
  175. 'special' => $special,
  176. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']),
  177. 'add' => $add
  178.  
  179. );
  180. }
  181.  
  182. if (!$this->config->get('config_customer_price')) {
  183. $this->data['display_price'] = TRUE;
  184. } elseif ($this->customer->isLogged()) {
  185. $this->data['display_price'] = TRUE;
  186. } else {
  187. $this->data['display_price'] = FALSE;
  188. }
  189.  
  190. $url = '';
  191.  
  192. if (isset($this->request->get['page'])) {
  193. $url .= '&page=' . $this->request->get['page'];
  194. }
  195.  
  196. $this->data['sorts'] = array();
  197.  
  198. $this->data['sorts'][] = array(
  199. 'text' => $this->language->get('text_default'),
  200. 'value' => 'p.sort_order-ASC',
  201. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC')
  202. );
  203.  
  204. $this->data['sorts'][] = array(
  205. 'text' => $this->language->get('text_name_asc'),
  206. 'value' => 'pd.name-ASC',
  207. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC')
  208. );
  209.  
  210. $this->data['sorts'][] = array(
  211. 'text' => $this->language->get('text_name_desc'),
  212. 'value' => 'pd.name-DESC',
  213. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC')
  214. );
  215.  
  216. $this->data['sorts'][] = array(
  217. 'text' => $this->language->get('text_price_asc'),
  218. 'value' => 'p.price-ASC',
  219. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.price&order=ASC')
  220. );
  221.  
  222. $this->data['sorts'][] = array(
  223. 'text' => $this->language->get('text_price_desc'),
  224. 'value' => 'p.price-DESC',
  225. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.price&order=DESC')
  226. );
  227.  
  228. if ($this->config->get('config_review')) {
  229. $this->data['sorts'][] = array(
  230. 'text' => $this->language->get('text_rating_desc'),
  231. 'value' => 'rating-DESC',
  232. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=rating&order=DESC')
  233. );
  234.  
  235. $this->data['sorts'][] = array(
  236. 'text' => $this->language->get('text_rating_asc'),
  237. 'value' => 'rating-ASC',
  238. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=rating&order=ASC')
  239. );
  240. }
  241.  
  242. $this->data['sorts'][] = array(
  243. 'text' => $this->language->get('text_model_asc'),
  244. 'value' => 'p.model-ASC',
  245. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.model&order=ASC')
  246. );
  247.  
  248. $this->data['sorts'][] = array(
  249. 'text' => $this->language->get('text_model_desc'),
  250. 'value' => 'p.model-DESC',
  251. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . '&sort=p.model&order=DESC')
  252. );
  253.  
  254. $url = '';
  255.  
  256. if (isset($this->request->get['sort'])) {
  257. $url .= '&sort=' . $this->request->get['sort'];
  258. }
  259.  
  260. if (isset($this->request->get['order'])) {
  261. $url .= '&order=' . $this->request->get['order'];
  262. }
  263.  
  264. $pagination = new Pagination();
  265. $pagination->total = $product_total;
  266. $pagination->page = $page;
  267. $pagination->limit = $this->config->get('config_catalog_limit');
  268. $pagination->text = $this->language->get('text_pagination');
  269. $pagination->url = $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . $url . '&page={page}');
  270.  
  271. $this->data['pagination'] = $pagination->render();
  272.  
  273. $this->data['sort'] = $sort;
  274. $this->data['order'] = $order;
  275.  
  276. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  277. $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
  278. } else {
  279. $this->template = 'default/template/product/category.tpl';
  280. }
  281.  
  282. $this->children = array(
  283. 'common/column_right',
  284. 'common/column_left',
  285. 'common/footer',
  286. 'common/header'
  287. );
  288.  
  289. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  290. } else {
  291. $this->document->title = $category_info['name'];
  292.  
  293. $this->document->description = $category_info['meta_description'];
  294.  
  295. $this->data['heading_title'] = $category_info['name'];
  296.  
  297. $this->data['text_error'] = $this->language->get('text_empty');
  298.  
  299. $this->data['button_continue'] = $this->language->get('button_continue');
  300.  
  301. $this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
  302.  
  303. $this->data['categories'] = array();
  304.  
  305. $this->data['products'] = array();
  306.  
  307. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  308. $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
  309. } else {
  310. $this->template = 'default/template/product/category.tpl';
  311. }
  312.  
  313. $this->children = array(
  314. 'common/column_right',
  315. 'common/column_left',
  316. 'common/footer',
  317. 'common/header'
  318. );
  319.  
  320. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  321. }
  322. } else {
  323. $url = '';
  324.  
  325. if (isset($this->request->get['sort'])) {
  326. $url .= '&sort=' . $this->request->get['sort'];
  327. }
  328.  
  329. if (isset($this->request->get['order'])) {
  330. $url .= '&order=' . $this->request->get['order'];
  331. }
  332.  
  333. if (isset($this->request->get['page'])) {
  334. $url .= '&page=' . $this->request->get['page'];
  335. }
  336.  
  337. if (isset($this->request->get['path'])) {
  338. $this->document->breadcrumbs[] = array(
  339. 'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $this->request->get['path'] . $url),
  340. 'text' => $this->language->get('text_error'),
  341. 'separator' => $this->language->get('text_separator')
  342. );
  343. }
  344.  
  345. $this->document->title = $this->language->get('text_error');
  346.  
  347. $this->data['heading_title'] = $this->language->get('text_error');
  348.  
  349. $this->data['text_error'] = $this->language->get('text_error');
  350.  
  351. $this->data['button_continue'] = $this->language->get('button_continue');
  352.  
  353. $this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
  354.  
  355. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  356. $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  357. } else {
  358. $this->template = 'default/template/error/not_found.tpl';
  359. }
  360.  
  361. $this->children = array(
  362. 'common/column_right',
  363. 'common/column_left',
  364. 'common/footer',
  365. 'common/header'
  366. );
  367.  
  368. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  369. }
  370. }
  371. }
  372. ?>
Add Comment
Please, Sign In to add comment