PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/controllers/admin/AdminManufacturersController.php

https://github.com/netplayer/PrestaShop
PHP | 849 lines | 711 code | 85 blank | 53 comment | 63 complexity | de2bb639e3fa90692a81966952d9824a MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, 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. $this->_orderBy = null;
  188. return parent::processExport($text_delimiter);
  189. }
  190. public function initListManufacturerAddresses()
  191. {
  192. $this->toolbar_title = $this->l('Addresses');
  193. // reset actions and query vars
  194. $this->actions = array();
  195. unset($this->fields_list, $this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter);
  196. $this->table = 'address';
  197. $this->list_id = 'address';
  198. $this->identifier = 'id_address';
  199. $this->deleted = true;
  200. $this->_defaultOrderBy = 'id_address';
  201. $this->_defaultOrderWay = 'ASC';
  202. $this->_orderBy = null;
  203. $this->addRowAction('editaddresses');
  204. $this->addRowAction('delete');
  205. // test if a filter is applied for this list
  206. if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
  207. $this->filter = true;
  208. // test if a filter reset request is required for this list
  209. $this->action = (isset($_POST['submitReset'.$this->table]) ? 'reset_filters' : '');
  210. $this->fields_list = $this->getAddressFieldsList();
  211. $this->bulk_actions = array(
  212. 'delete' => array(
  213. 'text' => $this->l('Delete selected'),
  214. 'icon' => 'icon-trash',
  215. 'confirm' => $this->l('Delete selected items?')
  216. )
  217. );
  218. $this->_select = 'cl.`name` as country, m.`name` AS manufacturer_name';
  219. $this->_join = '
  220. LEFT JOIN `'._DB_PREFIX_.'country_lang` cl
  221. ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.') ';
  222. $this->_join .= '
  223. LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
  224. ON (a.`id_manufacturer` = m.`id_manufacturer`)';
  225. $this->_where = 'AND a.`id_customer` = 0 AND a.`id_supplier` = 0 AND a.`id_warehouse` = 0 AND a.`deleted`= 0';
  226. $this->context->smarty->assign('title_list', $this->l('Manufacturers addresses'));
  227. // call postProcess() for take care about actions and filters
  228. $this->postProcess();
  229. $this->initToolbar();
  230. $this->content .= parent::renderList();
  231. }
  232. public function renderList()
  233. {
  234. $this->initListManufacturer();
  235. $this->initListManufacturerAddresses();
  236. }
  237. /**
  238. * Display editaddresses action link
  239. * @param string $token the token to add to the link
  240. * @param int $id the identifier to add to the link
  241. * @return string
  242. */
  243. public function displayEditaddressesLink($token = null, $id)
  244. {
  245. if (!array_key_exists('editaddresses', self::$cache_lang))
  246. self::$cache_lang['editaddresses'] = $this->l('Edit');
  247. $this->context->smarty->assign(array(
  248. 'href' => self::$currentIndex.
  249. '&'.$this->identifier.'='.$id.
  250. '&editaddresses&token='.($token != null ? $token : $this->token),
  251. 'action' => self::$cache_lang['editaddresses'],
  252. ));
  253. return $this->context->smarty->fetch('helpers/list/list_action_edit.tpl');
  254. }
  255. public function renderForm()
  256. {
  257. if (!($manufacturer = $this->loadObject(true)))
  258. return;
  259. $image = _PS_MANU_IMG_DIR_.$manufacturer->id.'.jpg';
  260. $image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350,
  261. $this->imageType, true, true);
  262. $image_size = file_exists($image) ? filesize($image) / 1000 : false;
  263. $this->fields_form = array(
  264. 'tinymce' => true,
  265. 'legend' => array(
  266. 'title' => $this->l('Manufacturers'),
  267. 'icon' => 'icon-certificate'
  268. ),
  269. 'input' => array(
  270. array(
  271. 'type' => 'text',
  272. 'label' => $this->l('Name'),
  273. 'name' => 'name',
  274. 'col' => 4,
  275. 'required' => true,
  276. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  277. ),
  278. array(
  279. 'type' => 'textarea',
  280. 'label' => $this->l('Short description'),
  281. 'name' => 'short_description',
  282. 'lang' => true,
  283. 'cols' => 60,
  284. 'rows' => 10,
  285. 'autoload_rte' => 'rte', //Enable TinyMCE editor for short description
  286. 'col' => 6,
  287. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  288. ),
  289. array(
  290. 'type' => 'textarea',
  291. 'label' => $this->l('Description'),
  292. 'name' => 'description',
  293. 'lang' => true,
  294. 'cols' => 60,
  295. 'rows' => 10,
  296. 'col' => 6,
  297. 'autoload_rte' => 'rte', //Enable TinyMCE editor for description
  298. 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}'
  299. ),
  300. array(
  301. 'type' => 'file',
  302. 'label' => $this->l('Logo'),
  303. 'name' => 'logo',
  304. 'image' => $image_url ? $image_url : false,
  305. 'size' => $image_size,
  306. 'display_image' => true,
  307. 'col' => 6,
  308. 'hint' => $this->l('Upload a manufacturer logo from your computer.')
  309. ),
  310. array(
  311. 'type' => 'text',
  312. 'label' => $this->l('Meta title'),
  313. 'name' => 'meta_title',
  314. 'lang' => true,
  315. 'col' => 4,
  316. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
  317. ),
  318. array(
  319. 'type' => 'text',
  320. 'label' => $this->l('Meta description'),
  321. 'name' => 'meta_description',
  322. 'lang' => true,
  323. 'col' => 6,
  324. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}'
  325. ),
  326. array(
  327. 'type' => 'tags',
  328. 'label' => $this->l('Meta keywords'),
  329. 'name' => 'meta_keywords',
  330. 'lang' => true,
  331. 'col' => 6,
  332. 'hint' => array(
  333. $this->l('Forbidden characters:').' &lt;&gt;;=#{}',
  334. $this->l('To add "tags," click inside the field, write something, and then press "Enter."')
  335. )
  336. ),
  337. array(
  338. 'type' => 'switch',
  339. 'label' => $this->l('Enable'),
  340. 'name' => 'active',
  341. 'required' => false,
  342. 'class' => 't',
  343. 'is_bool' => true,
  344. 'values' => array(
  345. array(
  346. 'id' => 'active_on',
  347. 'value' => 1,
  348. 'label' => $this->l('Enabled')
  349. ),
  350. array(
  351. 'id' => 'active_off',
  352. 'value' => 0,
  353. 'label' => $this->l('Disabled')
  354. )
  355. )
  356. )
  357. )
  358. );
  359. if (!($manufacturer = $this->loadObject(true)))
  360. return;
  361. if (Shop::isFeatureActive())
  362. {
  363. $this->fields_form['input'][] = array(
  364. 'type' => 'shop',
  365. 'label' => $this->l('Shop association'),
  366. 'name' => 'checkBoxShopAsso',
  367. );
  368. }
  369. $this->fields_form['submit'] = array(
  370. 'title' => $this->l('Save')
  371. );
  372. foreach ($this->_languages as $language)
  373. {
  374. $this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
  375. $manufacturer,
  376. 'short_description',
  377. $language['id_lang']
  378. )), ENT_COMPAT, 'UTF-8');
  379. $this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
  380. $manufacturer,
  381. 'description',
  382. $language['id_lang']
  383. )), ENT_COMPAT, 'UTF-8');
  384. }
  385. return parent::renderForm();
  386. }
  387. public function renderFormAddress()
  388. {
  389. // Change table and className for addresses
  390. $this->table = 'address';
  391. $this->className = 'Address';
  392. $id_address = Tools::getValue('id_address');
  393. // Create Object Address
  394. $address = new Address($id_address);
  395. $res = $address->getFieldsRequiredDatabase();
  396. $required_fields = array();
  397. foreach ($res as $row)
  398. $required_fields[(int)$row['id_required_field']] = $row['field_name'];
  399. $form = array(
  400. 'legend' => array(
  401. 'title' => $this->l('Addresses'),
  402. 'icon' => 'icon-building'
  403. )
  404. );
  405. if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer))
  406. $form['input'][] = array(
  407. 'type' => 'select',
  408. 'label' => $this->l('Choose the manufacturer'),
  409. 'name' => 'id_manufacturer',
  410. 'options' => array(
  411. 'query' => Manufacturer::getManufacturers(),
  412. 'id' => 'id_manufacturer',
  413. 'name' => 'name'
  414. )
  415. );
  416. else
  417. {
  418. $form['input'][] = array(
  419. 'type' => 'text',
  420. 'label' => $this->l('Manufacturer'),
  421. 'name' => 'name',
  422. 'col' => 4,
  423. 'disabled' => true,
  424. );
  425. $form['input'][] = array(
  426. 'type' => 'hidden',
  427. 'name' => 'id_manufacturer'
  428. );
  429. }
  430. $form['input'][] = array(
  431. 'type' => 'hidden',
  432. 'name' => 'alias',
  433. );
  434. $form['input'][] = array(
  435. 'type' => 'hidden',
  436. 'name' => 'id_address',
  437. );
  438. $form['input'][] = (in_array('company', $required_fields) ?
  439. array(
  440. 'type' => 'text',
  441. 'label' => $this->l('Company'),
  442. 'name' => 'company',
  443. 'display' => in_array('company', $required_fields),
  444. 'required' => in_array('company', $required_fields),
  445. 'maxlength' => 16,
  446. 'col' => 4,
  447. 'hint' => $this->l('Company name for this supplier')
  448. ) : null);
  449. $form['input'][] = array(
  450. 'type' => 'text',
  451. 'label' => $this->l('Last name'),
  452. 'name' => 'lastname',
  453. 'required' => true,
  454. 'col' => 4,
  455. 'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"ďż˝{}_$%:'
  456. );
  457. $form['input'][] = array(
  458. 'type' => 'text',
  459. 'label' => $this->l('First name'),
  460. 'name' => 'firstname',
  461. 'required' => true,
  462. 'col' => 4,
  463. 'hint' => $this->l('Invalid characters:').' 0-9!&lt;&gt;,;?=+()@#"ďż˝{}_$%:'
  464. );
  465. $form['input'][] = array(
  466. 'type' => 'text',
  467. 'label' => $this->l('Address'),
  468. 'name' => 'address1',
  469. 'col' => 6,
  470. 'required' => true,
  471. );
  472. $form['input'][] = array(
  473. 'type' => 'text',
  474. 'label' => $this->l('Address (2)'),
  475. 'name' => 'address2',
  476. 'col' => 6,
  477. 'required' => in_array('address2', $required_fields)
  478. );
  479. $form['input'][] = array(
  480. 'type' => 'text',
  481. 'label' => $this->l('Zip/postal code'),
  482. 'name' => 'postcode',
  483. 'col' => 2,
  484. 'required' => in_array('postcode', $required_fields)
  485. );
  486. $form['input'][] = array(
  487. 'type' => 'text',
  488. 'label' => $this->l('City'),
  489. 'name' => 'city',
  490. 'col' => 4,
  491. 'required' => true,
  492. );
  493. $form['input'][] = array(
  494. 'type' => 'select',
  495. 'label' => $this->l('Country'),
  496. 'name' => 'id_country',
  497. 'required' => false,
  498. 'default_value' => (int)$this->context->country->id,
  499. 'col' => 4,
  500. 'options' => array(
  501. 'query' => Country::getCountries($this->context->language->id),
  502. 'id' => 'id_country',
  503. 'name' => 'name',
  504. )
  505. );
  506. $form['input'][] = array(
  507. 'type' => 'select',
  508. 'label' => $this->l('State'),
  509. 'name' => 'id_state',
  510. 'required' => false,
  511. 'col' => 4,
  512. 'options' => array(
  513. 'query' => array(),
  514. 'id' => 'id_state',
  515. 'name' => 'name'
  516. )
  517. );
  518. $form['input'][] = array(
  519. 'type' => 'text',
  520. 'label' => $this->l('Home phone'),
  521. 'name' => 'phone',
  522. 'col' => 4,
  523. 'required' => in_array('phone', $required_fields)
  524. );
  525. $form['input'][] = array(
  526. 'type' => 'text',
  527. 'label' => $this->l('Mobile phone'),
  528. 'name' => 'phone_mobile',
  529. 'col' => 4,
  530. 'required' => in_array('phone_mobile', $required_fields)
  531. );
  532. $form['input'][] = array(
  533. 'type' => 'textarea',
  534. 'label' => $this->l('Other'),
  535. 'name' => 'other',
  536. 'required' => false,
  537. 'hint' => $this->l('Forbidden characters:').' &lt;&gt;;=#{}',
  538. 'rows' => 2,
  539. 'cols' => 10,
  540. 'col' => 6,
  541. );
  542. $form['submit'] = array(
  543. 'title' => $this->l('Save'),
  544. );
  545. $this->fields_value = array(
  546. 'name' => Manufacturer::getNameById($address->id_manufacturer),
  547. 'alias' => 'manufacturer',
  548. 'id_country' => $address->id_country
  549. );
  550. $this->initToolbar();
  551. $this->fields_form[0]['form'] = $form;
  552. $this->getlanguages();
  553. $helper = new HelperForm();
  554. $helper->show_cancel_button = true;
  555. $back = Tools::safeOutput(Tools::getValue('back', ''));
  556. if (empty($back))
  557. $back = self::$currentIndex.'&token='.$this->token;
  558. if (!Validate::isCleanHtml($back))
  559. die(Tools::displayError());
  560. $helper->back_url = $back;
  561. $helper->currentIndex = self::$currentIndex;
  562. $helper->token = $this->token;
  563. $helper->table = $this->table;
  564. $helper->identifier = $this->identifier;
  565. $helper->title = $this->l('Edit Addresses');
  566. $helper->id = $address->id;
  567. $helper->toolbar_scroll = true;
  568. $helper->languages = $this->_languages;
  569. $helper->default_form_language = $this->default_form_language;
  570. $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
  571. $helper->fields_value = $this->getFieldsValue($address);
  572. $helper->toolbar_btn = $this->toolbar_btn;
  573. $this->content .= $helper->generateForm($this->fields_form);
  574. }
  575. /**
  576. * AdminController::initToolbar() override
  577. * @see AdminController::initToolbar()
  578. *
  579. */
  580. public function initToolbar()
  581. {
  582. switch ($this->display)
  583. {
  584. case 'editaddresses':
  585. case 'addaddress':
  586. $this->toolbar_btn['save'] = array(
  587. 'href' => '#',
  588. 'desc' => $this->l('Save')
  589. );
  590. // Default cancel button - like old back link
  591. if (!isset($this->no_back) || $this->no_back == false)
  592. {
  593. $back = Tools::safeOutput(Tools::getValue('back', ''));
  594. if (empty($back))
  595. $back = self::$currentIndex.'&token='.$this->token;
  596. $this->toolbar_btn['cancel'] = array(
  597. 'href' => $back,
  598. 'desc' => $this->l('Cancel')
  599. );
  600. }
  601. break;
  602. default:
  603. parent::initToolbar();
  604. $this->toolbar_btn['import'] = array(
  605. 'href' => $this->context->link->getAdminLink('AdminImport', true).'&import_type=manufacturers',
  606. 'desc' => $this->l('Import')
  607. );
  608. }
  609. }
  610. public function renderView()
  611. {
  612. if (!($manufacturer = $this->loadObject()))
  613. return;
  614. $this->toolbar_btn['new'] = array(
  615. 'href' => $this->context->link->getAdminLink('AdminManufacturers').'&addaddress=1&id_manufacturer='.(int)$manufacturer->id,
  616. 'desc' => $this->l('Add address')
  617. );
  618. $this->toolbar_title = is_array($this->breadcrumbs) ? array_unique($this->breadcrumbs) : array($this->breadcrumbs);
  619. $this->toolbar_title[] = $manufacturer->name;
  620. $addresses = $manufacturer->getAddresses($this->context->language->id);
  621. $products = $manufacturer->getProductsLite($this->context->language->id);
  622. $total_product = count($products);
  623. for ($i = 0; $i < $total_product; $i++)
  624. {
  625. $products[$i] = new Product($products[$i]['id_product'], false, $this->context->language->id);
  626. $products[$i]->loadStockData();
  627. /* Build attributes combinations */
  628. $combinations = $products[$i]->getAttributeCombinations($this->context->language->id);
  629. foreach ($combinations as $k => $combination)
  630. {
  631. $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference'];
  632. $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13'];
  633. $comb_array[$combination['id_product_attribute']]['upc'] = $combination['upc'];
  634. $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity'];
  635. $comb_array[$combination['id_product_attribute']]['attributes'][] = array(
  636. $combination['group_name'],
  637. $combination['attribute_name'],
  638. $combination['id_attribute']
  639. );
  640. }
  641. if (isset($comb_array))
  642. {
  643. foreach ($comb_array as $key => $product_attribute)
  644. {
  645. $list = '';
  646. foreach ($product_attribute['attributes'] as $attribute)
  647. $list .= $attribute[0].' - '.$attribute[1].', ';
  648. $comb_array[$key]['attributes'] = rtrim($list, ', ');
  649. }
  650. isset($comb_array) ? $products[$i]->combination = $comb_array : '';
  651. unset($comb_array);
  652. }
  653. }
  654. $this->tpl_view_vars = array(
  655. 'manufacturer' => $manufacturer,
  656. 'addresses' => $addresses,
  657. 'products' => $products,
  658. 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
  659. 'shopContext' => Shop::getContext(),
  660. );
  661. return parent::renderView();
  662. }
  663. public function initContent()
  664. {
  665. $this->initTabModuleList();
  666. // toolbar (save, cancel, new, ..)
  667. $this->initToolbar();
  668. $this->initPageHeaderToolbar();
  669. if ($this->display == 'editaddresses' || $this->display == 'addaddress')
  670. $this->content .= $this->renderFormAddress();
  671. else if ($this->display == 'edit' || $this->display == 'add')
  672. {
  673. if (!$this->loadObject(true))
  674. return;
  675. $this->content .= $this->renderForm();
  676. }
  677. else if ($this->display == 'view')
  678. {
  679. // Some controllers use the view action without an object
  680. if ($this->className)
  681. $this->loadObject(true);
  682. $this->content .= $this->renderView();
  683. }
  684. else if (!$this->ajax)
  685. {
  686. $this->content .= $this->renderList();
  687. $this->content .= $this->renderOptions();
  688. }
  689. $this->context->smarty->assign(array(
  690. 'content' => $this->content,
  691. 'url_post' => self::$currentIndex.'&token='.$this->token,
  692. 'show_page_header_toolbar' => $this->show_page_header_toolbar,
  693. 'page_header_toolbar_title' => $this->page_header_toolbar_title,
  694. 'page_header_toolbar_btn' => $this->page_header_toolbar_btn
  695. ));
  696. }
  697. /**
  698. * AdminController::init() override
  699. * @see AdminController::init()
  700. */
  701. public function init()
  702. {
  703. parent::init();
  704. if (Tools::isSubmit('editaddresses'))
  705. $this->display = 'editaddresses';
  706. else if (Tools::isSubmit('updateaddress'))
  707. $this->display = 'editaddresses';
  708. else if (Tools::isSubmit('addaddress'))
  709. $this->display = 'addaddress';
  710. else if (Tools::isSubmit('submitAddaddress'))
  711. $this->action = 'save';
  712. else if (Tools::isSubmit('deleteaddress'))
  713. $this->action = 'delete';
  714. }
  715. public function initProcess()
  716. {
  717. if (Tools::isSubmit('submitAddaddress') || Tools::isSubmit('deleteaddress') || Tools::isSubmit('submitBulkdeleteaddress') || Tools::isSubmit('exportaddress'))
  718. {
  719. $this->table = 'address';
  720. $this->className = 'Address';
  721. $this->identifier = 'id_address';
  722. $this->deleted = true;
  723. $this->fields_list = $this->getAddressFieldsList();
  724. }
  725. parent::initProcess();
  726. }
  727. protected function afterImageUpload()
  728. {
  729. $res = true;
  730. /* Generate image with differents size */
  731. if (($id_manufacturer = (int)Tools::getValue('id_manufacturer')) &&
  732. isset($_FILES) &&
  733. count($_FILES) &&
  734. file_exists(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg'))
  735. {
  736. $images_types = ImageType::getImagesTypes('manufacturers');
  737. foreach ($images_types as $k => $image_type)
  738. {
  739. $res &= ImageManager::resize(
  740. _PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg',
  741. _PS_MANU_IMG_DIR_.$id_manufacturer.'-'.stripslashes($image_type['name']).'.jpg',
  742. (int)$image_type['width'],
  743. (int)$image_type['height']
  744. );
  745. }
  746. $current_logo_file = _PS_TMP_IMG_DIR_.'manufacturer_mini_'.$id_manufacturer.'_'.$this->context->shop->id.'.jpg';
  747. if ($res && file_exists($current_logo_file))
  748. unlink($current_logo_file);
  749. }
  750. if (!$res)
  751. $this->errors[] = Tools::displayError('Unable to resize one or more of your pictures.');
  752. return $res;
  753. }
  754. protected function beforeDelete($object)
  755. {
  756. return true;
  757. }
  758. public function processSave()
  759. {
  760. parent::processSave();
  761. if (Tools::isSubmit('submitAddaddress'))
  762. $this->display = 'editaddresses';
  763. }
  764. }