PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/catalog/controller/product/product.php

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