Advertisement
Guest User

Untitled

a guest
Nov 21st, 2012
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.01 KB | None | 0 0
  1. <?php
  2. class ControllerProductCategory extends Controller {
  3. public function index() {
  4. $this->language->load('product/category');
  5. //$this->language->load('module/fastorder'); //fast order
  6. $this->load->model('catalog/category');
  7.  
  8. $this->load->model('catalog/product');
  9.  
  10. $this->load->model('tool/image');
  11.  
  12. if (isset($this->request->get['sort'])) {
  13. $sort = $this->request->get['sort'];
  14. } else {
  15. $sort = 'instock';
  16. }
  17.  
  18. if (isset($this->request->get['order'])) {
  19. $order = $this->request->get['order'];
  20. } else {
  21. $order = 'ASC';
  22. }
  23.  
  24. if (isset($this->request->get['page'])) {
  25. $page = $this->request->get['page'];
  26. } else {
  27. $page = 1;
  28. }
  29.  
  30. if (isset($this->request->get['limit'])) {
  31. $limit = $this->request->get['limit'];
  32. } else {
  33. $limit = $this->config->get('config_catalog_limit');
  34. }
  35.  
  36. $this->data['breadcrumbs'] = array();
  37.  
  38. $this->data['breadcrumbs'][] = array(
  39. 'text' => $this->language->get('text_home'),
  40. 'href' => $this->url->link('common/home'),
  41. 'separator' => false
  42. );
  43.  
  44. if (isset($this->request->get['path'])) {
  45. $path = '';
  46.  
  47. $parts = explode('_', (string)$this->request->get['path']);
  48.  
  49. foreach ($parts as $path_id) {
  50. if (!$path) {
  51. $path = $path_id;
  52. } else {
  53. $path .= '_' . $path_id;
  54. }
  55.  
  56. $category_info = $this->model_catalog_category->getCategory($path_id);
  57.  
  58. if ($category_info) {
  59. $this->data['breadcrumbs'][] = array(
  60. 'text' => $category_info['name'],
  61. 'href' => $this->url->link('product/category', 'path=' . $path),
  62. 'separator' => $this->language->get('text_separator')
  63. );
  64. }
  65. }
  66.  
  67. $category_id = array_pop($parts);
  68. } else {
  69. $category_id = 0;
  70. }
  71.  
  72. $category_info = $this->model_catalog_category->getCategory($category_id);
  73.  
  74. if ($category_info) {
  75. if ($category_info['seo_title']) {
  76. $this->document->setTitle($category_info['seo_title']);
  77. } else {
  78. $this->document->setTitle($category_info['name']);
  79. }
  80.  
  81. $this->document->setDescription($category_info['meta_description']);
  82. $this->document->setKeywords($category_info['meta_keyword']);
  83.  
  84. $this->data['seo_h1'] = $category_info['seo_h1'];
  85.  
  86. $this->data['heading_title'] = $category_info['name'];
  87.  
  88. $this->data['text_refine'] = $this->language->get('text_refine');
  89. $this->data['text_empty'] = $this->language->get('text_empty');
  90. $this->data['text_quantity'] = $this->language->get('text_quantity');
  91. $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
  92. $this->data['text_model'] = $this->language->get('text_model');
  93. $this->data['text_price'] = $this->language->get('text_price');
  94. $this->data['text_tax'] = $this->language->get('text_tax');
  95. $this->data['text_points'] = $this->language->get('text_points');
  96. $this->data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
  97. $this->data['text_display'] = $this->language->get('text_display');
  98. $this->data['text_list'] = $this->language->get('text_list');
  99. $this->data['text_grid'] = $this->language->get('text_grid');
  100. $this->data['text_sort'] = $this->language->get('text_sort');
  101. $this->data['text_limit'] = $this->language->get('text_limit');
  102. //$this->data['text_fastorder'] = $this->language->get('text_fastorder'); //fast order
  103. $this->data['button_cart'] = $this->language->get('button_cart');
  104. $this->data['button_wishlist'] = $this->language->get('button_wishlist');
  105. $this->data['button_compare'] = $this->language->get('button_compare');
  106. $this->data['button_continue'] = $this->language->get('button_continue');
  107.  
  108. if ($category_info['image']) {
  109. $this->data['thumb'] = $this->model_tool_image->resize($category_info['image'], $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'));
  110. } else {
  111. $this->data['thumb'] = '';
  112. }
  113.  
  114. $this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  115. //if ($page == 1) {
  116. //$this->data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
  117. //} else {
  118. //$this->data['description'] = "";
  119. //}
  120. $this->data['compare'] = $this->url->link('product/compare');
  121.  
  122. $url = '';
  123.  
  124. if (isset($this->request->get['sort'])) {
  125. $url .= '&sort=' . $this->request->get['sort'];
  126. }
  127.  
  128. if (isset($this->request->get['order'])) {
  129. $url .= '&order=' . $this->request->get['order'];
  130. }
  131.  
  132. if (isset($this->request->get['limit'])) {
  133. $url .= '&limit=' . $this->request->get['limit'];
  134. }
  135.  
  136. $this->data['categories'] = array();
  137.  
  138. $results = $this->model_catalog_category->getCategories($category_id);
  139.  
  140. foreach ($results as $result) {
  141. $data = array(
  142. 'filter_category_id' => $result['category_id'],
  143. 'filter_sub_category' => true
  144. );
  145.  
  146. $product_total = $this->model_catalog_product->getTotalProducts($data);
  147.  
  148. $this->data['categories'][] = array(
  149. 'name' => $result['name'] . ' (' . $product_total . ')',
  150. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url)
  151. );
  152. }
  153.  
  154. $this->data['products'] = array();
  155.  
  156. $data = array(
  157. 'filter_category_id' => $category_id,
  158. 'sort' => $sort,
  159. 'order' => $order,
  160. 'start' => ($page - 1) * $limit,
  161. 'limit' => $limit
  162. );
  163.  
  164. $product_total = $this->model_catalog_product->getTotalProducts($data);
  165.  
  166. $results = $this->model_catalog_product->getProducts($data);
  167.  
  168. foreach ($results as $result) {
  169. if ($result['image']) {
  170. $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
  171. } else {
  172. $image = false;
  173. }
  174.  
  175. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  176. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  177. } else {
  178. $price = false;
  179. }
  180.  
  181. if ((float)$result['special']) {
  182. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  183. } else {
  184. $special = false;
  185. }
  186.  
  187. if ($this->config->get('config_tax')) {
  188. $tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
  189. } else {
  190. $tax = false;
  191. }
  192.  
  193. if ($this->config->get('config_review_status')) {
  194. $rating = (int)$result['rating'];
  195. } else {
  196. $rating = false;
  197. }
  198.  
  199. $this->data['products'][] = array(
  200. 'product_id' => $result['product_id'],
  201. 'thumb' => $image,
  202. 'name' => $result['name'],
  203. 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 200) . '..',
  204. 'price' => $price,
  205. 'special' => $special,
  206. 'tax' => $tax,
  207. 'rating' => $result['rating'],
  208. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  209. 'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])
  210. );
  211. }
  212.  
  213. $url = '';
  214.  
  215. if (isset($this->request->get['limit'])) {
  216. $url .= '&limit=' . $this->request->get['limit'];
  217. }
  218.  
  219. $this->data['sorts'] = array();
  220.  
  221. $this->data['sorts'][] = array(
  222. 'text' => $this->language->get('text_default'),
  223. 'value' => 'p.sort_order-ASC',
  224. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.sort_order&order=ASC' . $url)
  225. );
  226.  
  227. $this->data['sorts'][] = array(
  228. 'text' => $this->language->get('text_name_asc'),
  229. 'value' => 'pd.name-ASC',
  230. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=ASC' . $url)
  231. );
  232.  
  233. $this->data['sorts'][] = array(
  234. 'text' => $this->language->get('text_name_desc'),
  235. 'value' => 'pd.name-DESC',
  236. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=pd.name&order=DESC' . $url)
  237. );
  238.  
  239. $this->data['sorts'][] = array(
  240. 'text' => $this->language->get('text_price_asc'),
  241. 'value' => 'p.price-ASC',
  242. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=ASC' . $url)
  243. );
  244.  
  245. $this->data['sorts'][] = array(
  246. 'text' => $this->language->get('text_price_desc'),
  247. 'value' => 'p.price-DESC',
  248. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.price&order=DESC' . $url)
  249. );
  250.  
  251. if ($this->config->get('config_review_status')) {
  252. $this->data['sorts'][] = array(
  253. 'text' => $this->language->get('text_rating_desc'),
  254. 'value' => 'rating-DESC',
  255. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=DESC' . $url)
  256. );
  257.  
  258. $this->data['sorts'][] = array(
  259. 'text' => $this->language->get('text_rating_asc'),
  260. 'value' => 'rating-ASC',
  261. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=rating&order=ASC' . $url)
  262. );
  263. }
  264.  
  265. $this->data['sorts'][] = array(
  266. 'text' => $this->language->get('text_model_asc'),
  267. 'value' => 'p.model-ASC',
  268. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=ASC' . $url)
  269. );
  270.  
  271. $this->data['sorts'][] = array(
  272. 'text' => $this->language->get('text_model_desc'),
  273. 'value' => 'p.model-DESC',
  274. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=p.model&order=DESC' . $url)
  275. );
  276.  
  277. $this->data['sorts'][] = array(
  278. 'text' => $this->language->get('text_instock'),
  279. 'value' => 'instock-ASC',
  280. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '&sort=instock&order=ASC' . $url)
  281. );
  282.  
  283. $url = '';
  284.  
  285. if (isset($this->request->get['sort'])) {
  286. $url .= '&sort=' . $this->request->get['sort'];
  287. }
  288.  
  289. if (isset($this->request->get['order'])) {
  290. $url .= '&order=' . $this->request->get['order'];
  291. }
  292.  
  293. $this->data['limits'] = array();
  294.  
  295. $this->data['limits'][] = array(
  296. 'text' => $this->config->get('config_catalog_limit'),
  297. 'value' => $this->config->get('config_catalog_limit'),
  298. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=' . $this->config->get('config_catalog_limit'))
  299. );
  300.  
  301. $this->data['limits'][] = array(
  302. 'text' => 25,
  303. 'value' => 25,
  304. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=25')
  305. );
  306.  
  307. $this->data['limits'][] = array(
  308. 'text' => 50,
  309. 'value' => 50,
  310. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=50')
  311. );
  312.  
  313. $this->data['limits'][] = array(
  314. 'text' => 75,
  315. 'value' => 75,
  316. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=75')
  317. );
  318.  
  319. $this->data['limits'][] = array(
  320. 'text' => 100,
  321. 'value' => 100,
  322. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&limit=100')
  323. );
  324.  
  325. $url = '';
  326.  
  327. if (isset($this->request->get['sort'])) {
  328. $url .= '&sort=' . $this->request->get['sort'];
  329. }
  330.  
  331. if (isset($this->request->get['order'])) {
  332. $url .= '&order=' . $this->request->get['order'];
  333. }
  334.  
  335. if (isset($this->request->get['limit'])) {
  336. $url .= '&limit=' . $this->request->get['limit'];
  337. }
  338.  
  339. $pagination = new Pagination();
  340. $pagination->total = $product_total;
  341. $pagination->page = $page;
  342. $pagination->limit = $limit;
  343. $pagination->text = $this->language->get('text_pagination');
  344. $pagination->url = $this->url->link('product/category', 'path=' . $this->request->get['path'] . $url . '&page={page}');
  345.  
  346. $this->data['pagination'] = $pagination->render();
  347.  
  348. $this->data['sort'] = $sort;
  349. $this->data['order'] = $order;
  350. $this->data['limit'] = $limit;
  351.  
  352. $this->data['continue'] = $this->url->link('common/home');
  353.  
  354. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
  355. $this->template = $this->config->get('config_template') . '/template/product/category.tpl';
  356. } else {
  357. $this->template = 'default/template/product/category.tpl';
  358. }
  359.  
  360. $this->children = array(
  361. 'common/column_left',
  362. 'common/column_right',
  363. 'common/content_top',
  364. 'common/content_bottom',
  365. 'common/footer',
  366. 'common/header'
  367. );
  368.  
  369. $this->response->setOutput($this->render());
  370. } else {
  371. $url = '';
  372.  
  373. if (isset($this->request->get['path'])) {
  374. $url .= '&path=' . $this->request->get['path'];
  375. }
  376.  
  377. if (isset($this->request->get['sort'])) {
  378. $url .= '&sort=' . $this->request->get['sort'];
  379. }
  380.  
  381. if (isset($this->request->get['order'])) {
  382. $url .= '&order=' . $this->request->get['order'];
  383. }
  384.  
  385. if (isset($this->request->get['page'])) {
  386. $url .= '&page=' . $this->request->get['page'];
  387. }
  388.  
  389. if (isset($this->request->get['limit'])) {
  390. $url .= '&limit=' . $this->request->get['limit'];
  391. }
  392.  
  393. $this->data['breadcrumbs'][] = array(
  394. 'text' => $this->language->get('text_error'),
  395. 'href' => $this->url->link('product/category', $url),
  396. 'separator' => $this->language->get('text_separator')
  397. );
  398.  
  399. $this->document->setTitle($this->language->get('text_error'));
  400.  
  401. $this->data['heading_title'] = $this->language->get('text_error');
  402.  
  403. $this->data['text_error'] = $this->language->get('text_error');
  404.  
  405. $this->data['button_continue'] = $this->language->get('button_continue');
  406.  
  407. $this->data['continue'] = $this->url->link('common/home');
  408.  
  409. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  410. $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  411. } else {
  412. $this->template = 'default/template/error/not_found.tpl';
  413. }
  414.  
  415. $this->children = array(
  416. 'common/column_left',
  417. 'common/column_right',
  418. 'common/content_top',
  419. 'common/content_bottom',
  420. 'common/footer',
  421. 'common/header'
  422. );
  423.  
  424. $this->response->setOutput($this->render());
  425. }
  426. }
  427. }
  428. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement