PageRenderTime 44ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/admin/AdminManufacturersController.php

https://gitlab.com/mtellezgalindo/PrestaShop
PHP | 852 lines | 714 code | 85 blank | 53 comment | 50 complexity | 24704697c0283435a1ba6beb7e536d89 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-3.0
  1. <?php
  2. /*
  3. * 2007-2014 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2014 PrestaShop SA
  23. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  24. * International Registered Trademark & Property of PrestaShop SA
  25. */
  26. class AdminManufacturersControllerCore extends AdminController
  27. {
  28. public $bootstrap = true ;
  29. /** @var array countries list */
  30. protected $countries_array = array();
  31. public function __construct()
  32. {
  33. $this->table = 'manufacturer';
  34. $this->className = 'Manufacturer';
  35. $this->lang = false;
  36. $this->deleted = false;
  37. $this->allow_export = true;
  38. $this->list_id = 'manufacturer';
  39. $this->identifier = 'id_manufacturer';
  40. $this->_defaultOrderBy = 'name';
  41. $this->_defaultOrderWay = 'ASC';
  42. $this->bulk_actions = array(
  43. 'delete' => array(
  44. 'text' => $this->l('Delete selected'),
  45. 'icon' => 'icon-trash',
  46. 'confirm' => $this->l('Delete selected items?')
  47. )
  48. );
  49. $this->context = Context::getContext();
  50. $this->fieldImageSettings = array(
  51. 'name' => 'logo',
  52. 'dir' => 'm'
  53. );
  54. $this->fields_list = array(
  55. 'id_manufacturer' => array(
  56. 'title' => $this->l('ID'),
  57. 'align' => 'center',
  58. 'class' => 'fixed-width-xs'
  59. ),
  60. 'logo' => array(
  61. 'title' => $this->l('Logo'),
  62. 'image' => 'm',
  63. 'orderby' => false,
  64. 'search' => false,
  65. 'align' => 'center',
  66. ),
  67. 'name' => array(
  68. 'title' => $this->l('Name'),
  69. 'width' => 'auto'
  70. ),
  71. 'addresses' => array(
  72. 'title' => $this->l('Addresses'),
  73. 'search' => false,
  74. 'align' => 'center'
  75. ),
  76. 'products' => array(
  77. 'title' => $this->l('Products'),
  78. 'search' => false,
  79. 'align' => 'center',
  80. ),
  81. 'active' => array(
  82. 'title' => $this->l('Enabled'),
  83. 'active' => 'status',
  84. 'type' => 'bool',
  85. 'align' => 'center',
  86. 'class' => 'fixed-width-xs',
  87. 'orderby' => false
  88. )
  89. );
  90. parent::__construct();
  91. }
  92. public function setMedia()
  93. {
  94. parent::setMedia();
  95. $this->addJqueryUi('ui.widget');
  96. $this->addJqueryPlugin('tagify');
  97. }
  98. public function initPageHeaderToolbar()
  99. {
  100. if (empty($this->display))
  101. {
  102. $this->page_header_toolbar_btn['new_manufacturer'] = array(
  103. 'href' => self::$currentIndex.'&addmanufacturer&token='.$this->token,
  104. 'desc' => $this->l('Add new manufacturer', null, null, false),
  105. 'icon' => 'process-icon-new'
  106. );
  107. $this->page_header_toolbar_btn['new_manufacturer_address'] = array(
  108. 'href' => self::$currentIndex.'&addaddress&token='.$this->token,
  109. 'desc' => $this->l('Add new manufacturer address', null, null, false),
  110. 'icon' => 'process-icon-new'
  111. );
  112. }
  113. elseif ($this->display == 'editaddresses' || $this->display == 'addaddress') {
  114. // Default cancel button - like old back link
  115. if (!isset($this->no_back) || $this->no_back == false)
  116. {
  117. $back = Tools::safeOutput(Tools::getValue('back', ''));
  118. if (empty($back))
  119. $back = self::$currentIndex.'&token='.$this->token;
  120. $this->page_header_toolbar_btn['cancel'] = array(
  121. 'href' => $back,
  122. 'desc' => $this->l('Cancel', null, null, false)
  123. );
  124. }
  125. }
  126. parent::initPageHeaderToolbar();
  127. }
  128. public function initListManufacturer()
  129. {
  130. $this->addRowAction('view');
  131. $this->addRowAction('edit');
  132. $this->addRowAction('delete');
  133. $this->_select = '
  134. COUNT(`id_product`) AS `products`, (
  135. SELECT COUNT(ad.`id_manufacturer`) as `addresses`
  136. FROM `'._DB_PREFIX_.'address` ad
  137. WHERE ad.`id_manufacturer` = a.`id_manufacturer`
  138. AND ad.`deleted` = 0
  139. GROUP BY ad.`id_manufacturer`) as `addresses`';
  140. $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_manufacturer` = p.`id_manufacturer`)';
  141. $this->_group = 'GROUP BY a.`id_manufacturer`';
  142. $this->context->smarty->assign('title_list', $this->l('List of manufacturers'));
  143. $this->content .= parent::renderList();
  144. }
  145. protected function getAddressFieldsList()
  146. {
  147. // Sub tab addresses
  148. $countries = Country::getCountries($this->context->language->id);
  149. foreach ($countries as $country)
  150. $this->countries_array[$country['id_country']] = $country['name'];
  151. return array(
  152. 'id_address' => array(
  153. 'title' => $this->l('ID'),
  154. 'align' => 'center',
  155. 'class' => 'fixed-width-xs'
  156. ),
  157. 'manufacturer_name' => array(
  158. 'title' => $this->l('Manufacturer'),
  159. 'width' => 'auto',
  160. 'filter_key' => 'manufacturer_name'
  161. ),
  162. 'firstname' => array(
  163. 'title' => $this->l('First name')
  164. ),
  165. 'lastname' => array(
  166. 'title' => $this->l('Last name'),
  167. 'filter_key' => 'a!lastname'
  168. ),
  169. 'postcode' => array(
  170. 'title' => $this->l('Zip/Postal code'),
  171. 'align' => 'right'
  172. ),
  173. 'city' => array(
  174. 'title' => $this->l('City')
  175. ),
  176. 'country' => array(
  177. 'title' => $this->l('Country'),
  178. 'type' => 'select',
  179. 'list' => $this->countries_array,
  180. 'filter_key' => 'cl!id_country'
  181. )
  182. );
  183. }
  184. public function processExport($text_delimiter = '"')
  185. {
  186. if (strtolower($this->table) == 'address')
  187. {
  188. $this->_defaultOrderBy = 'id_manufacturer';
  189. $this->_where = 'AND a.`id_customer` = 0 AND a.`id_supplier` = 0 AND a.`id_warehouse` = 0 AND a.`deleted`= 0';
  190. }
  191. return parent::processExport($text_delimiter);
  192. }
  193. public function initListManufacturerAddresses()
  194. {
  195. $this->toolbar_title = $this->l('Addresses');
  196. // reset actions and query vars
  197. $this->actions = array();
  198. unset($this->fields_list, $this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter);
  199. $this->table = 'address';
  200. $this->list_id = 'address';
  201. $this->identifier = 'id_address';
  202. $this->deleted = true;
  203. $this->_defaultOrderBy = 'id_address';
  204. $this->_defaultOrderWay = 'ASC';
  205. $this->_orderBy = null;
  206. $this->addRowAction('editaddresses');
  207. $this->addRowAction('delete');
  208. // test if a filter is applied for this list
  209. if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
  210. $this->filter = true;
  211. // test if a filter reset request is required for this list
  212. $this->action = (isset($_POST['submitReset'.$this->table]) ? 'reset_filters' : '');
  213. $this->fields_list = $this->getAddressFieldsList();
  214. $this->bulk_actions = array(
  215. 'delete' => array(
  216. 'text' => $this->l('Delete selected'),
  217. 'icon' => 'icon-trash',
  218. 'confirm' => $this->l('Delete selected items?')
  219. )
  220. );
  221. $this->_select = 'cl.`name` as country, m.`name` AS manufacturer_name';
  222. $this->_join = '
  223. LEFT JOIN `'._DB_PREFIX_.'country_lang` cl
  224. ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.') ';
  225. $this->_join .= '
  226. LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
  227. ON (a.`id_manufacturer` = m.`id_manufacturer`)';
  228. $this->_where = 'AND a.`id_customer` = 0 AND a.`id_supplier` = 0 AND a.`id_warehouse` = 0 AND a.`deleted`= 0';
  229. $this->context->smarty->assign('title_list', $this->l('Manufacturers addresses'));
  230. // call postProcess() for take care about actions and filters
  231. $this->postProcess();
  232. $this->initToolbar();
  233. $this->content .= parent::renderList();
  234. }
  235. public function renderList()
  236. {
  237. $this->initListManufacturer();
  238. $this->initListManufacturerAddresses();
  239. }
  240. /**
  241. * Display editaddresses action link
  242. * @param string $token the token to add to the link
  243. * @param int $id the identifier to add to the link
  244. * @return string
  245. */
  246. public function displayEditaddressesLink($token = null, $id)
  247. {
  248. if (!array_key_exists('editaddresses', self::$cache_lang))
  249. self::$cache_lang['editaddresses'] = $this->l('Edit');
  250. $this->context->smarty->assign(array(
  251. 'href' => self::$currentIndex.
  252. '&'.$this->identifier.'='.$id.
  253. '&editaddresses&token='.($token != null ? $token : $this->token),
  254. 'action' => self::$cache_lang['editaddresses'],
  255. ));
  256. return $this->context->smarty->fetch('helpers/list/list_action_edit.tpl');
  257. }
  258. public function renderForm()
  259. {
  260. if (!($manufacturer = $this->loadObject(true)))
  261. return;
  262. $image = _PS_MANU_IMG_DIR_.$manufacturer->id.'.jpg';
  263. $image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350,
  264. $this->imageType, true, true);
  265. $image_size = file_exists($image) ? filesize($image) / 1000 : false;
  266. $this->fields_form = array(
  267. 'tinymce' => true,
  268. 'legend' => array(
  269. 'title' => $this->l('Manufacturers'),
  270. 'icon' => 'icon-certificate'
  271. ),
  272. 'input' => array(
  273. array(
  274. 'type' => 'text',
  275. 'label' => $this->l('Name'),
  276. 'name' => 'name',
  277. 'col' => 4,
  278. 'required' => true,
  279. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  280. ),
  281. array(
  282. 'type' => 'textarea',
  283. 'label' => $this->l('Short description'),
  284. 'name' => 'short_description',
  285. 'lang' => true,
  286. 'cols' => 60,
  287. 'rows' => 10,
  288. 'autoload_rte' => 'rte', //Enable TinyMCE editor for short description
  289. 'col' => 6,
  290. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  291. ),
  292. array(
  293. 'type' => 'textarea',
  294. 'label' => $this->l('Description'),
  295. 'name' => 'description',
  296. 'lang' => true,
  297. 'cols' => 60,
  298. 'rows' => 10,
  299. 'col' => 6,
  300. 'autoload_rte' => 'rte', //Enable TinyMCE editor for description
  301. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  302. ),
  303. array(
  304. 'type' => 'file',
  305. 'label' => $this->l('Logo'),
  306. 'name' => 'logo',
  307. 'image' => $image_url ? $image_url : false,
  308. 'size' => $image_size,
  309. 'display_image' => true,
  310. 'col' => 6,
  311. 'hint' => $this->l('Upload a manufacturer logo from your computer.')
  312. ),
  313. array(
  314. 'type' => 'text',
  315. 'label' => $this->l('Meta title'),
  316. 'name' => 'meta_title',
  317. 'lang' => true,
  318. 'col' => 4,
  319. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
  320. ),
  321. array(
  322. 'type' => 'text',
  323. 'label' => $this->l('Meta description'),
  324. 'name' => 'meta_description',
  325. 'lang' => true,
  326. 'col' => 6,
  327. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
  328. ),
  329. array(
  330. 'type' => 'tags',
  331. 'label' => $this->l('Meta keywords'),
  332. 'name' => 'meta_keywords',
  333. 'lang' => true,
  334. 'col' => 6,
  335. 'hint' => array(
  336. $this->l('Forbidden characters:').' &lt;&gt;;=#{}',
  337. $this->l('To add "tags," click inside the field, write something, and then press "Enter."')
  338. )
  339. ),
  340. array(
  341. 'type' => 'switch',
  342. 'label' => $this->l('Enable'),
  343. 'name' => 'active',
  344. 'required' => false,
  345. 'class' => 't',
  346. 'is_bool' => true,
  347. 'values' => array(
  348. array(
  349. 'id' => 'active_on',
  350. 'value' => 1,
  351. 'label' => $this->l('Enabled')
  352. ),
  353. array(
  354. 'id' => 'active_off',
  355. 'value' => 0,
  356. 'label' => $this->l('Disabled')
  357. )
  358. )
  359. )
  360. )
  361. );
  362. if (!($manufacturer = $this->loadObject(true)))
  363. return;
  364. if (Shop::isFeatureActive())
  365. {
  366. $this->fields_form['input'][] = array(
  367. 'type' => 'shop',
  368. 'label' => $this->l('Shop association'),
  369. 'name' => 'checkBoxShopAsso',
  370. );
  371. }
  372. $this->fields_form['submit'] = array(
  373. 'title' => $this->l('Save')
  374. );
  375. foreach ($this->_languages as $language)
  376. {
  377. $this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
  378. $manufacturer,
  379. 'short_description',
  380. $language['id_lang']
  381. )), ENT_COMPAT, 'UTF-8');
  382. $this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
  383. $manufacturer,
  384. 'description',
  385. $language['id_lang']
  386. )), ENT_COMPAT, 'UTF-8');
  387. }
  388. return parent::renderForm();
  389. }
  390. public function renderFormAddress()
  391. {
  392. // Change table and className for addresses
  393. $this->table = 'address';
  394. $this->className = 'Address';
  395. $id_address = Tools::getValue('id_address');
  396. // Create Object Address
  397. $address = new Address($id_address);
  398. $res = $address->getFieldsRequiredDatabase();
  399. $required_fields = array();
  400. foreach ($res as $row)
  401. $required_fields[(int)$row['id_required_field']] = $row['field_name'];
  402. $form = array(
  403. 'legend' => array(
  404. 'title' => $this->l('Addresses'),
  405. 'icon' => 'icon-building'
  406. )
  407. );
  408. if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer))
  409. $form['input'][] = array(
  410. 'type' => 'select',
  411. 'label' => $this->l('Choose the manufacturer'),
  412. 'name' => 'id_manufacturer',
  413. 'options' => array(
  414. 'query' => Manufacturer::getManufacturers(),
  415. 'id' => 'id_manufacturer',
  416. 'name' => 'name'
  417. )
  418. );
  419. else
  420. {
  421. $form['input'][] = array(
  422. 'type' => 'text',
  423. 'label' => $this->l('Manufacturer'),
  424. 'name' => 'name',
  425. 'col' => 4,
  426. 'disabled' => true,
  427. );
  428. $form['input'][] = array(
  429. 'type' => 'hidden',
  430. 'name' => 'id_manufacturer'
  431. );
  432. }
  433. $form['input'][] = array(
  434. 'type' => 'hidden',
  435. 'name' => 'alias',
  436. );
  437. $form['input'][] = array(
  438. 'type' => 'hidden',
  439. 'name' => 'id_address',
  440. );
  441. if (in_array('company', $required_fields))
  442. $form['input'][] = array(
  443. 'type' => 'text',
  444. 'label' => $this->l('Company'),
  445. 'name' => 'company',
  446. 'display' => in_array('company', $required_fields),
  447. 'required' => in_array('company', $required_fields),
  448. 'maxlength' => 16,
  449. 'col' => 4,
  450. 'hint' => $this->l('Company name for this supplier')
  451. );
  452. $form['input'][] = array(
  453. 'type' => 'text',
  454. 'label' => $this->l('Last name'),
  455. 'name' => 'lastname',
  456. 'required' => true,
  457. 'col' => 4,
  458. 'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"�{}_$%:'
  459. );
  460. $form['input'][] = array(
  461. 'type' => 'text',
  462. 'label' => $this->l('First name'),
  463. 'name' => 'firstname',
  464. 'required' => true,
  465. 'col' => 4,
  466. 'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"�{}_$%:'
  467. );
  468. $form['input'][] = array(
  469. 'type' => 'text',
  470. 'label' => $this->l('Address'),
  471. 'name' => 'address1',
  472. 'col' => 6,
  473. 'required' => true,
  474. );
  475. $form['input'][] = array(
  476. 'type' => 'text',
  477. 'label' => $this->l('Address (2)'),
  478. 'name' => 'address2',
  479. 'col' => 6,
  480. 'required' => in_array('address2', $required_fields)
  481. );
  482. $form['input'][] = array(
  483. 'type' => 'text',
  484. 'label' => $this->l('Zip/postal code'),
  485. 'name' => 'postcode',
  486. 'col' => 2,
  487. 'required' => in_array('postcode', $required_fields)
  488. );
  489. $form['input'][] = array(
  490. 'type' => 'text',
  491. 'label' => $this->l('City'),
  492. 'name' => 'city',
  493. 'col' => 4,
  494. 'required' => true,
  495. );
  496. $form['input'][] = array(
  497. 'type' => 'select',
  498. 'label' => $this->l('Country'),
  499. 'name' => 'id_country',
  500. 'required' => false,
  501. 'default_value' => (int)$this->context->country->id,
  502. 'col' => 4,
  503. 'options' => array(
  504. 'query' => Country::getCountries($this->context->language->id),
  505. 'id' => 'id_country',
  506. 'name' => 'name',
  507. )
  508. );
  509. $form['input'][] = array(
  510. 'type' => 'select',
  511. 'label' => $this->l('State'),
  512. 'name' => 'id_state',
  513. 'required' => false,
  514. 'col' => 4,
  515. 'options' => array(
  516. 'query' => array(),
  517. 'id' => 'id_state',
  518. 'name' => 'name'
  519. )
  520. );
  521. $form['input'][] = array(
  522. 'type' => 'text',
  523. 'label' => $this->l('Home phone'),
  524. 'name' => 'phone',
  525. 'col' => 4,
  526. 'required' => in_array('phone', $required_fields)
  527. );
  528. $form['input'][] = array(
  529. 'type' => 'text',
  530. 'label' => $this->l('Mobile phone'),
  531. 'name' => 'phone_mobile',
  532. 'col' => 4,
  533. 'required' => in_array('phone_mobile', $required_fields)
  534. );
  535. $form['input'][] = array(
  536. 'type' => 'textarea',
  537. 'label' => $this->l('Other'),
  538. 'name' => 'other',
  539. 'required' => false,
  540. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}',
  541. 'rows' => 2,
  542. 'cols' => 10,
  543. 'col' => 6,
  544. );
  545. $form['submit'] = array(
  546. 'title' => $this->l('Save'),
  547. );
  548. $this->fields_value = array(
  549. 'name' => Manufacturer::getNameById($address->id_manufacturer),
  550. 'alias' => 'manufacturer',
  551. 'id_country' => $address->id_country
  552. );
  553. $this->initToolbar();
  554. $this->fields_form[0]['form'] = $form;
  555. $this->getlanguages();
  556. $helper = new HelperForm();
  557. $helper->show_cancel_button = true;
  558. $back = Tools::safeOutput(Tools::getValue('back', ''));
  559. if (empty($back))
  560. $back = self::$currentIndex.'&token='.$this->token;
  561. if (!Validate::isCleanHtml($back))
  562. die(Tools::displayError());
  563. $helper->back_url = $back;
  564. $helper->currentIndex = self::$currentIndex;
  565. $helper->token = $this->token;
  566. $helper->table = $this->table;
  567. $helper->identifier = $this->identifier;
  568. $helper->title = $this->l('Edit Addresses');
  569. $helper->id = $address->id;
  570. $helper->toolbar_scroll = true;
  571. $helper->languages = $this->_languages;
  572. $helper->default_form_language = $this->default_form_language;
  573. $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
  574. $helper->fields_value = $this->getFieldsValue($address);
  575. $helper->toolbar_btn = $this->toolbar_btn;
  576. $this->content .= $helper->generateForm($this->fields_form);
  577. }
  578. /**
  579. * AdminController::initToolbar() override
  580. * @see AdminController::initToolbar()
  581. *
  582. */
  583. public function initToolbar()
  584. {
  585. switch ($this->display)
  586. {
  587. case 'editaddresses':
  588. case 'addaddress':
  589. $this->toolbar_btn['save'] = array(
  590. 'href' => '#',
  591. 'desc' => $this->l('Save')
  592. );
  593. // Default cancel button - like old back link
  594. if (!isset($this->no_back) || $this->no_back == false)
  595. {
  596. $back = Tools::safeOutput(Tools::getValue('back', ''));
  597. if (empty($back))
  598. $back = self::$currentIndex.'&token='.$this->token;
  599. $this->toolbar_btn['cancel'] = array(
  600. 'href' => $back,
  601. 'desc' => $this->l('Cancel')
  602. );
  603. }
  604. break;
  605. default:
  606. parent::initToolbar();
  607. $this->toolbar_btn['import'] = array(
  608. 'href' => $this->context->link->getAdminLink('AdminImport', true).'&import_type=manufacturers',
  609. 'desc' => $this->l('Import')
  610. );
  611. }
  612. }
  613. public function renderView()
  614. {
  615. if (!($manufacturer = $this->loadObject()))
  616. return;
  617. $this->toolbar_btn['new'] = array(
  618. 'href' => $this->context->link->getAdminLink('AdminManufacturers').'&addaddress=1&id_manufacturer='.(int)$manufacturer->id,
  619. 'desc' => $this->l('Add address')
  620. );
  621. $this->toolbar_title = is_array($this->breadcrumbs) ? array_unique($this->breadcrumbs) : array($this->breadcrumbs);
  622. $this->toolbar_title[] = $manufacturer->name;
  623. $addresses = $manufacturer->getAddresses($this->context->language->id);
  624. $products = $manufacturer->getProductsLite($this->context->language->id);
  625. $total_product = count($products);
  626. for ($i = 0; $i < $total_product; $i++)
  627. {
  628. $products[$i] = new Product($products[$i]['id_product'], false, $this->context->language->id);
  629. $products[$i]->loadStockData();
  630. /* Build attributes combinations */
  631. $combinations = $products[$i]->getAttributeCombinations($this->context->language->id);
  632. foreach ($combinations as $k => $combination)
  633. {
  634. $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference'];
  635. $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13'];
  636. $comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc'];
  637. $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity'];
  638. $comb_array[$combination['id_product_attribute']]['attributes'][] = array(
  639. $combination['group_name'],
  640. $combination['attribute_name'],
  641. $combination['id_attribute']
  642. );
  643. }
  644. if (isset($comb_array))
  645. {
  646. foreach ($comb_array as $key => $product_attribute)
  647. {
  648. $list = '';
  649. foreach ($product_attribute['attributes'] as $attribute)
  650. $list .= $attribute[0].' - '.$attribute[1].', ';
  651. $comb_array[$key]['attributes'] = rtrim($list, ', ');
  652. }
  653. isset($comb_array) ? $products[$i]->combination = $comb_array : '';
  654. unset($comb_array);
  655. }
  656. }
  657. $this->tpl_view_vars = array(
  658. 'manufacturer' => $manufacturer,
  659. 'addresses' => $addresses,
  660. 'products' => $products,
  661. 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
  662. 'shopContext' => Shop::getContext(),
  663. );
  664. return parent::renderView();
  665. }
  666. public function initContent()
  667. {
  668. $this->initTabModuleList();
  669. // toolbar (save, cancel, new, ..)
  670. $this->initToolbar();
  671. $this->initPageHeaderToolbar();
  672. if ($this->display == 'editaddresses' || $this->display == 'addaddress')
  673. $this->content .= $this->renderFormAddress();
  674. elseif ($this->display == 'edit' || $this->display == 'add')
  675. {
  676. if (!$this->loadObject(true))
  677. return;
  678. $this->content .= $this->renderForm();
  679. }
  680. elseif ($this->display == 'view')
  681. {
  682. // Some controllers use the view action without an object
  683. if ($this->className)
  684. $this->loadObject(true);
  685. $this->content .= $this->renderView();
  686. }
  687. elseif (!$this->ajax)
  688. {
  689. $this->content .= $this->renderList();
  690. $this->content .= $this->renderOptions();
  691. }
  692. $this->context->smarty->assign(array(
  693. 'content' => $this->content,
  694. 'url_post' => self::$currentIndex.'&token='.$this->token,
  695. 'show_page_header_toolbar' => $this->show_page_header_toolbar,
  696. 'page_header_toolbar_title' => $this->page_header_toolbar_title,
  697. 'page_header_toolbar_btn' => $this->page_header_toolbar_btn
  698. ));
  699. }
  700. /**
  701. * AdminController::init() override
  702. * @see AdminController::init()
  703. */
  704. public function init()
  705. {
  706. parent::init();
  707. if (Tools::isSubmit('editaddresses'))
  708. $this->display = 'editaddresses';
  709. elseif (Tools::isSubmit('updateaddress'))
  710. $this->display = 'editaddresses';
  711. elseif (Tools::isSubmit('addaddress'))
  712. $this->display = 'addaddress';
  713. elseif (Tools::isSubmit('submitAddaddress'))
  714. $this->action = 'save';
  715. elseif (Tools::isSubmit('deleteaddress'))
  716. $this->action = 'delete';
  717. }
  718. public function initProcess()
  719. {
  720. if (Tools::isSubmit('submitAddaddress') || Tools::isSubmit('deleteaddress') || Tools::isSubmit('submitBulkdeleteaddress') || Tools::isSubmit('exportaddress'))
  721. {
  722. $this->table = 'address';
  723. $this->className = 'Address';
  724. $this->identifier = 'id_address';
  725. $this->deleted = true;
  726. $this->fields_list = $this->getAddressFieldsList();
  727. }
  728. parent::initProcess();
  729. }
  730. protected function afterImageUpload()
  731. {
  732. $res = true;
  733. /* Generate image with differents size */
  734. if (($id_manufacturer = (int)Tools::getValue('id_manufacturer')) &&
  735. isset($_FILES) &&
  736. count($_FILES) &&
  737. file_exists(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg'))
  738. {
  739. $images_types = ImageType::getImagesTypes('manufacturers');
  740. foreach ($images_types as $k => $image_type)
  741. {
  742. $res &= ImageManager::resize(
  743. _PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg',
  744. _PS_MANU_IMG_DIR_.$id_manufacturer.'-'.stripslashes($image_type['name']).'.jpg',
  745. (int)$image_type['width'],
  746. (int)$image_type['height']
  747. );
  748. }
  749. $current_logo_file = _PS_TMP_IMG_DIR_.'manufacturer_mini_'.$id_manufacturer.'_'.$this->context->shop->id.'.jpg';
  750. if ($res && file_exists($current_logo_file))
  751. unlink($current_logo_file);
  752. }
  753. if (!$res)
  754. $this->errors[] = Tools::displayError('Unable to resize one or more of your pictures.');
  755. return $res;
  756. }
  757. protected function beforeDelete($object)
  758. {
  759. return true;
  760. }
  761. public function processSave()
  762. {
  763. parent::processSave();
  764. if (Tools::isSubmit('submitAddaddress'))
  765. $this->display = 'editaddresses';
  766. }
  767. }