paketonlinestore

product.php controller file

Feb 2nd, 2014
358
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class ControllerCatalogProduct extends Controller {
  3. private $error = array();
  4.  
  5. public function index() {
  6. $this->load->language('catalog/product');
  7.  
  8. $this->document->title = $this->language->get('heading_title');
  9.  
  10. $this->load->model('catalog/product');
  11.  
  12. $this->getList();
  13. }
  14.  
  15. public function insert() {
  16. $this->load->language('catalog/product');
  17.  
  18. $this->document->title = $this->language->get('heading_title');
  19.  
  20. $this->load->model('catalog/product');
  21.  
  22. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  23. $this->model_catalog_product->addProduct($this->request->post);
  24.  
  25. $this->session->data['success'] = $this->language->get('text_success');
  26.  
  27. $url = '';
  28.  
  29. if (isset($this->request->get['filter_name'])) {
  30. $url .= '&filter_name=' . $this->request->get['filter_name'];
  31. }
  32.  
  33. if (isset($this->request->get['filter_model'])) {
  34. $url .= '&filter_model=' . $this->request->get['filter_model'];
  35. }
  36.  
  37. if (isset($this->request->get['filter_quantity'])) {
  38. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  39. }
  40.  
  41. if (isset($this->request->get['filter_status'])) {
  42. $url .= '&filter_status=' . $this->request->get['filter_status'];
  43. }
  44.  
  45. if (isset($this->request->get['page'])) {
  46. $url .= '&page=' . $this->request->get['page'];
  47. }
  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. $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  58. }
  59.  
  60. $this->getForm();
  61. }
  62.  
  63. public function update() {
  64. $this->load->language('catalog/product');
  65.  
  66. $this->document->title = $this->language->get('heading_title');
  67.  
  68. $this->load->model('catalog/product');
  69.  
  70. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  71. $this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);
  72.  
  73. $this->session->data['success'] = $this->language->get('text_success');
  74.  
  75. $url = '';
  76.  
  77. if (isset($this->request->get['filter_name'])) {
  78. $url .= '&filter_name=' . $this->request->get['filter_name'];
  79. }
  80.  
  81. if (isset($this->request->get['filter_model'])) {
  82. $url .= '&filter_model=' . $this->request->get['filter_model'];
  83. }
  84.  
  85. if (isset($this->request->get['filter_quantity'])) {
  86. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  87. }
  88.  
  89. if (isset($this->request->get['filter_status'])) {
  90. $url .= '&filter_status=' . $this->request->get['filter_status'];
  91. }
  92.  
  93. if (isset($this->request->get['page'])) {
  94. $url .= '&page=' . $this->request->get['page'];
  95. }
  96.  
  97. if (isset($this->request->get['sort'])) {
  98. $url .= '&sort=' . $this->request->get['sort'];
  99. }
  100.  
  101. if (isset($this->request->get['order'])) {
  102. $url .= '&order=' . $this->request->get['order'];
  103. }
  104.  
  105. $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  106. }
  107.  
  108. $this->getForm();
  109. }
  110.  
  111. public function delete() {
  112. $this->load->language('catalog/product');
  113.  
  114. $this->document->title = $this->language->get('heading_title');
  115.  
  116. $this->load->model('catalog/product');
  117.  
  118. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  119. foreach ($this->request->post['selected'] as $product_id) {
  120. $this->model_catalog_product->deleteProduct($product_id);
  121. }
  122.  
  123. $this->session->data['success'] = $this->language->get('text_success');
  124.  
  125. $url = '';
  126.  
  127. if (isset($this->request->get['filter_name'])) {
  128. $url .= '&filter_name=' . $this->request->get['filter_name'];
  129. }
  130.  
  131. if (isset($this->request->get['filter_model'])) {
  132. $url .= '&filter_model=' . $this->request->get['filter_model'];
  133. }
  134.  
  135. if (isset($this->request->get['filter_quantity'])) {
  136. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  137. }
  138.  
  139. if (isset($this->request->get['filter_status'])) {
  140. $url .= '&filter_status=' . $this->request->get['filter_status'];
  141. }
  142.  
  143. if (isset($this->request->get['page'])) {
  144. $url .= '&page=' . $this->request->get['page'];
  145. }
  146.  
  147. if (isset($this->request->get['sort'])) {
  148. $url .= '&sort=' . $this->request->get['sort'];
  149. }
  150.  
  151. if (isset($this->request->get['order'])) {
  152. $url .= '&order=' . $this->request->get['order'];
  153. }
  154.  
  155. $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  156. }
  157.  
  158. $this->getList();
  159. }
  160.  
  161. public function copy() {
  162. $this->load->language('catalog/product');
  163.  
  164. $this->document->title = $this->language->get('heading_title');
  165.  
  166. $this->load->model('catalog/product');
  167.  
  168. if (isset($this->request->post['selected']) && $this->validateCopy()) {
  169. foreach ($this->request->post['selected'] as $product_id) {
  170. $this->model_catalog_product->copyProduct($product_id);
  171. }
  172.  
  173. $this->session->data['success'] = $this->language->get('text_success');
  174.  
  175. $url = '';
  176.  
  177. if (isset($this->request->get['filter_name'])) {
  178. $url .= '&filter_name=' . $this->request->get['filter_name'];
  179. }
  180.  
  181. if (isset($this->request->get['filter_model'])) {
  182. $url .= '&filter_model=' . $this->request->get['filter_model'];
  183. }
  184.  
  185. if (isset($this->request->get['filter_quantity'])) {
  186. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  187. }
  188.  
  189. if (isset($this->request->get['filter_status'])) {
  190. $url .= '&filter_status=' . $this->request->get['filter_status'];
  191. }
  192.  
  193. if (isset($this->request->get['page'])) {
  194. $url .= '&page=' . $this->request->get['page'];
  195. }
  196.  
  197. if (isset($this->request->get['sort'])) {
  198. $url .= '&sort=' . $this->request->get['sort'];
  199. }
  200.  
  201. if (isset($this->request->get['order'])) {
  202. $url .= '&order=' . $this->request->get['order'];
  203. }
  204.  
  205. $this->redirect(HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url);
  206. }
  207.  
  208. $this->getList();
  209. }
  210.  
  211. private function getList() {
  212. if (isset($this->request->get['page'])) {
  213. $page = $this->request->get['page'];
  214. } else {
  215. $page = 1;
  216. }
  217.  
  218. if (isset($this->request->get['sort'])) {
  219. $sort = $this->request->get['sort'];
  220. } else {
  221. $sort = 'pd.name';
  222. }
  223.  
  224. if (isset($this->request->get['order'])) {
  225. $order = $this->request->get['order'];
  226. } else {
  227. $order = 'ASC';
  228. }
  229.  
  230. if (isset($this->request->get['filter_name'])) {
  231. $filter_name = $this->request->get['filter_name'];
  232. } else {
  233. $filter_name = NULL;
  234. }
  235.  
  236. if (isset($this->request->get['filter_model'])) {
  237. $filter_model = $this->request->get['filter_model'];
  238. } else {
  239. $filter_model = NULL;
  240. }
  241.  
  242. if (isset($this->request->get['filter_quantity'])) {
  243. $filter_quantity = $this->request->get['filter_quantity'];
  244. } else {
  245. $filter_quantity = NULL;
  246. }
  247.  
  248. if (isset($this->request->get['filter_status'])) {
  249. $filter_status = $this->request->get['filter_status'];
  250. } else {
  251. $filter_status = NULL;
  252. }
  253.  
  254. $url = '';
  255.  
  256. if (isset($this->request->get['filter_name'])) {
  257. $url .= '&filter_name=' . $this->request->get['filter_name'];
  258. }
  259.  
  260. if (isset($this->request->get['filter_model'])) {
  261. $url .= '&filter_model=' . $this->request->get['filter_model'];
  262. }
  263.  
  264. if (isset($this->request->get['filter_quantity'])) {
  265. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  266. }
  267.  
  268. if (isset($this->request->get['filter_status'])) {
  269. $url .= '&filter_status=' . $this->request->get['filter_status'];
  270. }
  271.  
  272. if (isset($this->request->get['page'])) {
  273. $url .= '&page=' . $this->request->get['page'];
  274. }
  275.  
  276. if (isset($this->request->get['sort'])) {
  277. $url .= '&sort=' . $this->request->get['sort'];
  278. }
  279.  
  280. if (isset($this->request->get['order'])) {
  281. $url .= '&order=' . $this->request->get['order'];
  282. }
  283.  
  284. $this->document->breadcrumbs = array();
  285.  
  286. $this->document->breadcrumbs[] = array(
  287. 'href' => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
  288. 'text' => $this->language->get('text_home'),
  289. 'separator' => FALSE
  290. );
  291.  
  292. $this->document->breadcrumbs[] = array(
  293. 'href' => HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url,
  294. 'text' => $this->language->get('heading_title'),
  295. 'separator' => ' :: '
  296. );
  297.  
  298. $this->data['insert'] = HTTPS_SERVER . 'index.php?route=catalog/product/insert&token=' . $this->session->data['token'] . $url;
  299. $this->data['copy'] = HTTPS_SERVER . 'index.php?route=catalog/product/copy&token=' . $this->session->data['token'] . $url;
  300. $this->data['delete'] = HTTPS_SERVER . 'index.php?route=catalog/product/delete&token=' . $this->session->data['token'] . $url;
  301.  
  302. $this->data['products'] = array();
  303.  
  304. $data = array(
  305. 'filter_name' => $filter_name,
  306. 'filter_model' => $filter_model,
  307. 'filter_quantity' => $filter_quantity,
  308. 'filter_status' => $filter_status,
  309. 'sort' => $sort,
  310. 'order' => $order,
  311. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  312. 'limit' => $this->config->get('config_admin_limit')
  313. );
  314.  
  315. $this->load->model('tool/image');
  316.  
  317. $product_total = $this->model_catalog_product->getTotalProducts($data);
  318.  
  319. $results = $this->model_catalog_product->getProducts($data);
  320.  
  321. foreach ($results as $result) {
  322. $action = array();
  323.  
  324. $action[] = array(
  325. 'text' => $this->language->get('text_edit'),
  326. 'href' => HTTPS_SERVER . 'index.php?route=catalog/product/update&token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url
  327. );
  328.  
  329. if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
  330. $image = $this->model_tool_image->resize($result['image'], 40, 40);
  331. } else {
  332. $image = $this->model_tool_image->resize('no_image.jpg', 40, 40);
  333. }
  334.  
  335. $this->data['products'][] = array(
  336. 'product_id' => $result['product_id'],
  337. 'name' => $result['name'],
  338. 'model' => $result['model'],
  339. 'image' => $image,
  340. 'quantity' => $result['quantity'],
  341. 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
  342. 'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']),
  343. 'action' => $action
  344. );
  345. }
  346.  
  347. $this->data['heading_title'] = $this->language->get('heading_title');
  348.  
  349. $this->data['text_enabled'] = $this->language->get('text_enabled');
  350. $this->data['text_disabled'] = $this->language->get('text_disabled');
  351. $this->data['text_no_results'] = $this->language->get('text_no_results');
  352. $this->data['text_image_manager'] = $this->language->get('text_image_manager');
  353.  
  354. $this->data['column_image'] = $this->language->get('column_image');
  355. $this->data['column_name'] = $this->language->get('column_name');
  356. $this->data['column_model'] = $this->language->get('column_model');
  357. $this->data['column_quantity'] = $this->language->get('column_quantity');
  358. $this->data['column_status'] = $this->language->get('column_status');
  359. $this->data['column_action'] = $this->language->get('column_action');
  360.  
  361. $this->data['button_copy'] = $this->language->get('button_copy');
  362. $this->data['button_insert'] = $this->language->get('button_insert');
  363. $this->data['button_delete'] = $this->language->get('button_delete');
  364. $this->data['button_filter'] = $this->language->get('button_filter');
  365.  
  366. $this->data['token'] = $this->session->data['token'];
  367.  
  368. if (isset($this->error['warning'])) {
  369. $this->data['error_warning'] = $this->error['warning'];
  370. } else {
  371. $this->data['error_warning'] = '';
  372. }
  373.  
  374. if (isset($this->session->data['success'])) {
  375. $this->data['success'] = $this->session->data['success'];
  376.  
  377. unset($this->session->data['success']);
  378. } else {
  379. $this->data['success'] = '';
  380. }
  381.  
  382. $url = '';
  383.  
  384. if (isset($this->request->get['filter_name'])) {
  385. $url .= '&filter_name=' . $this->request->get['filter_name'];
  386. }
  387.  
  388. if (isset($this->request->get['filter_model'])) {
  389. $url .= '&filter_model=' . $this->request->get['filter_model'];
  390. }
  391.  
  392. if (isset($this->request->get['filter_quantity'])) {
  393. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  394. }
  395.  
  396. if (isset($this->request->get['filter_status'])) {
  397. $url .= '&filter_status=' . $this->request->get['filter_status'];
  398. }
  399.  
  400. if ($order == 'ASC') {
  401. $url .= '&order=DESC';
  402. } else {
  403. $url .= '&order=ASC';
  404. }
  405.  
  406. if (isset($this->request->get['page'])) {
  407. $url .= '&page=' . $this->request->get['page'];
  408. }
  409.  
  410. $this->data['sort_name'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=pd.name' . $url;
  411. $this->data['sort_model'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.model' . $url;
  412. $this->data['sort_quantity'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.quantity' . $url;
  413. $this->data['sort_status'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.status' . $url;
  414. $this->data['sort_order'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . '&sort=p.sort_order' . $url;
  415.  
  416. $url = '';
  417.  
  418. if (isset($this->request->get['filter_name'])) {
  419. $url .= '&filter_name=' . $this->request->get['filter_name'];
  420. }
  421.  
  422. if (isset($this->request->get['filter_model'])) {
  423. $url .= '&filter_model=' . $this->request->get['filter_model'];
  424. }
  425.  
  426. if (isset($this->request->get['filter_quantity'])) {
  427. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  428. }
  429.  
  430. if (isset($this->request->get['filter_status'])) {
  431. $url .= '&filter_status=' . $this->request->get['filter_status'];
  432. }
  433.  
  434. if (isset($this->request->get['sort'])) {
  435. $url .= '&sort=' . $this->request->get['sort'];
  436. }
  437.  
  438. if (isset($this->request->get['order'])) {
  439. $url .= '&order=' . $this->request->get['order'];
  440. }
  441.  
  442. $pagination = new Pagination();
  443. $pagination->total = $product_total;
  444. $pagination->page = $page;
  445. $pagination->limit = $this->config->get('config_admin_limit');
  446. $pagination->text = $this->language->get('text_pagination');
  447. $pagination->url = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url . '&page={page}';
  448.  
  449. $this->data['pagination'] = $pagination->render();
  450.  
  451. $this->data['filter_name'] = $filter_name;
  452. $this->data['filter_model'] = $filter_model;
  453. $this->data['filter_quantity'] = $filter_quantity;
  454. $this->data['filter_status'] = $filter_status;
  455.  
  456. $this->data['sort'] = $sort;
  457. $this->data['order'] = $order;
  458.  
  459. $this->template = 'catalog/product_list.tpl';
  460. $this->children = array(
  461. 'common/header',
  462. 'common/footer'
  463. );
  464.  
  465. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  466. }
  467.  
  468. private function getForm() {
  469. $this->data['heading_title'] = $this->language->get('heading_title');
  470.  
  471. $this->data['text_enabled'] = $this->language->get('text_enabled');
  472. $this->data['text_disabled'] = $this->language->get('text_disabled');
  473. $this->data['text_none'] = $this->language->get('text_none');
  474. $this->data['text_yes'] = $this->language->get('text_yes');
  475. $this->data['text_no'] = $this->language->get('text_no');
  476. $this->data['text_plus'] = $this->language->get('text_plus');
  477. $this->data['text_minus'] = $this->language->get('text_minus');
  478. $this->data['text_default'] = $this->language->get('text_default');
  479. $this->data['text_image_manager'] = $this->language->get('text_image_manager');
  480. $this->data['text_option'] = $this->language->get('text_option');
  481. $this->data['text_option_value'] = $this->language->get('text_option_value');
  482. $this->data['text_select'] = $this->language->get('text_select');
  483. $this->data['text_none'] = $this->language->get('text_none');
  484.  
  485. $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  486. $this->data['tab_links'] = $this->language->get('tab_links');
  487.  
  488. $this->data['entry_name'] = $this->language->get('entry_name');
  489. $this->data['entry_meta_keywords'] = $this->language->get('entry_meta_keywords');
  490. $this->data['entry_meta_description'] = $this->language->get('entry_meta_description');
  491. $this->data['entry_description'] = $this->language->get('entry_description');
  492. $this->data['entry_store'] = $this->language->get('entry_store');
  493. $this->data['entry_keyword'] = $this->language->get('entry_keyword');
  494. $this->data['entry_model'] = $this->language->get('entry_model');
  495. $this->data['entry_sku'] = $this->language->get('entry_sku');
  496. $this->data['entry_location'] = $this->language->get('entry_location');
  497. $this->data['entry_minimum'] = $this->language->get('entry_minimum');
  498. $this->data['entry_manufacturer'] = $this->language->get('entry_manufacturer');
  499. $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  500. $this->data['entry_date_available'] = $this->language->get('entry_date_available');
  501. $this->data['entry_quantity'] = $this->language->get('entry_quantity');
  502. $this->data['entry_stock_status'] = $this->language->get('entry_stock_status');
  503. $this->data['entry_status'] = $this->language->get('entry_status');
  504. $this->data['entry_tax_class'] = $this->language->get('entry_tax_class');
  505. $this->data['entry_price'] = $this->language->get('entry_price');
  506. $this->data['entry_cost'] = $this->language->get('entry_cost');
  507. $this->data['entry_subtract'] = $this->language->get('entry_subtract');
  508. $this->data['entry_weight_class'] = $this->language->get('entry_weight_class');
  509. $this->data['entry_weight'] = $this->language->get('entry_weight');
  510. $this->data['entry_dimension'] = $this->language->get('entry_dimension');
  511. $this->data['entry_length'] = $this->language->get('entry_length');
  512. $this->data['entry_image'] = $this->language->get('entry_image');
  513. $this->data['entry_download'] = $this->language->get('entry_download');
  514. $this->data['entry_category'] = $this->language->get('entry_category');
  515. $this->data['entry_related'] = $this->language->get('entry_related');
  516. $this->data['entry_option'] = $this->language->get('entry_option');
  517. $this->data['entry_option_value'] = $this->language->get('entry_option_value');
  518. $this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
  519. $this->data['entry_prefix'] = $this->language->get('entry_prefix');
  520. $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  521. $this->data['entry_date_start'] = $this->language->get('entry_date_start');
  522. $this->data['entry_date_end'] = $this->language->get('entry_date_end');
  523. $this->data['entry_priority'] = $this->language->get('entry_priority');
  524. $this->data['entry_tags'] = $this->language->get('entry_tags');
  525.  
  526. $this->data['button_save'] = $this->language->get('button_save');
  527. $this->data['button_cancel'] = $this->language->get('button_cancel');
  528. $this->data['button_add_option'] = $this->language->get('button_add_option');
  529. $this->data['button_add_option_value'] = $this->language->get('button_add_option_value');
  530. $this->data['button_add_discount'] = $this->language->get('button_add_discount');
  531. $this->data['button_add_special'] = $this->language->get('button_add_special');
  532. $this->data['button_add_image'] = $this->language->get('button_add_image');
  533. $this->data['button_remove'] = $this->language->get('button_remove');
  534.  
  535. $this->data['tab_general'] = $this->language->get('tab_general');
  536. $this->data['tab_data'] = $this->language->get('tab_data');
  537. $this->data['tab_discount'] = $this->language->get('tab_discount');
  538. $this->data['tab_special'] = $this->language->get('tab_special');
  539. $this->data['tab_option'] = $this->language->get('tab_option');
  540. $this->data['tab_image'] = $this->language->get('tab_image');
  541.  
  542. if (isset($this->error['warning'])) {
  543. $this->data['error_warning'] = $this->error['warning'];
  544. } else {
  545. $this->data['error_warning'] = '';
  546. }
  547.  
  548. if (isset($this->error['name'])) {
  549. $this->data['error_name'] = $this->error['name'];
  550. } else {
  551. $this->data['error_name'] = '';
  552. }
  553.  
  554. if (isset($this->error['meta_description'])) {
  555. $this->data['error_meta_description'] = $this->error['meta_description'];
  556. } else {
  557. $this->data['error_meta_description'] = '';
  558. }
  559.  
  560. if (isset($this->error['description'])) {
  561. $this->data['error_description'] = $this->error['description'];
  562. } else {
  563. $this->data['error_description'] = '';
  564. }
  565.  
  566. if (isset($this->error['model'])) {
  567. $this->data['error_model'] = $this->error['model'];
  568. } else {
  569. $this->data['error_model'] = '';
  570. }
  571.  
  572. if (isset($this->error['date_available'])) {
  573. $this->data['error_date_available'] = $this->error['date_available'];
  574. } else {
  575. $this->data['error_date_available'] = '';
  576. }
  577.  
  578. $url = '';
  579.  
  580. if (isset($this->request->get['filter_name'])) {
  581. $url .= '&filter_name=' . $this->request->get['filter_name'];
  582. }
  583.  
  584. if (isset($this->request->get['filter_model'])) {
  585. $url .= '&filter_model=' . $this->request->get['filter_model'];
  586. }
  587.  
  588. if (isset($this->request->get['filter_quantity'])) {
  589. $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];
  590. }
  591.  
  592. if (isset($this->request->get['filter_status'])) {
  593. $url .= '&filter_status=' . $this->request->get['filter_status'];
  594. }
  595.  
  596. if (isset($this->request->get['page'])) {
  597. $url .= '&page=' . $this->request->get['page'];
  598. }
  599.  
  600. if (isset($this->request->get['sort'])) {
  601. $url .= '&sort=' . $this->request->get['sort'];
  602. }
  603.  
  604. if (isset($this->request->get['order'])) {
  605. $url .= '&order=' . $this->request->get['order'];
  606. }
  607.  
  608. $this->document->breadcrumbs = array();
  609.  
  610. $this->document->breadcrumbs[] = array(
  611. 'href' => HTTPS_SERVER . 'index.php?route=common/home&token=' . $this->session->data['token'],
  612. 'text' => $this->language->get('text_home'),
  613. 'separator' => FALSE
  614. );
  615.  
  616. $this->document->breadcrumbs[] = array(
  617. 'href' => HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url,
  618. 'text' => $this->language->get('heading_title'),
  619. 'separator' => ' :: '
  620. );
  621.  
  622. if (!isset($this->request->get['product_id'])) {
  623. $this->data['action'] = HTTPS_SERVER . 'index.php?route=catalog/product/insert&token=' . $this->session->data['token'] . $url;
  624. } else {
  625. $this->data['action'] = HTTPS_SERVER . 'index.php?route=catalog/product/update&token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'] . $url;
  626. }
  627.  
  628. $this->data['cancel'] = HTTPS_SERVER . 'index.php?route=catalog/product&token=' . $this->session->data['token'] . $url;
  629.  
  630. $this->data['token'] = $this->session->data['token'];
  631.  
  632. if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  633. $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
  634. }
  635.  
  636. $this->load->model('localisation/language');
  637.  
  638. $this->data['languages'] = $this->model_localisation_language->getLanguages();
  639.  
  640. if (isset($this->request->post['product_description'])) {
  641. $this->data['product_description'] = $this->request->post['product_description'];
  642. } elseif (isset($product_info)) {
  643. $this->data['product_description'] = $this->model_catalog_product->getProductDescriptions($this->request->get['product_id']);
  644. } else {
  645. $this->data['product_description'] = array();
  646. }
  647.  
  648. if (isset($this->request->post['model'])) {
  649. $this->data['model'] = $this->request->post['model'];
  650. } elseif (isset($product_info)) {
  651. $this->data['model'] = $product_info['model'];
  652. } else {
  653. $this->data['model'] = '';
  654. }
  655.  
  656. if (isset($this->request->post['sku'])) {
  657. $this->data['sku'] = $this->request->post['sku'];
  658. } elseif (isset($product_info)) {
  659. $this->data['sku'] = $product_info['sku'];
  660. } else {
  661. $this->data['sku'] = '';
  662. }
  663.  
  664. if (isset($this->request->post['location'])) {
  665. $this->data['location'] = $this->request->post['location'];
  666. } elseif (isset($product_info)) {
  667. $this->data['location'] = $product_info['location'];
  668. } else {
  669. $this->data['location'] = '';
  670. }
  671.  
  672. $this->load->model('setting/store');
  673.  
  674. $this->data['stores'] = $this->model_setting_store->getStores();
  675.  
  676. if (isset($this->request->post['product_store'])) {
  677. $this->data['product_store'] = $this->request->post['product_store'];
  678. } elseif (isset($product_info)) {
  679. $this->data['product_store'] = $this->model_catalog_product->getProductStores($this->request->get['product_id']);
  680. } else {
  681. $this->data['product_store'] = array(0);
  682. }
  683.  
  684. if (isset($this->request->post['keyword'])) {
  685. $this->data['keyword'] = $this->request->post['keyword'];
  686. } elseif (isset($product_info)) {
  687. $this->data['keyword'] = $product_info['keyword'];
  688. } else {
  689. $this->data['keyword'] = '';
  690. }
  691.  
  692. if (isset($this->request->post['product_tags'])) {
  693. $this->data['product_tags'] = $this->request->post['product_tags'];
  694. } elseif (isset($product_info)) {
  695. $this->data['product_tags'] = $this->model_catalog_product->getProductTags($this->request->get['product_id']);
  696. } else {
  697. $this->data['product_tags'] = array();
  698. }
  699.  
  700. if (isset($this->request->post['image'])) {
  701. $this->data['image'] = $this->request->post['image'];
  702. } elseif (isset($product_info)) {
  703. $this->data['image'] = $product_info['image'];
  704. } else {
  705. $this->data['image'] = '';
  706. }
  707.  
  708. $this->load->model('tool/image');
  709.  
  710. if (isset($product_info) && $product_info['image'] && file_exists(DIR_IMAGE . $product_info['image'])) {
  711. $this->data['preview'] = $this->model_tool_image->resize($product_info['image'], 100, 100);
  712. } else {
  713. $this->data['preview'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
  714. }
  715.  
  716. $this->load->model('catalog/manufacturer');
  717.  
  718. $this->data['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers();
  719.  
  720. if (isset($this->request->post['manufacturer_id'])) {
  721. $this->data['manufacturer_id'] = $this->request->post['manufacturer_id'];
  722. } elseif (isset($product_info)) {
  723. $this->data['manufacturer_id'] = $product_info['manufacturer_id'];
  724. } else {
  725. $this->data['manufacturer_id'] = 0;
  726. }
  727.  
  728. if (isset($this->request->post['shipping'])) {
  729. $this->data['shipping'] = $this->request->post['shipping'];
  730. } elseif (isset($product_info)) {
  731. $this->data['shipping'] = $product_info['shipping'];
  732. } else {
  733. $this->data['shipping'] = 1;
  734. }
  735.  
  736. if (isset($this->request->post['date_available'])) {
  737. $this->data['date_available'] = $this->request->post['date_available'];
  738. } elseif (isset($product_info)) {
  739. $this->data['date_available'] = date('Y-m-d', strtotime($product_info['date_available']));
  740. } else {
  741. $this->data['date_available'] = date('Y-m-d', time()-86400);
  742. }
  743.  
  744. if (isset($this->request->post['quantity'])) {
  745. $this->data['quantity'] = $this->request->post['quantity'];
  746. } elseif (isset($product_info)) {
  747. $this->data['quantity'] = $product_info['quantity'];
  748. } else {
  749. $this->data['quantity'] = 1;
  750. }
  751.  
  752. if (isset($this->request->post['minimum'])) {
  753. $this->data['minimum'] = $this->request->post['minimum'];
  754. } elseif (isset($product_info)) {
  755. $this->data['minimum'] = $product_info['minimum'];
  756. } else {
  757. $this->data['minimum'] = 1;
  758. }
  759.  
  760. if (isset($this->request->post['subtract'])) {
  761. $this->data['subtract'] = $this->request->post['subtract'];
  762. } elseif (isset($product_info)) {
  763. $this->data['subtract'] = $product_info['subtract'];
  764. } else {
  765. $this->data['subtract'] = 1;
  766. }
  767.  
  768. if (isset($this->request->post['sort_order'])) {
  769. $this->data['sort_order'] = $this->request->post['sort_order'];
  770. } elseif (isset($product_info)) {
  771. $this->data['sort_order'] = $product_info['sort_order'];
  772. } else {
  773. $this->data['sort_order'] = 1;
  774. }
  775.  
  776. $this->load->model('localisation/stock_status');
  777.  
  778. $this->data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();
  779.  
  780. if (isset($this->request->post['stock_status_id'])) {
  781. $this->data['stock_status_id'] = $this->request->post['stock_status_id'];
  782. } else if (isset($product_info)) {
  783. $this->data['stock_status_id'] = $product_info['stock_status_id'];
  784. } else {
  785. $this->data['stock_status_id'] = $this->config->get('config_stock_status_id');
  786. }
  787.  
  788. if (isset($this->request->post['price'])) {
  789. $this->data['price'] = $this->request->post['price'];
  790. } else if (isset($product_info)) {
  791. $this->data['price'] = $product_info['price'];
  792. } else {
  793. $this->data['price'] = '';
  794. }
  795.  
  796. if (isset($this->request->post['cost'])) {
  797. $this->data['cost'] = $this->request->post['cost'];
  798. } else if (isset($product_info)) {
  799. $this->data['cost'] = $product_info['cost'];
  800. } else {
  801. $this->data['cost'] = '';
  802. }
  803.  
  804. if (isset($this->request->post['status'])) {
  805. $this->data['status'] = $this->request->post['status'];
  806. } else if (isset($product_info)) {
  807. $this->data['status'] = $product_info['status'];
  808. } else {
  809. $this->data['status'] = 1;
  810. }
  811.  
  812. $this->load->model('localisation/tax_class');
  813.  
  814. $this->data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses();
  815.  
  816. if (isset($this->request->post['tax_class_id'])) {
  817. $this->data['tax_class_id'] = $this->request->post['tax_class_id'];
  818. } else if (isset($product_info)) {
  819. $this->data['tax_class_id'] = $product_info['tax_class_id'];
  820. } else {
  821. $this->data['tax_class_id'] = 0;
  822. }
  823.  
  824. if (isset($this->request->post['weight'])) {
  825. $this->data['weight'] = $this->request->post['weight'];
  826. } else if (isset($product_info)) {
  827. $this->data['weight'] = $product_info['weight'];
  828. } else {
  829. $this->data['weight'] = '';
  830. }
  831.  
  832. $this->load->model('localisation/weight_class');
  833.  
  834. $this->data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses();
  835.  
  836. $weight_info = $this->model_localisation_weight_class->getWeightClassDescriptionByUnit($this->config->get('config_weight_class'));
  837.  
  838. if (isset($this->request->post['weight_class_id'])) {
  839. $this->data['weight_class_id'] = $this->request->post['weight_class_id'];
  840. } elseif (isset($product_info)) {
  841. $this->data['weight_class_id'] = $product_info['weight_class_id'];
  842. } elseif (isset($weight_info)) {
  843. $this->data['weight_class_id'] = $weight_info['weight_class_id'];
  844. } else {
  845. $this->data['weight_class_id'] = '';
  846. }
  847.  
  848. if (isset($this->request->post['length'])) {
  849. $this->data['length'] = $this->request->post['length'];
  850. } elseif (isset($product_info)) {
  851. $this->data['length'] = $product_info['length'];
  852. } else {
  853. $this->data['length'] = '';
  854. }
  855.  
  856. if (isset($this->request->post['width'])) {
  857. $this->data['width'] = $this->request->post['width'];
  858. } elseif (isset($product_info)) {
  859. $this->data['width'] = $product_info['width'];
  860. } else {
  861. $this->data['width'] = '';
  862. }
  863.  
  864. if (isset($this->request->post['height'])) {
  865. $this->data['height'] = $this->request->post['height'];
  866. } elseif (isset($product_info)) {
  867. $this->data['height'] = $product_info['height'];
  868. } else {
  869. $this->data['height'] = '';
  870. }
  871.  
  872. $this->load->model('localisation/length_class');
  873.  
  874. $this->data['length_classes'] = $this->model_localisation_length_class->getLengthClasses();
  875.  
  876. $length_info = $this->model_localisation_length_class->getLengthClassDescriptionByUnit($this->config->get('config_length_class'));
  877.  
  878. if (isset($this->request->post['length_class_id'])) {
  879. $this->data['length_class_id'] = $this->request->post['length_class_id'];
  880. } elseif (isset($product_info)) {
  881. $this->data['length_class_id'] = $product_info['length_class_id'];
  882. } elseif (isset($length_info)) {
  883. $this->data['length_class_id'] = $length_info['length_class_id'];
  884. } else {
  885. $this->data['length_class_id'] = '';
  886. }
  887.  
  888. $this->data['language_id'] = $this->config->get('config_language_id');
  889.  
  890. if (isset($this->request->post['product_option'])) {
  891. $this->data['product_options'] = $this->request->post['product_option'];
  892. } elseif (isset($product_info)) {
  893. $this->data['product_options'] = $this->model_catalog_product->getProductOptions($this->request->get['product_id']);
  894. } else {
  895. $this->data['product_options'] = array();
  896. }
  897.  
  898. $this->load->model('sale/customer_group');
  899.  
  900. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  901.  
  902. if (isset($this->request->post['product_discount'])) {
  903. $this->data['product_discounts'] = $this->request->post['product_discount'];
  904. } elseif (isset($product_info)) {
  905. $this->data['product_discounts'] = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);
  906. } else {
  907. $this->data['product_discounts'] = array();
  908. }
  909.  
  910. if (isset($this->request->post['product_special'])) {
  911. $this->data['product_specials'] = $this->request->post['product_special'];
  912. } elseif (isset($product_info)) {
  913. $this->data['product_specials'] = $this->model_catalog_product->getProductSpecials($this->request->get['product_id']);
  914. } else {
  915. $this->data['product_specials'] = array();
  916. }
  917.  
  918. $this->data['no_image'] = $this->model_tool_image->resize('no_image.jpg', 100, 100);
  919.  
  920. $this->data['product_images'] = array();
  921.  
  922. if (isset($product_info)) {
  923. $results = $this->model_catalog_product->getProductImages($this->request->get['product_id']);
  924.  
  925. foreach ($results as $result) {
  926. if ($result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
  927. $this->data['product_images'][] = array(
  928. 'preview' => $this->model_tool_image->resize($result['image'], 100, 100),
  929. 'file' => $result['image']
  930. );
  931. } else {
  932. $this->data['product_images'][] = array(
  933. 'preview' => $this->model_tool_image->resize('no_image.jpg', 100, 100),
  934. 'file' => $result['image']
  935. );
  936. }
  937. }
  938. }
  939.  
  940. $this->load->model('catalog/download');
  941.  
  942. $this->data['downloads'] = $this->model_catalog_download->getDownloads();
  943.  
  944. if (isset($this->request->post['product_download'])) {
  945. $this->data['product_download'] = $this->request->post['product_download'];
  946. } elseif (isset($product_info)) {
  947. $this->data['product_download'] = $this->model_catalog_product->getProductDownloads($this->request->get['product_id']);
  948. } else {
  949. $this->data['product_download'] = array();
  950. }
  951.  
  952. $this->load->model('catalog/category');
  953.  
  954. $this->data['categories'] = $this->model_catalog_category->getCategories(0);
  955.  
  956. if (isset($this->request->post['product_category'])) {
  957. $this->data['product_category'] = $this->request->post['product_category'];
  958. } elseif (isset($product_info)) {
  959. $this->data['product_category'] = $this->model_catalog_product->getProductCategories($this->request->get['product_id']);
  960. } else {
  961. $this->data['product_category'] = array();
  962. }
  963.  
  964. if (isset($this->request->post['product_related'])) {
  965. $this->data['product_related'] = $this->request->post['product_related'];
  966. } elseif (isset($product_info)) {
  967. $this->data['product_related'] = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
  968. } else {
  969. $this->data['product_related'] = array();
  970. }
  971.  
  972. $this->template = 'catalog/product_form.tpl';
  973. $this->children = array(
  974. 'common/header',
  975. 'common/footer'
  976. );
  977.  
  978. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  979. }
  980.  
  981. private function validateForm() {
  982. if (!$this->user->hasPermission('modify', 'catalog/product')) {
  983. $this->error['warning'] = $this->language->get('error_permission');
  984. }
  985.  
  986. foreach ($this->request->post['product_description'] as $language_id => $value) {
  987. if ((strlen(utf8_decode($value['name'])) < 1) || (strlen(utf8_decode($value['name'])) > 255)) {
  988. $this->error['name'][$language_id] = $this->language->get('error_name');
  989. }
  990. }
  991.  
  992. if ((strlen(utf8_decode($this->request->post['model'])) < 1) || (strlen(utf8_decode($this->request->post['model'])) > 64)) {
  993. $this->error['model'] = $this->language->get('error_model');
  994. }
  995.  
  996. if (!$this->error) {
  997. return TRUE;
  998. } else {
  999. if (!isset($this->error['warning'])) {
  1000. $this->error['warning'] = $this->language->get('error_required_data');
  1001. }
  1002. return FALSE;
  1003. }
  1004. }
  1005.  
  1006. private function validateDelete() {
  1007. if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1008. $this->error['warning'] = $this->language->get('error_permission');
  1009. }
  1010.  
  1011. if (!$this->error) {
  1012. return TRUE;
  1013. } else {
  1014. return FALSE;
  1015. }
  1016. }
  1017.  
  1018. private function validateCopy() {
  1019. if (!$this->user->hasPermission('modify', 'catalog/product')) {
  1020. $this->error['warning'] = $this->language->get('error_permission');
  1021. }
  1022.  
  1023. if (!$this->error) {
  1024. return TRUE;
  1025. } else {
  1026. return FALSE;
  1027. }
  1028. }
  1029.  
  1030. public function category() {
  1031. $this->load->model('catalog/product');
  1032.  
  1033. if (isset($this->request->get['category_id'])) {
  1034. $category_id = $this->request->get['category_id'];
  1035. } else {
  1036. $category_id = 0;
  1037. }
  1038.  
  1039. $product_data = array();
  1040.  
  1041. $results = $this->model_catalog_product->getProductsByCategoryId($category_id);
  1042.  
  1043. foreach ($results as $result) {
  1044. $product_data[] = array(
  1045. 'product_id' => $result['product_id'],
  1046. 'name' => $result['name'],
  1047. 'model' => $result['model']
  1048. );
  1049. }
  1050.  
  1051. $this->load->library('json');
  1052.  
  1053. $this->response->setOutput(Json::encode($product_data));
  1054. }
  1055.  
  1056. public function related() {
  1057. $this->load->model('catalog/product');
  1058.  
  1059. if (isset($this->request->post['product_related'])) {
  1060. $products = $this->request->post['product_related'];
  1061. } else {
  1062. $products = array();
  1063. }
  1064.  
  1065. $product_data = array();
  1066.  
  1067. foreach ($products as $product_id) {
  1068. $product_info = $this->model_catalog_product->getProduct($product_id);
  1069.  
  1070. if ($product_info) {
  1071. $product_data[] = array(
  1072. 'product_id' => $product_info['product_id'],
  1073. 'name' => $product_info['name'],
  1074. 'model' => $product_info['model']
  1075. );
  1076. }
  1077. }
  1078.  
  1079. $this->load->library('json');
  1080.  
  1081. $this->response->setOutput(Json::encode($product_data));
  1082. }
  1083. }
  1084. ?>
RAW Paste Data