PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/opencart/trunk/upload/admin/controller/catalog/product.php

http://coderstalk.googlecode.com/
PHP | 1034 lines | 810 code | 224 blank | 0 comment | 212 complexity | 154414c68601ad183b44abd31d7b2555 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-3.0
  1. <?php
  2. class ControllerCatalogProduct extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('catalog/product');
  6. $this->document->title = $this->language->get('heading_title');
  7. $this->load->model('catalog/product');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->load->language('catalog/product');
  12. $this->document->title = $this->language->get('heading_title');
  13. $this->load->model('catalog/product');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $data = array();
  16. if (is_uploaded_file($this->request->files['image']['tmp_name']) && is_writable(DIR_IMAGE) && is_writable(DIR_IMAGE . 'cache/')) {
  17. move_uploaded_file($this->request->files['image']['tmp_name'], DIR_IMAGE . $this->request->files['image']['name']);
  18. if (file_exists(DIR_IMAGE . $this->request->files['image']['name'])) {
  19. $data['image'] = $this->request->files['image']['name'];
  20. }
  21. }
  22. if (isset($this->request->files['product_image'])) {
  23. foreach (array_keys($this->request->files['product_image']['name']) as $key) {
  24. if (is_uploaded_file($this->request->files['product_image']['tmp_name'][$key]) && is_writable(DIR_IMAGE) && is_writable(DIR_IMAGE . 'cache/')) {
  25. move_uploaded_file($this->request->files['product_image']['tmp_name'][$key], DIR_IMAGE . $this->request->files['product_image']['name'][$key]);
  26. if (file_exists(DIR_IMAGE . $this->request->files['product_image']['name'][$key])) {
  27. $data['product_image'][] = $this->request->files['product_image']['name'][$key];
  28. }
  29. }
  30. }
  31. }
  32. $this->model_catalog_product->addProduct(array_merge($this->request->post, $data));
  33. $this->session->data['success'] = $this->language->get('text_success');
  34. $url = '';
  35. if (isset($this->request->get['filter_name'])) {
  36. $url .= '&filter_name=' . $this->request->get['filter_name'];
  37. }
  38. if (isset($this->request->get['filter_model'])) {
  39. $url .= '&filter_model=' . $this->request->get['filter_model'];
  40. }
  41. if (isset($this->request->get['filter_quantity'])) {
  42. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  43. }
  44. if (isset($this->request->get['filter_status'])) {
  45. $url .= '&filter_status=' . $this->request->get['filter_status'];
  46. }
  47. if (isset($this->request->get['page'])) {
  48. $url .= '&page=' . $this->request->get['page'];
  49. }
  50. if (isset($this->request->get['sort'])) {
  51. $url .= '&sort=' . $this->request->get['sort'];
  52. }
  53. if (isset($this->request->get['order'])) {
  54. $url .= '&order=' . $this->request->get['order'];
  55. }
  56. $this->redirect($this->url->https('catalog/product' . $url));
  57. }
  58. $this->getForm();
  59. }
  60. public function update() {
  61. $this->load->language('catalog/product');
  62. $this->document->title = $this->language->get('heading_title');
  63. $this->load->model('catalog/product');
  64. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  65. $data = array();
  66. if (is_uploaded_file($this->request->files['image']['tmp_name']) && is_writable(DIR_IMAGE) && is_writable(DIR_IMAGE . 'cache/')) {
  67. move_uploaded_file($this->request->files['image']['tmp_name'], DIR_IMAGE . $this->request->files['image']['name']);
  68. if (file_exists(DIR_IMAGE . $this->request->files['image']['name'])) {
  69. $data['image'] = $this->request->files['image']['name'];
  70. }
  71. }
  72. if (isset($this->request->files['product_image'])) {
  73. foreach (array_keys($this->request->files['product_image']['name']) as $key) {
  74. if (is_uploaded_file($this->request->files['product_image']['tmp_name'][$key]) && is_writable(DIR_IMAGE) && is_writable(DIR_IMAGE . 'cache/')) {
  75. move_uploaded_file($this->request->files['product_image']['tmp_name'][$key], DIR_IMAGE . $this->request->files['product_image']['name'][$key]);
  76. if (file_exists(DIR_IMAGE . $this->request->files['product_image']['name'][$key])) {
  77. $data['product_image'][] = $this->request->files['product_image']['name'][$key];
  78. }
  79. unset($this->request->post['product_image'][$key]);
  80. }
  81. }
  82. }
  83. if (isset($this->request->post['product_image'])) {
  84. foreach (array_keys($this->request->post['product_image']) as $key) {
  85. $data['product_image'][] = $this->request->post['product_image'][$key];
  86. unset($this->request->post['product_image'][$key]);
  87. }
  88. }
  89. $this->model_catalog_product->editProduct($this->request->get['product_id'], array_merge($this->request->post, $data));
  90. $this->session->data['success'] = $this->language->get('text_success');
  91. $url = '';
  92. if (isset($this->request->get['filter_name'])) {
  93. $url .= '&filter_name=' . $this->request->get['filter_name'];
  94. }
  95. if (isset($this->request->get['filter_model'])) {
  96. $url .= '&filter_model=' . $this->request->get['filter_model'];
  97. }
  98. if (isset($this->request->get['filter_quantity'])) {
  99. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  100. }
  101. if (isset($this->request->get['filter_status'])) {
  102. $url .= '&filter_status=' . $this->request->get['filter_status'];
  103. }
  104. if (isset($this->request->get['page'])) {
  105. $url .= '&page=' . $this->request->get['page'];
  106. }
  107. if (isset($this->request->get['sort'])) {
  108. $url .= '&sort=' . $this->request->get['sort'];
  109. }
  110. if (isset($this->request->get['order'])) {
  111. $url .= '&order=' . $this->request->get['order'];
  112. }
  113. $this->redirect($this->url->https('catalog/product' . $url));
  114. }
  115. $this->getForm();
  116. }
  117. public function delete() {
  118. $this->load->language('catalog/product');
  119. $this->document->title = $this->language->get('heading_title');
  120. $this->load->model('catalog/product');
  121. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  122. foreach ($this->request->post['selected'] as $product_id) {
  123. $this->model_catalog_product->deleteProduct($product_id);
  124. }
  125. $this->session->data['success'] = $this->language->get('text_success');
  126. $url = '';
  127. if (isset($this->request->get['filter_name'])) {
  128. $url .= '&filter_name=' . $this->request->get['filter_name'];
  129. }
  130. if (isset($this->request->get['filter_model'])) {
  131. $url .= '&filter_model=' . $this->request->get['filter_model'];
  132. }
  133. if (isset($this->request->get['filter_quantity'])) {
  134. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  135. }
  136. if (isset($this->request->get['filter_status'])) {
  137. $url .= '&filter_status=' . $this->request->get['filter_status'];
  138. }
  139. if (isset($this->request->get['page'])) {
  140. $url .= '&page=' . $this->request->get['page'];
  141. }
  142. if (isset($this->request->get['sort'])) {
  143. $url .= '&sort=' . $this->request->get['sort'];
  144. }
  145. if (isset($this->request->get['order'])) {
  146. $url .= '&order=' . $this->request->get['order'];
  147. }
  148. $this->redirect($this->url->https('catalog/product' . $url));
  149. }
  150. $this->getList();
  151. }
  152. private function getList() {
  153. if (isset($this->request->get['page'])) {
  154. $page = $this->request->get['page'];
  155. } else {
  156. $page = 1;
  157. }
  158. if (isset($this->request->get['sort'])) {
  159. $sort = $this->request->get['sort'];
  160. } else {
  161. $sort = 'pd.name';
  162. }
  163. if (isset($this->request->get['order'])) {
  164. $order = $this->request->get['order'];
  165. } else {
  166. $order = 'ASC';
  167. }
  168. if (isset($this->request->get['filter_name'])) {
  169. $filter_name = $this->request->get['filter_name'];
  170. } else {
  171. $filter_name = NULL;
  172. }
  173. if (isset($this->request->get['filter_model'])) {
  174. $filter_model = $this->request->get['filter_model'];
  175. } else {
  176. $filter_model = NULL;
  177. }
  178. if (isset($this->request->get['filter_quantity'])) {
  179. $filter_quantity = $this->request->get['filter_quantity'];
  180. } else {
  181. $filter_quantity = NULL;
  182. }
  183. if (isset($this->request->get['filter_status'])) {
  184. $filter_status = $this->request->get['filter_status'];
  185. } else {
  186. $filter_status = NULL;
  187. }
  188. $url = '';
  189. if (isset($this->request->get['filter_name'])) {
  190. $url .= '&filter_name=' . $this->request->get['filter_name'];
  191. }
  192. if (isset($this->request->get['filter_model'])) {
  193. $url .= '&filter_model=' . $this->request->get['filter_model'];
  194. }
  195. if (isset($this->request->get['filter_quantity'])) {
  196. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  197. }
  198. if (isset($this->request->get['filter_status'])) {
  199. $url .= '&filter_status=' . $this->request->get['filter_status'];
  200. }
  201. if (isset($this->request->get['page'])) {
  202. $url .= '&page=' . $this->request->get['page'];
  203. }
  204. if (isset($this->request->get['sort'])) {
  205. $url .= '&sort=' . $this->request->get['sort'];
  206. }
  207. if (isset($this->request->get['order'])) {
  208. $url .= '&order=' . $this->request->get['order'];
  209. }
  210. $this->document->breadcrumbs = array();
  211. $this->document->breadcrumbs[] = array(
  212. 'href' => $this->url->https('common/home'),
  213. 'text' => $this->language->get('text_home'),
  214. 'separator' => FALSE
  215. );
  216. $this->document->breadcrumbs[] = array(
  217. 'href' => $this->url->https('catalog/product' . $url),
  218. 'text' => $this->language->get('heading_title'),
  219. 'separator' => ' :: '
  220. );
  221. $this->data['insert'] = $this->url->https('catalog/product/insert' . $url);
  222. $this->data['delete'] = $this->url->https('catalog/product/delete' . $url);
  223. $this->data['products'] = array();
  224. $data = array(
  225. 'filter_name' => $filter_name,
  226. 'filter_model' => $filter_model,
  227. 'filter_quantity' => $filter_quantity,
  228. 'filter_status' => $filter_status,
  229. 'sort' => $sort,
  230. 'order' => $order,
  231. 'start' => ($page - 1) * 10,
  232. 'limit' => 10
  233. );
  234. $product_total = $this->model_catalog_product->getTotalProducts($data);
  235. $results = $this->model_catalog_product->getProducts($data);
  236. foreach ($results as $result) {
  237. $action = array();
  238. $action[] = array(
  239. 'text' => $this->language->get('text_edit'),
  240. 'href' => $this->url->https('catalog/product/update&product_id=' . $result['product_id'] . $url)
  241. );
  242. $this->data['products'][] = array(
  243. 'product_id' => $result['product_id'],
  244. 'name' => $result['name'],
  245. 'model' => $result['model'],
  246. 'quantity' => $result['quantity'],
  247. 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
  248. 'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']),
  249. 'action' => $action
  250. );
  251. }
  252. $this->data['heading_title'] = $this->language->get('heading_title');
  253. $this->data['text_enabled'] = $this->language->get('text_enabled');
  254. $this->data['text_disabled'] = $this->language->get('text_disabled');
  255. $this->data['text_no_results'] = $this->language->get('text_no_results');
  256. $this->data['column_name'] = $this->language->get('column_name');
  257. $this->data['column_model'] = $this->language->get('column_model');
  258. $this->data['column_quantity'] = $this->language->get('column_quantity');
  259. $this->data['column_status'] = $this->language->get('column_status');
  260. $this->data['column_action'] = $this->language->get('column_action');
  261. $this->data['button_insert'] = $this->language->get('button_insert');
  262. $this->data['button_delete'] = $this->language->get('button_delete');
  263. $this->data['button_filter'] = $this->language->get('button_filter');
  264. if (isset($this->error['warning'])) {
  265. $this->data['error_warning'] = $this->error['warning'];
  266. } else {
  267. $this->data['error_warning'] = '';
  268. }
  269. if (isset($this->session->data['success'])) {
  270. $this->data['success'] = $this->session->data['success'];
  271. unset($this->session->data['success']);
  272. } else {
  273. $this->data['success'] = '';
  274. }
  275. $url = '';
  276. if (isset($this->request->get['filter_name'])) {
  277. $url .= '&filter_name=' . $this->request->get['filter_name'];
  278. }
  279. if (isset($this->request->get['filter_model'])) {
  280. $url .= '&filter_model=' . $this->request->get['filter_model'];
  281. }
  282. if (isset($this->request->get['filter_quantity'])) {
  283. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  284. }
  285. if (isset($this->request->get['filter_status'])) {
  286. $url .= '&filter_status=' . $this->request->get['filter_status'];
  287. }
  288. if ($order == 'ASC') {
  289. $url .= '&order=' . 'DESC';
  290. } else {
  291. $url .= '&order=' . 'ASC';
  292. }
  293. if (isset($this->request->get['page'])) {
  294. $url .= '&page=' . $this->request->get['page'];
  295. }
  296. $this->data['sort_name'] = $this->url->https('catalog/product&sort=pd.name' . $url);
  297. $this->data['sort_model'] = $this->url->https('catalog/product&sort=p.model' . $url);
  298. $this->data['sort_quantity'] = $this->url->https('catalog/product&sort=p.quantity' . $url);
  299. $this->data['sort_status'] = $this->url->https('catalog/product&sort=p.status' . $url);
  300. $this->data['sort_order'] = $this->url->https('catalog/product&sort=p.sort_order' . $url);
  301. $url = '';
  302. if (isset($this->request->get['filter_name'])) {
  303. $url .= '&filter_name=' . $this->request->get['filter_name'];
  304. }
  305. if (isset($this->request->get['filter_model'])) {
  306. $url .= '&filter_model=' . $this->request->get['filter_model'];
  307. }
  308. if (isset($this->request->get['filter_quantity'])) {
  309. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  310. }
  311. if (isset($this->request->get['filter_status'])) {
  312. $url .= '&filter_status=' . $this->request->get['filter_status'];
  313. }
  314. if (isset($this->request->get['sort'])) {
  315. $url .= '&sort=' . $this->request->get['sort'];
  316. }
  317. if (isset($this->request->get['order'])) {
  318. $url .= '&order=' . $this->request->get['order'];
  319. }
  320. $pagination = new Pagination();
  321. $pagination->total = $product_total;
  322. $pagination->page = $page;
  323. $pagination->limit = 10;
  324. $pagination->text = $this->language->get('text_pagination');
  325. $pagination->url = $this->url->https('catalog/product' . $url . '&page=%s');
  326. $this->data['pagination'] = $pagination->render();
  327. $this->data['filter_name'] = $filter_name;
  328. $this->data['filter_model'] = $filter_model;
  329. $this->data['filter_quantity'] = $filter_quantity;
  330. $this->data['filter_status'] = $filter_status;
  331. $this->data['sort'] = $sort;
  332. $this->data['order'] = $order;
  333. $this->template = 'catalog/product_list.tpl';
  334. $this->children = array(
  335. 'common/header',
  336. 'common/footer'
  337. );
  338. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  339. }
  340. private function getForm() {
  341. $this->data['heading_title'] = $this->language->get('heading_title');
  342. $this->data['text_enabled'] = $this->language->get('text_enabled');
  343. $this->data['text_disabled'] = $this->language->get('text_disabled');
  344. $this->data['text_none'] = $this->language->get('text_none');
  345. $this->data['text_yes'] = $this->language->get('text_yes');
  346. $this->data['text_no'] = $this->language->get('text_no');
  347. $this->data['text_plus'] = $this->language->get('text_plus');
  348. $this->data['text_minus'] = $this->language->get('text_minus');
  349. $this->data['entry_name'] = $this->language->get('entry_name');
  350. $this->data['entry_keyword'] = $this->language->get('entry_keyword');
  351. $this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
  352. $this->data['entry_description'] = $this->language->get('entry_description');
  353. $this->data['entry_model'] = $this->language->get('entry_model');
  354. $this->data['entry_sku'] = $this->language->get('entry_sku');
  355. $this->data['entry_location'] = $this->language->get('entry_location');
  356. $this->data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
  357. $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  358. $this->data['entry_date_available'] = $this->language->get('entry_date_available');
  359. $this->data['entry_quantity'] = $this->language->get('entry_quantity');
  360. $this->data['entry_stock_status'] = $this->language->get('entry_stock_status');
  361. $this->data['entry_status'] = $this->language->get('entry_status');
  362. $this->data['entry_tax_class'] = $this->language->get('entry_tax_class');
  363. $this->data['entry_price'] = $this->language->get('entry_price');
  364. $this->data['entry_subtract'] = $this->language->get('entry_subtract');
  365. $this->data['entry_weight_class'] = $this->language->get('entry_weight_class');
  366. $this->data['entry_weight'] = $this->language->get('entry_weight');
  367. $this->data['entry_dimension'] = $this->language->get('entry_dimension');
  368. $this->data['entry_measurement'] = $this->language->get('entry_measurement');
  369. $this->data['entry_image'] = $this->language->get('entry_image');
  370. $this->data['entry_download'] = $this->language->get('entry_download');
  371. $this->data['entry_category'] = $this->language->get('entry_category');
  372. $this->data['entry_related'] = $this->language->get('entry_related');
  373. $this->data['entry_option'] = $this->language->get('entry_option');
  374. $this->data['entry_option_value'] = $this->language->get('entry_option_value');
  375. $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
  376. $this->data['entry_prefix'] = $this->language->get('entry_prefix');
  377. $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  378. $this->data['entry_date_start'] = $this->language->get('entry_date_start');
  379. $this->data['entry_date_end'] = $this->language->get('entry_date_end');
  380. $this->data['entry_priority'] = $this->language->get('entry_priority');
  381. $this->data['button_save'] = $this->language->get('button_save');
  382. $this->data['button_cancel'] = $this->language->get('button_cancel');
  383. $this->data['button_add_option'] = $this->language->get('button_add_option');
  384. $this->data['button_add_option_value'] = $this->language->get('button_add_option_value');
  385. $this->data['button_add_discount'] = $this->language->get('button_add_discount');
  386. $this->data['button_add_special'] = $this->language->get('button_add_special');
  387. $this->data['button_add_image'] = $this->language->get('button_add_image');
  388. $this->data['button_remove'] = $this->language->get('button_remove');
  389. $this->data['tab_general'] = $this->language->get('tab_general');
  390. $this->data['tab_data'] = $this->language->get('tab_data');
  391. $this->data['tab_discount'] = $this->language->get('tab_discount');
  392. $this->data['tab_special'] = $this->language->get('tab_special');
  393. $this->data['tab_option'] = $this->language->get('tab_option');
  394. $this->data['tab_image'] = $this->language->get('tab_image');
  395. if (isset($this->error['warning'])) {
  396. $this->data['error_warning'] = $this->error['warning'];
  397. } else {
  398. $this->data['error_warning'] = '';
  399. }
  400. if (isset($this->error['name'])) {
  401. $this->data['error_name'] = $this->error['name'];
  402. } else {
  403. $this->data['error_name'] = '';
  404. }
  405. if (isset($this->error['meta_description'])) {
  406. $this->data['error_meta_description'] = $this->error['meta_description'];
  407. } else {
  408. $this->data['error_meta_description'] = '';
  409. }
  410. if (isset($this->error['description'])) {
  411. $this->data['error_description'] = $this->error['description'];
  412. } else {
  413. $this->data['error_description'] = '';
  414. }
  415. if (isset($this->error['model'])) {
  416. $this->data['error_model'] = $this->error['model'];
  417. } else {
  418. $this->data['error_model'] = '';
  419. }
  420. if (isset($this->error['date_available'])) {
  421. $this->data['error_date_available'] = $this->error['date_available'];
  422. } else {
  423. $this->data['error_date_available'] = '';
  424. }
  425. $url = '';
  426. if (isset($this->request->get['filter_name'])) {
  427. $url .= '&filter_name=' . $this->request->get['filter_name'];
  428. }
  429. if (isset($this->request->get['filter_model'])) {
  430. $url .= '&filter_model=' . $this->request->get['filter_model'];
  431. }
  432. if (isset($this->request->get['filter_quantity'])) {
  433. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  434. }
  435. if (isset($this->request->get['filter_status'])) {
  436. $url .= '&filter_status=' . $this->request->get['filter_status'];
  437. }
  438. if (isset($this->request->get['page'])) {
  439. $url .= '&page=' . $this->request->get['page'];
  440. }
  441. if (isset($this->request->get['sort'])) {
  442. $url .= '&sort=' . $this->request->get['sort'];
  443. }
  444. if (isset($this->request->get['order'])) {
  445. $url .= '&order=' . $this->request->get['order'];
  446. }
  447. $this->document->breadcrumbs = array();
  448. $this->document->breadcrumbs[] = array(
  449. 'href' => $this->url->https('common/home'),
  450. 'text' => $this->language->get('text_home'),
  451. 'separator' => FALSE
  452. );
  453. $this->document->breadcrumbs[] = array(
  454. 'href' => $this->url->https('catalog/product' . $url),
  455. 'text' => $this->language->get('heading_title'),
  456. 'separator' => ' :: '
  457. );
  458. if (!isset($this->request->get['product_id'])) {
  459. $this->data['action'] = $this->url->https('catalog/product/insert' . $url);
  460. } else {
  461. $this->data['action'] = $this->url->https('catalog/product/update&product_id=' . $this->request->get['product_id'] . $url);
  462. }
  463. $this->data['cancel'] = $this->url->https('catalog/product' . $url);
  464. if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  465. $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
  466. }
  467. $this->load->model('localisation/language');
  468. $this->data['languages'] = $this->model_localisation_language->getLanguages();
  469. if (isset($this->request->post['product_description'])) {
  470. $this->data['product_description'] = $this->request->post['product_description'];
  471. } elseif (isset($product_info)) {
  472. $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
  473. } else {
  474. $this->data['product_description'] = array();
  475. }
  476. if (isset($this->request->post['model'])) {
  477. $this->data['model'] = $this->request->post['model'];
  478. } elseif (isset($product_info)) {
  479. $this->data['model'] = $product_info['model'];
  480. } else {
  481. $this->data['model'] = '';
  482. }
  483. if (isset($this->request->post['sku'])) {
  484. $this->data['sku'] = $this->request->post['sku'];
  485. } elseif (isset($product_info)) {
  486. $this->data['sku'] = $product_info['sku'];
  487. } else {
  488. $this->data['sku'] = '';
  489. }
  490. if (isset($this->request->post['location'])) {
  491. $this->data['location'] = $this->request->post['location'];
  492. } elseif (isset($product_info)) {
  493. $this->data['location'] = $product_info['location'];
  494. } else {
  495. $this->data['location'] = '';
  496. }
  497. if (isset($this->request->post['keyword'])) {
  498. $this->data['keyword'] = $this->request->post['keyword'];
  499. } elseif (isset($product_info)) {
  500. $this->data['keyword'] = $product_info['keyword'];
  501. } else {
  502. $this->data['keyword'] = '';
  503. }
  504. $this->load->helper('image');
  505. if (isset($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
  506. $this->data['preview'] = image_resize($product_info['image'], 100, 100);
  507. } else {
  508. $this->data['preview'] = image_resize('no_image.jpg', 100, 100);
  509. }
  510. $this->load->model('catalog/manufacturer');
  511. $this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers();
  512. if (isset($this->request->post['manufacturer_id'])) {
  513. $this->data['manufacturer_id'] = $this->request->post['manufacturer_id'];
  514. } elseif (isset($product_info)) {
  515. $this->data['manufacturer_id'] = $product_info['manufacturer_id'];
  516. } else {
  517. $this->data['manufacturer_id'] = 0;
  518. }
  519. if (isset($this->request->post['shipping'])) {
  520. $this->data['shipping'] = $this->request->post['shipping'];
  521. } elseif (isset($product_info)) {
  522. $this->data['shipping'] = $product_info['shipping'];
  523. } else {
  524. $this->data['shipping'] = 1;
  525. }
  526. if (isset($this->request->post['date_available'])) {
  527. $this->data['date_available'] = $this->request->post['date_available'];
  528. } elseif (isset($product_info)) {
  529. $this->data['date_available'] = date('Y-m-d', strtotime($product_info['date_available']));
  530. } else {
  531. $this->data['date_available'] = date('Y-m-d', time());
  532. }
  533. if (isset($this->request->post['quantity'])) {
  534. $this->data['quantity'] = $this->request->post['quantity'];
  535. } elseif (isset($product_info)) {
  536. $this->data['quantity'] = $product_info['quantity'];
  537. } else {
  538. $this->data['quantity'] = 1;
  539. }
  540. $this->load->model('localisation/stock_status');
  541. $this->data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();
  542. if (isset($this->request->post['stock_status_id'])) {
  543. $this->data['stock_status_id'] = $this->request->post['stock_status_id'];
  544. } else if (isset($product_info)) {
  545. $this->data['stock_status_id'] = $product_info['stock_status_id'];
  546. } else {
  547. $this->data['stock_status_id'] = $this->config->get('config_stock_status_id');
  548. }
  549. if (isset($this->request->post['price'])) {
  550. $this->data['price'] = $this->request->post['price'];
  551. } else if (isset($product_info)) {
  552. $this->data['price'] = $product_info['price'];
  553. } else {
  554. $this->data['price'] = '';
  555. }
  556. if (isset($this->request->post['status'])) {
  557. $this->data['status'] = $this->request->post['status'];
  558. } else if (isset($product_info)) {
  559. $this->data['status'] = $product_info['status'];
  560. } else {
  561. $this->data['status'] = 1;
  562. }
  563. $this->load->model('localisation/tax_class');
  564. $this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
  565. if (isset($this->request->post['tax_class_id'])) {
  566. $this->data['tax_class_id'] = $this->request->post['tax_class_id'];
  567. } else if (isset($product_info)) {
  568. $this->data['tax_class_id'] = $product_info['tax_class_id'];
  569. } else {
  570. $this->data['tax_class_id'] = 0;
  571. }
  572. if (isset($this->request->post['weight'])) {
  573. $this->data['weight'] = $this->request->post['weight'];
  574. } else if (isset($product_info)) {
  575. $this->data['weight'] = $product_info['weight'];
  576. } else {
  577. $this->data['weight'] = '';
  578. }
  579. $this->load->model('localisation/weight_class');
  580. $this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
  581. if (isset($this->request->post['weight_class_id'])) {
  582. $this->data['weight_class_id'] = $this->request->post['weight_class_id'];
  583. } elseif (isset($product_info)) {
  584. $this->data['weight_class_id'] = $product_info['weight_class_id'];
  585. } else {
  586. $this->data['weight_class_id'] = $this->config->get('config_weight_class_id');
  587. }
  588. if (isset($this->request->post['length'])) {
  589. $this->data['length'] = $this->request->post['length'];
  590. } elseif (isset($product_info)) {
  591. $this->data['length'] = $product_info['length'];
  592. } else {
  593. $this->data['length'] = '';
  594. }
  595. if (isset($this->request->post['width'])) {
  596. $this->data['width'] = $this->request->post['width'];
  597. } elseif (isset($product_info)) {
  598. $this->data['width'] = $product_info['width'];
  599. } else {
  600. $this->data['width'] = '';
  601. }
  602. if (isset($this->request->post['height'])) {
  603. $this->data['height'] = $this->request->post['height'];
  604. } elseif (isset($product_info)) {
  605. $this->data['height'] = $product_info['height'];
  606. } else {
  607. $this->data['height'] = '';
  608. }
  609. $this->load->model('localisation/measurement_class');
  610. $this->data['measurement_classes'] = $this->model_localisation_measurement_class->getMeasurementClasses();
  611. if (isset($this->request->post['measurement_class_id'])) {
  612. $this->data['measurement_class_id'] = $this->request->post['measurement_class_id'];
  613. } elseif (isset($product_info)) {
  614. $this->data['measurement_class_id'] = $product_info['measurement_class_id'];
  615. } else {
  616. $this->data['measurement_class_id'] = $this->config->get('config_measurement_class_id');
  617. }
  618. if (isset($this->request->post['product_option'])) {
  619. $this->data['product_options'] = $this->request->post['product_option'];
  620. } elseif (isset($product_info)) {
  621. $this->data['product_options'] = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
  622. } else {
  623. $this->data['product_options'] = array();
  624. }
  625. $this->load->model('customer/customer_group');
  626. $this->data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
  627. if (isset($this->request->post['product_discount'])) {
  628. $this->data['product_discounts'] = $this->request->post['product_discount'];
  629. } elseif (isset($product_info)) {
  630. $this->data['product_discounts'] = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  631. } else {
  632. $this->data['product_discounts'] = array();
  633. }
  634. if (isset($this->request->post['product_special'])) {
  635. $this->data['product_specials'] = $this->request->post['product_special'];
  636. } elseif (isset($product_info)) {
  637. $this->data['product_specials'] = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']);
  638. } else {
  639. $this->data['product_specials'] = array();
  640. }
  641. $this->data['no_image'] = image_resize('no_image.jpg', 100, 100);
  642. $this->data['product_images'] = array();
  643. if (isset($product_info)) {
  644. $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  645. foreach ($results as $result) {
  646. if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
  647. $this->data['product_images'][] = array(
  648. 'preview' => image_resize($result['image'], 100, 100),#
  649. 'file' => $result['image']
  650. );
  651. } else {
  652. $this->data['product_images'][] = array(
  653. 'preview' => image_resize('no_image.jpg', 100, 100),
  654. 'file' => $result['image']
  655. );
  656. }
  657. }
  658. }
  659. $this->load->model('catalog/download');
  660. $this->data['downloads'] = $this->model_catalog_download->getDownloads();
  661. if (isset($this->request->post['product_download'])) {
  662. $this->data['product_download'] = $this->request->post['product_download'];
  663. } elseif (isset($product_info)) {
  664. $this->data['product_download'] = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']);
  665. } else {
  666. $this->data['product_download'] = array();
  667. }
  668. $this->load->model('catalog/category');
  669. $this->data['categories'] = $this->model_catalog_category->getCategories(0);
  670. if (isset($this->request->post['product_category'])) {
  671. $this->data['product_category'] = $this->request->post['product_category'];
  672. } elseif (isset($product_info)) {
  673. $this->data['product_category'] = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
  674. } else {
  675. $this->data['product_category'] = array();
  676. }
  677. if (isset($this->request->post['product_related'])) {
  678. $this->data['product_related'] = $this->request->post['product_related'];
  679. } elseif (isset($product_info)) {
  680. $this->data['product_related'] = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  681. } else {
  682. $this->data['product_related'] = array();
  683. }
  684. $this->template = 'catalog/product_form.tpl';
  685. $this->children = array(
  686. 'common/header',
  687. 'common/footer'
  688. );
  689. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  690. }
  691. private function validateForm() {
  692. if (!$this->user->hasPermission('modify', 'catalog/product')) {
  693. $this->error['warning'] = $this->language->get('error_permission');
  694. }
  695. foreach ($this->request->post['product_description'] as $language_id => $value) {
  696. if ((strlen(utf8_decode($value['name'])) < 3) || (strlen(utf8_decode($value['name'])) > 255)) {
  697. $this->error['name'][$language_id] = $this->language->get('error_name');
  698. }
  699. }
  700. if ((strlen(utf8_decode($this->request->post['model'])) < 3) || (strlen(utf8_decode($this->request->post['model'])) > 24)) {
  701. $this->error['model'] = $this->language->get('error_model');
  702. }
  703. if ($this->request->files['image']['name']) {
  704. if ((strlen(utf8_decode($this->request->files['image']['name'])) < 3) || (strlen(utf8_decode($this->request->files['image']['name'])) > 255)) {
  705. $this->error['warning'] = $this->language->get('error_filename');
  706. }
  707. $allowed = array(
  708. 'image/jpeg',
  709. 'image/pjpeg',
  710. 'image/png',
  711. 'image/x-png',
  712. 'image/gif'
  713. );
  714. if (!in_array($this->request->files['image']['type'], $allowed)) {
  715. $this->error['warning'] = $this->language->get('error_filetype');
  716. }
  717. if (!is_writable(DIR_IMAGE)) {
  718. $this->error['warning'] = $this->language->get('error_writable_image');
  719. }
  720. if (!is_writable(DIR_IMAGE . 'cache/')) {
  721. $this->error['warning'] = $this->language->get('error_writable_image_cache');
  722. }
  723. if ($this->request->files['image']['error'] != UPLOAD_ERR_OK) {
  724. $this->error['warning'] = $this->language->get('error_upload_' . $this->request->files['image']['error']);
  725. }
  726. }
  727. if (isset($this->request->files['product_image'])) {
  728. foreach (array_keys($this->request->files['product_image']['name']) as $key) {
  729. if ($this->request->files['product_image']['name'][$key]) {
  730. if ((strlen(utf8_decode($this->request->files['product_image']['name'][$key])) < 3) || (strlen(utf8_decode($this->request->files['product_image']['name'][$key])) > 255)) {
  731. $this->error['warning'] = $this->language->get('error_filename');
  732. }
  733. $allowed = array(
  734. 'image/jpeg',
  735. 'image/pjpeg',
  736. 'image/png',
  737. 'image/x-png',
  738. 'image/gif'
  739. );
  740. if (!in_array($this->request->files['product_image']['type'][$key], $allowed)) {
  741. $this->error['warning'] = $this->language->get('error_filetype');
  742. }
  743. if (!is_writable(DIR_IMAGE)) {
  744. $this->error['warning'] = $this->language->get('error_writable_image');
  745. }
  746. if (!is_writable(DIR_IMAGE . 'cache/')) {
  747. $this->error['warning'] = $this->language->get('error_writable_image_cache');
  748. }
  749. if ($this->request->files['product_image']['error'][$key] != UPLOAD_ERR_OK) {
  750. $this->error['warning'] = $this->language->get('error_upload_' . $this->request->files['product_image']['error'][$key]);
  751. }
  752. }
  753. }
  754. }
  755. if (!$this->error) {
  756. return TRUE;
  757. } else {
  758. return FALSE;
  759. }
  760. }
  761. public function category() {
  762. $this->load->model('catalog/product');
  763. if (isset($this->request->get['category_id'])) {
  764. $category_id = $this->request->get['category_id'];
  765. } else {
  766. $category_id = 0;
  767. }
  768. $product_data = array();
  769. $results = $this->model_catalog_product->getProductsByCategoryId($category_id);
  770. foreach ($results as $result) {
  771. $product_data[] = array(
  772. 'product_id' => $result['product_id'],
  773. 'name' => $result['name']
  774. );
  775. }
  776. $this->load->library('json');
  777. $this->response->setOutput(Json::encode($product_data));
  778. }
  779. public function related() {
  780. $this->load->model('catalog/product');
  781. if (isset($this->request->post['product_related'])) {
  782. $products = $this->request->post['product_related'];
  783. } else {
  784. $products = array();
  785. }
  786. $product_data = array();
  787. foreach ($products as $product_id) {
  788. $product_info = $this->model_catalog_product->getProduct($product_id);
  789. if ($product_info) {
  790. $product_data[] = array(
  791. 'product_id' => $product_info['product_id'],
  792. 'name' => $product_info['name']
  793. );
  794. }
  795. }
  796. $this->load->library('json');
  797. $this->response->setOutput(Json::encode($product_data));
  798. }
  799. private function validateDelete() {
  800. if (!$this->user->hasPermission('modify', 'catalog/product')) {
  801. $this->error['warning'] = $this->language->get('error_permission');
  802. }
  803. if (!$this->error) {
  804. return TRUE;
  805. } else {
  806. return FALSE;
  807. }
  808. }
  809. }
  810. ?>