Guest User

Untitled

a guest
Dec 12th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.72 KB | None | 0 0
  1. <?php
  2. class ControllerProductProduct extends Controller {
  3. private $error = array();
  4.  
  5. public function index() {
  6. $this->language->load('product/product');
  7.  
  8. $this->data['breadcrumbs'] = array();
  9.  
  10. $this->data['breadcrumbs'][] = array(
  11. 'text' => $this->language->get('text_home'),
  12. 'href' => $this->url->link('common/home'),
  13. 'separator' => false
  14. );
  15.  
  16. $this->load->model('catalog/category');
  17.  
  18. if (isset($this->request->get['path'])) {
  19. $path = '';
  20.  
  21. $parts = explode('_', (string)$this->request->get['path']);
  22.  
  23. $category_id = (int)array_pop($parts);
  24.  
  25. foreach ($parts as $path_id) {
  26. if (!$path) {
  27. $path = $path_id;
  28. } else {
  29. $path .= '_' . $path_id;
  30. }
  31.  
  32. $category_info = $this->model_catalog_category->getCategory($path_id);
  33.  
  34. if ($category_info) {
  35. $this->data['breadcrumbs'][] = array(
  36. 'text' => $category_info['name'],
  37. 'href' => $this->url->link('product/category', 'path=' . $path),
  38. 'separator' => $this->language->get('text_separator')
  39. );
  40. }
  41. }
  42.  
  43. // Set the last category breadcrumb
  44. $category_info = $this->model_catalog_category->getCategory($category_id);
  45.  
  46. if ($category_info) {
  47. $url = '';
  48.  
  49. if (isset($this->request->get['sort'])) {
  50. $url .= '&sort=' . $this->request->get['sort'];
  51. }
  52.  
  53. if (isset($this->request->get['order'])) {
  54. $url .= '&order=' . $this->request->get['order'];
  55. }
  56.  
  57. if (isset($this->request->get['page'])) {
  58. $url .= '&page=' . $this->request->get['page'];
  59. }
  60.  
  61. if (isset($this->request->get['limit'])) {
  62. $url .= '&limit=' . $this->request->get['limit'];
  63. }
  64.  
  65. $this->data['breadcrumbs'][] = array(
  66. 'text' => $category_info['name'],
  67. 'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'].$url),
  68. 'separator' => $this->language->get('text_separator')
  69. );
  70. }
  71. }
  72.  
  73. $this->load->model('catalog/manufacturer');
  74.  
  75. if (isset($this->request->get['manufacturer_id'])) {
  76. $this->data['breadcrumbs'][] = array(
  77. 'text' => $this->language->get('text_brand'),
  78. 'href' => $this->url->link('product/manufacturer'),
  79. 'separator' => $this->language->get('text_separator')
  80. );
  81.  
  82. $url = '';
  83.  
  84. if (isset($this->request->get['sort'])) {
  85. $url .= '&sort=' . $this->request->get['sort'];
  86. }
  87.  
  88. if (isset($this->request->get['order'])) {
  89. $url .= '&order=' . $this->request->get['order'];
  90. }
  91.  
  92. if (isset($this->request->get['page'])) {
  93. $url .= '&page=' . $this->request->get['page'];
  94. }
  95.  
  96. if (isset($this->request->get['limit'])) {
  97. $url .= '&limit=' . $this->request->get['limit'];
  98. }
  99.  
  100. $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
  101.  
  102. if ($manufacturer_info) {
  103. $this->data['breadcrumbs'][] = array(
  104. 'text' => $manufacturer_info['name'],
  105. 'href' => $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $this->request->get['manufacturer_id'] . $url),
  106. 'separator' => $this->language->get('text_separator')
  107. );
  108. }
  109. }
  110.  
  111. if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
  112. $url = '';
  113.  
  114. if (isset($this->request->get['search'])) {
  115. $url .= '&search=' . $this->request->get['search'];
  116. }
  117.  
  118. if (isset($this->request->get['tag'])) {
  119. $url .= '&tag=' . $this->request->get['tag'];
  120. }
  121.  
  122. if (isset($this->request->get['description'])) {
  123. $url .= '&description=' . $this->request->get['description'];
  124. }
  125.  
  126. if (isset($this->request->get['category_id'])) {
  127. $url .= '&category_id=' . $this->request->get['category_id'];
  128. }
  129.  
  130. if (isset($this->request->get['sub_category'])) {
  131. $url .= '&sub_category=' . $this->request->get['sub_category'];
  132. }
  133.  
  134. if (isset($this->request->get['sort'])) {
  135. $url .= '&sort=' . $this->request->get['sort'];
  136. }
  137.  
  138. if (isset($this->request->get['order'])) {
  139. $url .= '&order=' . $this->request->get['order'];
  140. }
  141.  
  142. if (isset($this->request->get['page'])) {
  143. $url .= '&page=' . $this->request->get['page'];
  144. }
  145.  
  146. if (isset($this->request->get['limit'])) {
  147. $url .= '&limit=' . $this->request->get['limit'];
  148. }
  149.  
  150. $this->data['breadcrumbs'][] = array(
  151. 'text' => $this->language->get('text_search'),
  152. 'href' => $this->url->link('product/search', $url),
  153. 'separator' => $this->language->get('text_separator')
  154. );
  155. }
  156.  
  157. if (isset($this->request->get['product_id'])) {
  158. $product_id = (int)$this->request->get['product_id'];
  159. } else {
  160. $product_id = 0;
  161. }
  162.  
  163. $this->load->model('catalog/product');
  164.  
  165. $product_info = $this->model_catalog_product->getProduct($product_id);
  166.  
  167. if ($product_info) {
  168. $url = '';
  169.  
  170. if (isset($this->request->get['path'])) {
  171. $url .= '&path=' . $this->request->get['path'];
  172. }
  173.  
  174. if (isset($this->request->get['filter'])) {
  175. $url .= '&filter=' . $this->request->get['filter'];
  176. }
  177.  
  178. if (isset($this->request->get['manufacturer_id'])) {
  179. $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  180. }
  181.  
  182. if (isset($this->request->get['search'])) {
  183. $url .= '&search=' . $this->request->get['search'];
  184. }
  185.  
  186. if (isset($this->request->get['tag'])) {
  187. $url .= '&tag=' . $this->request->get['tag'];
  188. }
  189.  
  190. if (isset($this->request->get['description'])) {
  191. $url .= '&description=' . $this->request->get['description'];
  192. }
  193.  
  194. if (isset($this->request->get['category_id'])) {
  195. $url .= '&category_id=' . $this->request->get['category_id'];
  196. }
  197.  
  198. if (isset($this->request->get['sub_category'])) {
  199. $url .= '&sub_category=' . $this->request->get['sub_category'];
  200. }
  201.  
  202. if (isset($this->request->get['sort'])) {
  203. $url .= '&sort=' . $this->request->get['sort'];
  204. }
  205.  
  206. if (isset($this->request->get['order'])) {
  207. $url .= '&order=' . $this->request->get['order'];
  208. }
  209.  
  210. if (isset($this->request->get['page'])) {
  211. $url .= '&page=' . $this->request->get['page'];
  212. }
  213.  
  214. if (isset($this->request->get['limit'])) {
  215. $url .= '&limit=' . $this->request->get['limit'];
  216. }
  217.  
  218. $this->data['breadcrumbs'][] = array(
  219. 'text' => $product_info['name'],
  220. 'href' => $this->url->link('product/product', $url . '&product_id=' . $this->request->get['product_id']),
  221. 'separator' => $this->language->get('text_separator')
  222. );
  223.  
  224. $this->document->setTitle($product_info['name']);
  225. $this->document->setDescription($product_info['meta_description']);
  226. $this->document->setKeywords($product_info['meta_keyword']);
  227. $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
  228. $this->document->addScript('catalog/view/javascript/jquery/tabs.js');
  229. $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js');
  230. $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css');
  231.  
  232. $this->data['heading_title'] = $product_info['name'];
  233.  
  234. $this->data['text_select'] = $this->language->get('text_select');
  235. $this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
  236. $this->data['text_model'] = $this->language->get('text_model');
  237. $this->data['text_reward'] = $this->language->get('text_reward');
  238. $this->data['text_points'] = $this->language->get('text_points');
  239. $this->data['text_discount'] = $this->language->get('text_discount');
  240. $this->data['text_stock'] = $this->language->get('text_stock');
  241. $this->data['text_price'] = $this->language->get('text_price');
  242. $this->data['text_tax'] = $this->language->get('text_tax');
  243. $this->data['text_discount'] = $this->language->get('text_discount');
  244. $this->data['text_option'] = $this->language->get('text_option');
  245. $this->data['text_qty'] = $this->language->get('text_qty');
  246. $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
  247. $this->data['text_or'] = $this->language->get('text_or');
  248. $this->data['text_write'] = $this->language->get('text_write');
  249. $this->data['text_note'] = $this->language->get('text_note');
  250. $this->data['text_share'] = $this->language->get('text_share');
  251. $this->data['text_wait'] = $this->language->get('text_wait');
  252. $this->data['text_tags'] = $this->language->get('text_tags');
  253.  
  254. $this->data['entry_name'] = $this->language->get('entry_name');
  255. $this->data['entry_review'] = $this->language->get('entry_review');
  256. $this->data['entry_rating'] = $this->language->get('entry_rating');
  257. $this->data['entry_good'] = $this->language->get('entry_good');
  258. $this->data['entry_bad'] = $this->language->get('entry_bad');
  259. $this->data['entry_captcha'] = $this->language->get('entry_captcha');
  260.  
  261. $this->data['button_cart'] = $this->language->get('button_cart');
  262. $this->data['button_wishlist'] = $this->language->get('button_wishlist');
  263. $this->data['button_compare'] = $this->language->get('button_compare');
  264. $this->data['button_upload'] = $this->language->get('button_upload');
  265. $this->data['button_continue'] = $this->language->get('button_continue');
  266.  
  267. $this->load->model('catalog/review');
  268.  
  269. $this->data['tab_description'] = $this->language->get('tab_description');
  270. $this->data['tab_attribute'] = $this->language->get('tab_attribute');
  271. $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $product_info['reviews']);
  272. $this->data['tab_related'] = $this->language->get('tab_related');
  273.  
  274. $this->data['product_id'] = $this->request->get['product_id'];
  275. $this->data['manufacturer'] = $product_info['manufacturer'];
  276. $this->data['manufacturers'] = $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $product_info['manufacturer_id']);
  277. $this->data['model'] = $product_info['model'];
  278. $this->data['reward'] = $product_info['reward'];
  279. $this->data['points'] = $product_info['points'];
  280.  
  281. if ($product_info['quantity'] <= 0) {
  282. $this->data['stock'] = $product_info['stock_status'];
  283. } elseif ($this->config->get('config_stock_display')) {
  284. $this->data['stock'] = $product_info['quantity'];
  285. } else {
  286. $this->data['stock'] = $this->language->get('text_instock');
  287. }
  288.  
  289. $this->load->model('tool/image');
  290.  
  291. if ($product_info['image']) {
  292. $this->data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
  293. } else {
  294. $this->data['popup'] = '';
  295. }
  296.  
  297. if ($product_info['image']) {
  298. $this->data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));
  299. } else {
  300. $this->data['thumb'] = '';
  301. }
  302.  
  303. $this->data['images'] = array();
  304.  
  305. $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  306.  
  307. foreach ($results as $result) {
  308. $this->data['images'][] = array(
  309. 'popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),
  310. 'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'))
  311. );
  312. }
  313.  
  314. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  315. $this->data['price'] = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  316. } else {
  317. $this->data['price'] = false;
  318. }
  319.  
  320. if ((float)$product_info['special']) {
  321. $this->data['special'] = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  322. } else {
  323. $this->data['special'] = false;
  324. }
  325.  
  326. if ($this->config->get('config_tax')) {
  327. $this->data['tax'] = $this->currency->format((float)$product_info['special'] ? $product_info['special'] : $product_info['price']);
  328. } else {
  329. $this->data['tax'] = false;
  330. }
  331.  
  332. $discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  333.  
  334. $this->data['discounts'] = array();
  335.  
  336. foreach ($discounts as $discount) {
  337. $this->data['discounts'][] = array(
  338. 'quantity' => $discount['quantity'],
  339. 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
  340. );
  341. }
  342.  
  343. $this->data['options'] = array();
  344.  
  345. foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) {
  346. if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
  347. $option_value_data = array();
  348.  
  349. foreach ($option['option_value'] as $option_value) {
  350. if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
  351. if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
  352. $price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
  353. } else {
  354. $price = false;
  355. }
  356.  
  357. }
  358. }
  359.  
  360.  
  361. $this->data['options'][] = array(
  362. 'product_option_id' => $option['product_option_id'],
  363. 'option_id' => $option['option_id'],
  364. 'name' => $option['name'],
  365. 'type' => $option['type'],
  366. 'price' => $price,
  367. 'option_value' => $option_value_data,
  368. 'required' => $option['required']
  369. );
  370. } elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
  371. $this->data['options'][] = array(
  372. 'product_option_id' => $option['product_option_id'],
  373. 'option_id' => $option['option_id'],
  374. 'name' => $option['name'],
  375. 'type' => $option['type'],
  376. 'option_value' => $option['option_value'],
  377. 'required' => $option['required']
  378. );
  379. }
  380. }
  381.  
  382. if ($product_info['minimum']) {
  383. $this->data['minimum'] = $product_info['minimum'];
  384. } else {
  385. $this->data['minimum'] = 1;
  386. }
  387.  
  388. $this->data['review_status'] = $this->config->get('config_review_status');
  389. $this->data['reviews'] = sprintf($this->language->get('text_reviews'), (int)$product_info['reviews']);
  390. $this->data['rating'] = (int)$product_info['rating'];
  391. $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
  392. $this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);
  393.  
  394. $this->data['products'] = array();
  395.  
  396. $results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  397.  
  398. foreach ($results as $result) {
  399. if ($result['image']) {
  400. $image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_related_width'), $this->config->get('config_image_related_height'));
  401. } else {
  402. $image = false;
  403. }
  404.  
  405. if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
  406. $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
  407. } else {
  408. $price = false;
  409. }
  410.  
  411. if ((float)$result['special']) {
  412. $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
  413. } else {
  414. $special = false;
  415. }
  416.  
  417. if ($this->config->get('config_review_status')) {
  418. $rating = (int)$result['rating'];
  419. } else {
  420. $rating = false;
  421. }
  422.  
  423. $this->data['products'][] = array(
  424. 'product_id' => $result['product_id'],
  425. 'thumb' => $image,
  426. 'name' => $result['name'],
  427. 'price' => $price,
  428. 'special' => $special,
  429. 'rating' => $rating,
  430. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
  431. 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
  432. );
  433. }
  434.  
  435. $this->data['tags'] = array();
  436.  
  437. if ($product_info['tag']) {
  438. $tags = explode(',', $product_info['tag']);
  439.  
  440. foreach ($tags as $tag) {
  441. $this->data['tags'][] = array(
  442. 'tag' => trim($tag),
  443. 'href' => $this->url->link('product/search', 'tag=' . trim($tag))
  444. );
  445. }
  446. }
  447.  
  448. $this->data['text_payment_profile'] = $this->language->get('text_payment_profile');
  449. $this->data['profiles'] = $this->model_catalog_product->getProfiles($product_info['product_id']);
  450.  
  451. $this->model_catalog_product->updateViewed($this->request->get['product_id']);
  452.  
  453. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/product.tpl')) {
  454. $this->template = $this->config->get('config_template') . '/template/product/product.tpl';
  455. } else {
  456. $this->template = 'default/template/product/product.tpl';
  457. }
  458.  
  459. $this->children = array(
  460. 'common/column_left',
  461. 'common/column_right',
  462. 'common/content_top',
  463. 'common/content_bottom',
  464. 'common/footer',
  465. 'common/header'
  466. );
  467.  
  468. $this->response->setOutput($this->render());
  469. } else {
  470. $url = '';
  471.  
  472. if (isset($this->request->get['path'])) {
  473. $url .= '&path=' . $this->request->get['path'];
  474. }
  475.  
  476. if (isset($this->request->get['filter'])) {
  477. $url .= '&filter=' . $this->request->get['filter'];
  478. }
  479.  
  480. if (isset($this->request->get['manufacturer_id'])) {
  481. $url .= '&manufacturer_id=' . $this->request->get['manufacturer_id'];
  482. }
  483.  
  484. if (isset($this->request->get['search'])) {
  485. $url .= '&search=' . $this->request->get['search'];
  486. }
  487.  
  488. if (isset($this->request->get['tag'])) {
  489. $url .= '&tag=' . $this->request->get['tag'];
  490. }
  491.  
  492. if (isset($this->request->get['description'])) {
  493. $url .= '&description=' . $this->request->get['description'];
  494. }
  495.  
  496. if (isset($this->request->get['category_id'])) {
  497. $url .= '&category_id=' . $this->request->get['category_id'];
  498. }
  499.  
  500. if (isset($this->request->get['sub_category'])) {
  501. $url .= '&sub_category=' . $this->request->get['sub_category'];
  502. }
  503.  
  504. if (isset($this->request->get['sort'])) {
  505. $url .= '&sort=' . $this->request->get['sort'];
  506. }
  507.  
  508. if (isset($this->request->get['order'])) {
  509. $url .= '&order=' . $this->request->get['order'];
  510. }
  511.  
  512. if (isset($this->request->get['page'])) {
  513. $url .= '&page=' . $this->request->get['page'];
  514. }
  515.  
  516. if (isset($this->request->get['limit'])) {
  517. $url .= '&limit=' . $this->request->get['limit'];
  518. }
  519.  
  520. $this->data['breadcrumbs'][] = array(
  521. 'text' => $this->language->get('text_error'),
  522. 'href' => $this->url->link('product/product', $url . '&product_id=' . $product_id),
  523. 'separator' => $this->language->get('text_separator')
  524. );
  525.  
  526. $this->document->setTitle($this->language->get('text_error'));
  527.  
  528. $this->data['heading_title'] = $this->language->get('text_error');
  529.  
  530. $this->data['text_error'] = $this->language->get('text_error');
  531.  
  532. $this->data['button_continue'] = $this->language->get('button_continue');
  533.  
  534. $this->data['continue'] = $this->url->link('common/home');
  535.  
  536. $this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . '/1.1 404 Not Found');
  537.  
  538. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
  539. $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
  540. } else {
  541. $this->template = 'default/template/error/not_found.tpl';
  542. }
  543.  
  544. $this->children = array(
  545. 'common/column_left',
  546. 'common/column_right',
  547. 'common/content_top',
  548. 'common/content_bottom',
  549. 'common/footer',
  550. 'common/header'
  551. );
  552.  
  553. $this->response->setOutput($this->render());
  554. }
  555. }
  556.  
  557. public function review() {
  558. $this->language->load('product/product');
  559.  
  560. $this->load->model('catalog/review');
  561.  
  562. $this->data['text_on'] = $this->language->get('text_on');
  563. $this->data['text_no_reviews'] = $this->language->get('text_no_reviews');
  564.  
  565. if (isset($this->request->get['page'])) {
  566. $page = $this->request->get['page'];
  567. } else {
  568. $page = 1;
  569. }
  570.  
  571. $this->data['reviews'] = array();
  572.  
  573. $review_total = $this->model_catalog_review->getTotalReviewsByProductId($this->request->get['product_id']);
  574.  
  575. $results = $this->model_catalog_review->getReviewsByProductId($this->request->get['product_id'], ($page - 1) * 5, 5);
  576.  
  577. foreach ($results as $result) {
  578. $this->data['reviews'][] = array(
  579. 'author' => $result['author'],
  580. 'text' => $result['text'],
  581. 'rating' => (int)$result['rating'],
  582. 'reviews' => sprintf($this->language->get('text_reviews'), (int)$review_total),
  583. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  584. );
  585. }
  586.  
  587. $pagination = new Pagination();
  588. $pagination->total = $review_total;
  589. $pagination->page = $page;
  590. $pagination->limit = 5;
  591. $pagination->text = $this->language->get('text_pagination');
  592. $pagination->url = $this->url->link('product/product/review', 'product_id=' . $this->request->get['product_id'] . '&page={page}');
  593.  
  594. $this->data['pagination'] = $pagination->render();
  595.  
  596. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/review.tpl')) {
  597. $this->template = $this->config->get('config_template') . '/template/product/review.tpl';
  598. } else {
  599. $this->template = 'default/template/product/review.tpl';
  600. }
  601.  
  602. $this->response->setOutput($this->render());
  603. }
  604.  
  605. public function getRecurringDescription() {
  606. $this->language->load('product/product');
  607. $this->load->model('catalog/product');
  608.  
  609. if (isset($this->request->post['product_id'])) {
  610. $product_id = $this->request->post['product_id'];
  611. } else {
  612. $product_id = 0;
  613. }
  614.  
  615. if (isset($this->request->post['profile_id'])) {
  616. $profile_id = $this->request->post['profile_id'];
  617. } else {
  618. $profile_id = 0;
  619. }
  620.  
  621. if (isset($this->request->post['quantity'])) {
  622. $quantity = $this->request->post['quantity'];
  623. } else {
  624. $quantity = 1;
  625. }
  626.  
  627. $product_info = $this->model_catalog_product->getProduct($product_id);
  628. $profile_info = $this->model_catalog_product->getProfile($product_id, $profile_id);
  629.  
  630. $json = array();
  631.  
  632. if ($product_info && $profile_info) {
  633.  
  634. if (!$json) {
  635. $frequencies = array(
  636. 'day' => $this->language->get('text_day'),
  637. 'week' => $this->language->get('text_week'),
  638. 'semi_month' => $this->language->get('text_semi_month'),
  639. 'month' => $this->language->get('text_month'),
  640. 'year' => $this->language->get('text_year'),
  641. );
  642.  
  643. if ($profile_info['trial_status'] == 1) {
  644. $price = $this->currency->format($this->tax->calculate($profile_info['trial_price'] * $quantity, $product_info['tax_class_id'], $this->config->get('config_tax')));
  645. $trial_text = sprintf($this->language->get('text_trial_description'), $price, $profile_info['trial_cycle'], $frequencies[$profile_info['trial_frequency']], $profile_info['trial_duration']) . ' ';
  646. } else {
  647. $trial_text = '';
  648. }
  649.  
  650. $price = $this->currency->format($this->tax->calculate($profile_info['price'] * $quantity, $product_info['tax_class_id'], $this->config->get('config_tax')));
  651.  
  652. if ($profile_info['duration']) {
  653. $text = $trial_text . sprintf($this->language->get('text_payment_description'), $price, $profile_info['cycle'], $frequencies[$profile_info['frequency']], $profile_info['duration']);
  654. } else {
  655. $text = $trial_text . sprintf($this->language->get('text_payment_until_canceled_description'), $price, $profile_info['cycle'], $frequencies[$profile_info['frequency']], $profile_info['duration']);
  656. }
  657.  
  658. $json['success'] = $text;
  659. }
  660. }
  661.  
  662. $this->response->setOutput(json_encode($json));
  663. }
  664.  
  665.  
  666. public function write() {
  667. $this->language->load('product/product');
  668.  
  669. $this->load->model('catalog/review');
  670.  
  671. $json = array();
  672.  
  673. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  674. if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 25)) {
  675. $json['error'] = $this->language->get('error_name');
  676. }
  677.  
  678. if ((utf8_strlen($this->request->post['text']) < 25) || (utf8_strlen($this->request->post['text']) > 1000)) {
  679. $json['error'] = $this->language->get('error_text');
  680. }
  681.  
  682. if (empty($this->request->post['rating'])) {
  683. $json['error'] = $this->language->get('error_rating');
  684. }
  685.  
  686. if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
  687. $json['error'] = $this->language->get('error_captcha');
  688. }
  689.  
  690. if (!isset($json['error'])) {
  691. $this->model_catalog_review->addReview($this->request->get['product_id'], $this->request->post);
  692.  
  693. $json['success'] = $this->language->get('text_success');
  694. }
  695. }
  696.  
  697. $this->response->setOutput(json_encode($json));
  698. }
  699.  
  700. public function captcha() {
  701. $this->load->library('captcha');
  702.  
  703. $captcha = new Captcha();
  704.  
  705. $this->session->data['captcha'] = $captcha->getCode();
  706.  
  707. $captcha->showImage();
  708. }
  709.  
  710. public function upload() {
  711. $this->language->load('product/product');
  712.  
  713. $json = array();
  714.  
  715. if (!empty($this->request->files['file']['name'])) {
  716. $filename = basename(preg_replace('/[^a-zA-Z0-9\.\-\s+]/', '', html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')));
  717.  
  718. if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 64)) {
  719. $json['error'] = $this->language->get('error_filename');
  720. }
  721.  
  722. // Allowed file extension types
  723. $allowed = array();
  724.  
  725. $filetypes = explode("\n", $this->config->get('config_file_extension_allowed'));
  726.  
  727. foreach ($filetypes as $filetype) {
  728. $allowed[] = trim($filetype);
  729. }
  730.  
  731. if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  732. $json['error'] = $this->language->get('error_filetype');
  733. }
  734.  
  735. // Allowed file mime types
  736. $allowed = array();
  737.  
  738. $filetypes = explode("\n", $this->config->get('config_file_mime_allowed'));
  739.  
  740. foreach ($filetypes as $filetype) {
  741. $allowed[] = trim($filetype);
  742. }
  743.  
  744. if (!in_array($this->request->files['file']['type'], $allowed)) {
  745. $json['error'] = $this->language->get('error_filetype');
  746. }
  747.  
  748. // Check to see if any PHP files are trying to be uploaded
  749. $content = file_get_contents($this->request->files['file']['tmp_name']);
  750.  
  751. if (preg_match('/\<\?php/i', $content)) {
  752. $json['error'] = $this->language->get('error_filetype');
  753. }
  754.  
  755. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  756. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  757. }
  758. } else {
  759. $json['error'] = $this->language->get('error_upload');
  760. }
  761.  
  762. if (!$json && is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  763. $file = basename($filename) . '.' . md5(mt_rand());
  764.  
  765. // Hide the uploaded file name so people can not link to it directly.
  766. $json['file'] = $this->encryption->encrypt($file);
  767.  
  768. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  769.  
  770. $json['success'] = $this->language->get('text_upload');
  771. }
  772.  
  773. $this->response->setOutput(json_encode($json));
  774. }
  775. }
  776.  
  777. ?>
Advertisement
Add Comment
Please, Sign In to add comment