From 166d0e956ffbc94eeebd8e66930bec09964906a5 Mon Sep 17 00:00:00 2001 From: lLefevre Date: Fri, 28 Oct 2011 12:20:50 +0000 Subject: [PATCH] [*] BO #PSFV-94 : Added AdminManufacturerController --- admin-dev/tabs/AdminManufacturers.php | 309 --------- .../themes/template/helper/form/form.tpl | 24 +- .../form_addresses.tpl} | 58 +- .../list_action_edit_adresses.tpl | 27 + .../template/manufacturers/list_header.tpl | 202 ++++++ .../themes/template/manufacturers/view.tpl | 102 +++ classes/HelperForm.php | 4 + classes/Manufacturer.php | 201 +++--- .../admin/AdminCategoriesController.php | 1 + .../admin/AdminManufacturersController.php | 652 ++++++++++++++++++ 10 files changed, 1153 insertions(+), 427 deletions(-) delete mode 100644 admin-dev/tabs/AdminManufacturers.php rename admin-dev/themes/template/{categories/form.tpl => manufacturers/form_addresses.tpl} (90%) create mode 100644 admin-dev/themes/template/manufacturers/list_action_edit_adresses.tpl create mode 100644 admin-dev/themes/template/manufacturers/list_header.tpl create mode 100644 admin-dev/themes/template/manufacturers/view.tpl create mode 100644 controllers/admin/AdminManufacturersController.php diff --git a/admin-dev/tabs/AdminManufacturers.php b/admin-dev/tabs/AdminManufacturers.php deleted file mode 100644 index 14aab5664..000000000 --- a/admin-dev/tabs/AdminManufacturers.php +++ /dev/null @@ -1,309 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7300 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class AdminManufacturers extends AdminTab -{ - /** @var array countries list */ - private $countriesArray = array(); - - public function __construct() - { - - $this->table = 'manufacturer'; - $this->className = 'Manufacturer'; - $this->lang = false; - $this->edit = true; - $this->delete = true; - $this->context = Context::getContext(); - - // Sub tab addresses - $countries = Country::getCountries($this->context->language->id); - foreach ($countries AS $country) - $this->countriesArray[$country['id_country']] = $country['name']; - - $this->fieldsDisplayAddresses = array( - 'id_address' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'm!manufacturer_name' => array('title' => $this->l('Manufacturer'), 'width' => 100), - 'firstname' => array('title' => $this->l('First name'), 'width' => 80), - 'lastname' => array('title' => $this->l('Last name'), 'width' => 100, 'filter_key' => 'a!name'), - 'postcode' => array('title' => $this->l('Postcode/ Zip Code'), 'align' => 'right', 'width' => 50), - 'city' => array('title' => $this->l('City'), 'width' => 150), - 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'select' => $this->countriesArray, 'filter_key' => 'cl!id_country')); - $this->_includeTabTitle = array($this->l('Manufacturers addresses')); - $this->_joinAddresses = 'LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON - (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.') '; - $this->_joinAddresses .= 'LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (a.`id_manufacturer` = m.`id_manufacturer`)'; - $this->_selectAddresses = 'cl.`name` as country, m.`name` AS manufacturer_name'; - $this->_includeTab = array('Addresses' => array('addressType' => 'manufacturer', 'fieldsDisplay' => $this->fieldsDisplayAddresses, '_join' => $this->_joinAddresses, '_select' => $this->_selectAddresses)); - $this->view = true; - $this->_select = 'COUNT(`id_product`) AS `products`, (SELECT COUNT(ad.`id_manufacturer`) as `addresses` FROM `'._DB_PREFIX_.'address` ad WHERE ad.`id_manufacturer` = a.`id_manufacturer` AND ad.`deleted` = 0 GROUP BY ad.`id_manufacturer`) as `addresses`'; - $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_manufacturer` = p.`id_manufacturer`)'; - $this->_joinCount = false; - - $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'm'); - - $this->fieldsDisplay = array( - 'id_manufacturer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'name' => array('title' => $this->l('Name'), 'width' => 200), - 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'm', 'orderby' => false, 'search' => false), - 'addresses' => array('title' => $this->l('Addresses'), 'align' => 'right', 'tmpTableFilter' => true, 'width' => 20), - 'products' => array('title' => $this->l('Products'), 'align' => 'right', 'tmpTableFilter' => true, 'width' => 20), - 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) - ); - - parent::__construct(); - } - - public function afterImageUpload() - { - /* Generate image with differents size */ - if (($id_manufacturer = (int)(Tools::getValue('id_manufacturer'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg')) - { - $imagesTypes = ImageType::getImagesTypes('manufacturers'); - foreach ($imagesTypes AS $k => $imageType) - imageResize(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg', _PS_MANU_IMG_DIR_.$id_manufacturer.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); - } - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($manufacturer = $this->loadObject(true))) - return; - $langtags = 'cdesc2¤cdesc¤mmeta_title¤mmeta_keywords¤mmeta_description'; - - echo ' -
- '.($manufacturer->id ? '' : '').' -
- '.$this->l('Manufacturers').' - -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
'; - - echo '
-
'; - foreach ($this->_languages as $language) - echo ' -
- -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'cdesc2'); - echo '
'; - - echo '


-
'; - foreach ($this->_languages as $language) - echo ' -
- -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'cdesc'); - echo '
'; - - // TinyMCE - $iso = $this->context->language->iso_code; - $isoTinyMCE = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en'); - $ad = dirname($_SERVER["PHP_SELF"]); - echo ' - - - '; - echo '


-
'; - $this->displayImage($manufacturer->id, _PS_MANU_IMG_DIR_.$manufacturer->id.'.jpg', 350, NULL, NULL, true); - echo '
-

'.$this->l('Upload manufacturer logo from your computer').'

-
- -
'; - foreach ($this->_languages as $language) - echo ' -
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_title'); - echo '
-
- -
'; - foreach ($this->_languages as $language) - echo '
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_description'); - echo '
-
- -
'; - foreach ($this->_languages as $language) - echo ' -
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'mmeta_keywords'); - echo '
-
- -
- getFieldValue($manufacturer, 'active') ? 'checked="checked" ' : '').'/> - - getFieldValue($manufacturer, 'active') ? 'checked="checked" ' : '').'/> - -
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop('group_shop'); - echo '
'; - } - echo ' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } - - public function viewmanufacturer() - { - if (!($manufacturer = $this->loadObject())) - return; - echo '

'.$manufacturer->name.'

'; - - $products = $manufacturer->getProductsLite($this->context->language->id); - $addresses = $manufacturer->getAddresses($this->context->language->id); - - echo '

'.$this->l('Total addresses:').' '.sizeof($addresses).'

'; - echo '
'; - foreach ($addresses AS $addresse) - echo ' -

- - - - - - - -
'.$addresse['firstname'].' '.$addresse['lastname'].'
-
- '.$addresse['address1'].'
- '.($addresse['address2'] ? $addresse['address2'].'
' : '').' - '.$addresse['postcode'].' '.$addresse['city'].'
- '.($addresse['state'] ? $addresse['state'].'
' : '').' - '.$addresse['country'].'
-
-
- '.($addresse['phone'] ? $addresse['phone'].'
' : '').' - '.($addresse['phone_mobile'] ? $addresse['phone_mobile'].'
' : '').' -
- '.($addresse['other'] ? '

'.$addresse['other'].'
' : '').' -
'; - if (!sizeof($addresses)) - echo 'No address for this manufacturer.'; - echo '

'; - echo '

'.$this->l('Total products:').' '.sizeof($products).'

'; - foreach ($products AS $product) - { - $product = new Product($product['id_product'], false, $this->context->language->id); - echo '
'; - if (!$product->hasAttributes()) - { - echo ' -
- '.$this->l('Edit').' - '.$this->l('Delete').' -
- - - - '.(!empty($product->reference) ? '' : '').' - '.(!empty($product->ean13) ? '' : '').' - '.(!empty($product->upc) ? '' : '').' - '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' - -
'.$product->name.''.$this->l('Ref:').' '.$product->reference.''.$this->l('EAN13:').' '.$product->ean13.''.$this->l('UPC:').' '.$product->upc.''.$this->l('Qty:').' '.$product->quantity.'
'; - } - else - { - echo ' -
- '.$this->l('Edit').' - '.$this->l('Delete').' -
-

'.$product->name.'

- - - - - - - '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' - '; - /* Build attributes combinaisons */ - $combinaisons = $product->getAttributeCombinaisons($this->context->language->id); - foreach ($combinaisons AS $k => $combinaison) - { - $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference']; - $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13']; - $combArray[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; - $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity']; - $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']); - } - $irow = 0; - foreach ($combArray AS $id_product_attribute => $product_attribute) - { - $list = ''; - foreach ($product_attribute['attributes'] AS $attribute) - $list .= $attribute[0].' - '.$attribute[1].', '; - $list = rtrim($list, ', '); - echo ' - - - - '.(Configuration::get('PS_STOCK_MANAGEMENT') ? '' : '').' - - '; - } - unset($combArray); - echo '
'.$this->l('Attribute name').''.$this->l('Reference').''.$this->l('EAN13').''.$this->l('UPC').''.$this->l('Quantity').'
'.stripslashes($list).''.$product_attribute['reference'].''.$product_attribute['ean13'].''.$product_attribute['upc'].''.$product_attribute['quantity'].'
'; - } - } - } -} diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index 57a7cbb6a..c2511f957 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -240,8 +240,18 @@
{/foreach} {elseif $input.type == 'file'} + {if $input.display_image} + {if isset($fields_value.image) && $fields_value.image} +
+ {$fields_value.image} +

{l s='File size'} {$fields_value.size}kb

+ + {l s='Delete'} {l s='Delete'} + +

+ {/if} + {/if} - {elseif $input.type == 'password'} {l s='Shop association:'}
@@ -290,6 +303,15 @@ {if $required_fields}
* {l s ='Required field'}
{/if} + {if isset($fields.tinymce) && $fields.tinymce} + + + + {/if} diff --git a/admin-dev/themes/template/categories/form.tpl b/admin-dev/themes/template/manufacturers/form_addresses.tpl similarity index 90% rename from admin-dev/themes/template/categories/form.tpl rename to admin-dev/themes/template/manufacturers/form_addresses.tpl index 37f3bc2ec..ef93b8d8c 100644 --- a/admin-dev/themes/template/categories/form.tpl +++ b/admin-dev/themes/template/manufacturers/form_addresses.tpl @@ -31,20 +31,26 @@ var id_language = {$defaultFormLanguage}; var languages = new Array(); - $(document).ready(function() { + $(document).ready(function() {ldelim} {foreach $languages as $k => $language} - languages[{$k}] = { + languages[{$k}] = {ldelim} id_lang: {$language.id_lang}, iso_code: '{$language.iso_code}', name: '{$language.name}' - }; + {rdelim}; {/foreach} displayFlags(languages, id_language, {$allowEmployeeFormLang}); - $('input[name=name_'+id_language+']').keyup(function() { - $('input[name=link_rewrite_'+id_language+']').val(str2url($(this).val())); - }); - }); + {if isset($fields_value.id_state)} + if ($('#id_country') && $('#id_state')) + {ldelim} + ajaxStates({$fields_value.id_state}); + $('#id_country').change(function() {ldelim} + ajaxStates(); + {rdelim}); + {rdelim} + {/if} + {rdelim}); {/if} @@ -65,13 +71,17 @@ {if $input.name == 'id_state'}
{/if} + {block name="label"} {if isset($input.label)} - + {/if} + {/block} {if $input.type == 'hidden'} {else} -
+ {block name="start_field_block"} +
+ {/block} {if $input.type == 'text'} {if isset($input.lang) && isset($input.attributeLang)} {foreach $languages as $language} @@ -115,6 +125,7 @@ {if isset($input.class)}class="{$input.class}"{/if} {if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} {if isset($input.disabled) && $input.disabled}disabled="disabled"{/if} /> + {if isset($input.suffix)}{$input.suffix}{/if} {if isset($input.hint)}{$input.hint} {/if} {/if} {elseif $input.type == 'select'} @@ -215,18 +226,8 @@
{/foreach} {elseif $input.type == 'file'} - {if $input.display_image} - {if isset($fields_value.image) && $fields_value.image} -
- {$fields_value.image} -

{l s='File size'} {$fields_value.size}kb

- - {l s='Delete'} {l s='Delete'} - -

- {/if} - {/if} + {elseif $input.type == 'password'} {elseif $input.type == 'group'} {assign var=groups value=$input.values} - {include file='helper/form/form_group.tpl'} + {include file='form_group.tpl'} {elseif $input.type == 'shop' OR $input.type == 'group_shop'} - {include file='helper/form/form_shop.tpl'} - {elseif $input.type == 'categories'} - {assign var=categories value=$input.values} - {include file='helper/form/form_category.tpl'} + {include file='form_shop.tpl'} {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop}
@@ -263,7 +261,7 @@

{/if} {if isset($languages)}
{/if} -
+ {block name="end_field_block"}
{/block} {/if} {if $input.name == 'id_state'}
@@ -281,14 +279,6 @@ - - - -

{if $firstCall && !$no_back} {if $back} diff --git a/admin-dev/themes/template/manufacturers/list_action_edit_adresses.tpl b/admin-dev/themes/template/manufacturers/list_action_edit_adresses.tpl new file mode 100644 index 000000000..ca6ee9ac6 --- /dev/null +++ b/admin-dev/themes/template/manufacturers/list_action_edit_adresses.tpl @@ -0,0 +1,27 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9197 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{$action} \ No newline at end of file diff --git a/admin-dev/themes/template/manufacturers/list_header.tpl b/admin-dev/themes/template/manufacturers/list_header.tpl new file mode 100644 index 000000000..effd37115 --- /dev/null +++ b/admin-dev/themes/template/manufacturers/list_header.tpl @@ -0,0 +1,202 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9639 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if !$simple_header} + + + + {* Display column names and arrows for ordering (ASC, DESC) *} + {if $is_order_position} + + + + {/if} + + + +
+ +
{* todo : what to display as title for each items (table_lang.name ? *} +

{$current_obj_name|default:' '}

+
+
+   +

{$title_list}

+ + +
+{/if}{* End if simple_header *} + + + {if !$simple_header} + + + + {/if} + + +
+ + {if $page > 1} +   + + {/if} + {l s='Page '}{$page} / {$total_pages} + {if $page < $total_pages} +   + + {/if} + | {l s='Display'} + + / {$list_total} {l s='result(s)'} + + + + + + +
+ + + + {foreach $fields_display AS $key => $params} + + {/foreach} + + {if $shop_link_type} + + {/if} + {if $has_actions} + + {/if} + + {if !$simple_header} + + + + {* Filters (input, select, date or bool) *} + {foreach $fields_display AS $key => $params} + + {/foreach} + + {if $shop_link_type} + + {/if} + {if $has_actions} + + {/if} + + {/if} + \ No newline at end of file diff --git a/admin-dev/themes/template/manufacturers/view.tpl b/admin-dev/themes/template/manufacturers/view.tpl new file mode 100644 index 000000000..d14d5a5d3 --- /dev/null +++ b/admin-dev/themes/template/manufacturers/view.tpl @@ -0,0 +1,102 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9646 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{$manufacturer->name}

+ +

{l s='Total addresses:'} {count($addresses)}

+
+ +{if !count($addresses)} + {l s='No address for this manufacturer'} +{else} + {foreach $addresses AS $addresse} +
+ {if $delete} + + {/if} + {$params.title} + {if (!isset($params.orderby) || $params.orderby) && !$simple_header} +
+ + + + + + + {/if} +
+ {if $shop_link_type == 'shop'} + {l s='shop'} + {else} + {l s='Group shop'} + {/if} + {l s='Actions'}
+ {if $delete} + -- + {/if} + + {if isset($params.search) && !$params.search} + -- + {else} + {if $params.type == 'bool'} + + {elseif $params.type == 'date' || $params.type == 'datetime'} + {l s='From'}
+ {l s='To'} + {elseif $params.type == 'select'} + {if isset($params.filter_key)} + + {/if} + {else} + + {/if} + {/if} +
----
+ + + + + + +
{$addresse.firstname} {$addresse.lastname}
+
+ {$addresse.address1}
+ {if $addresse.address2}{$addresse.address2}
{/if} + {$addresse.postcode} {$addresse.city}
+ {if $addresse.state}{$addresse.state}
{/if} + {$addresse.country}
+
+
+ {if $addresse.phone}{$addresse.phone}
{/if} + {if $addresse.phone_mobile}{$addresse.phone_mobile}
{/if} +
+ {if $addresse.other}

{$addresse.other}
{/if} +

+ {/foreach} +{/if} +

+ +

{l s='Total products:'} {count($products)}

+{foreach $products AS $product} +
+ {if !$product->hasAttributes()} + + + + + {if !empty($product->reference)}{/if} + {if !empty($product->ean13)}{/if} + {if !empty($product->upc)}{/if} + +
{$product->name}{l s='Ref:'} {$product->reference}{l s='EAN13:'} {$product->ean13}{l s='UPC:'} {$product->upc}
+ {else} + +

{$product->name}

+ + + + + + + + {foreach $product->combinaison AS $id_product_attribute => $product_attribute} + + + + + + + {/foreach} +
{l s='Attribute name'}{l s='Reference'}{l s='EAN13'}{l s='UPC'}
{$product_attribute.attributes}{$product_attribute.reference}{$product_attribute.ean13}{$product_attribute.upc}
+ {/if} +{/foreach} +

+ {l s='Back to manufacturer list'}
diff --git a/classes/HelperForm.php b/classes/HelperForm.php index e5ad4c5c4..63337fd67 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -75,6 +75,7 @@ class HelperFormCore extends Helper if ($this->submit_action == '') $this->submit_action = 'submitAdd'.$this->table; + $iso = $this->context->language->iso_code; $this->context->smarty->assign(array( 'submit_action' => $this->submit_action, 'toolbar_btn' => $this->toolbar_btn, @@ -95,6 +96,9 @@ class HelperFormCore extends Helper 'module_dir' => _MODULE_DIR_, 'contains_states' => (isset($this->fields_value['id_country']) && isset($this->fields_value['id_state'])) ? Country::containsStates($this->fields_value['id_country']) : null, 'asso_shop' => (isset($this->fields_form['asso_shop']) && $this->fields_form['asso_shop']) ? $this->displayAssoShop() : null, + 'iso' => file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en', + 'path_css' => _THEME_CSS_DIR_, + 'ad' => dirname($_SERVER["PHP_SELF"]) )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl); diff --git a/classes/Manufacturer.php b/classes/Manufacturer.php index 8294f0a20..f66a3ae69 100644 --- a/classes/Manufacturer.php +++ b/classes/Manufacturer.php @@ -27,55 +27,61 @@ class ManufacturerCore extends ObjectModel { - public $id; + public $id; /** @var integer manufacturer ID */ - public $id_manufacturer;//FIXME is it really usefull...? + public $id_manufacturer;//FIXME is it really usefull...? /** @var string Name */ - public $name; + public $name; /** @var string A description */ - public $description; + public $description; /** @var string A short description */ - public $short_description; + public $short_description; /** @var int Address */ - public $id_address; + public $id_address; /** @var string Object creation date */ - public $date_add; + public $date_add; /** @var string Object last modification date */ - public $date_upd; + public $date_upd; /** @var string Friendly URL */ - public $link_rewrite; + public $link_rewrite; /** @var string Meta title */ - public $meta_title; + public $meta_title; /** @var string Meta keywords */ - public $meta_keywords; + public $meta_keywords; /** @var string Meta description */ - public $meta_description; + public $meta_description; /** @var boolean active */ - public $active; + public $active; - protected $fieldsRequired = array('name'); - protected $fieldsSize = array('name' => 64); - protected $fieldsValidate = array('name' => 'isCatalogName'); + protected $fieldsRequired = array('name'); + protected $fieldsSize = array('name' => 64); + protected $fieldsValidate = array('name' => 'isCatalogName'); - protected $fieldsSizeLang = array('short_description' => 254, 'meta_title' => 128, 'meta_description' => 255, 'meta_description' => 255); - protected $fieldsValidateLang = array('description' => 'isString', 'short_description' => 'isString', 'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName'); + protected $fieldsSizeLang = array('short_description' => 254, 'meta_title' => 128, 'meta_description' => 255, 'meta_description' => 255); + protected $fieldsValidateLang = array( + 'description' => 'isString', + 'short_description' => 'isString', + 'meta_title' => 'isGenericName', + 'meta_description' => 'isGenericName', + 'meta_keywords' => 'isGenericName' + ); - protected $table = 'manufacturer'; - protected $identifier = 'id_manufacturer'; + protected $table = 'manufacturer'; + protected $identifier = 'id_manufacturer'; - protected $webserviceParameters = array( + protected $webserviceParameters = array( 'fields' => array( 'active' => array(), 'link_rewrite' => array('getter' => 'getLink', 'setter' => false), @@ -87,7 +93,7 @@ class ManufacturerCore extends ObjectModel ), ); - public function __construct($id = NULL, $id_lang = NULL) + public function __construct($id = null, $id_lang = null) { parent::__construct($id, $id_lang); @@ -101,11 +107,11 @@ class ManufacturerCore extends ObjectModel { $this->validateFields(); if (isset($this->id)) - $fields['id_manufacturer'] = (int)($this->id); + $fields['id_manufacturer'] = (int)$this->id; $fields['name'] = pSQL($this->name); $fields['date_add'] = pSQL($this->date_add); $fields['date_upd'] = pSQL($this->date_upd); - $fields['active'] = (int)($this->active); + $fields['active'] = (int)$this->active; return $fields; } @@ -137,23 +143,27 @@ class ManufacturerCore extends ObjectModel */ public function deleteSelection($selection) { - if (!is_array($selection) OR !Validate::isTableOrIdentifier($this->identifier) OR !Validate::isTableOrIdentifier($this->table)) + if (!is_array($selection) || !Validate::isTableOrIdentifier($this->identifier) || !Validate::isTableOrIdentifier($this->table)) die(Tools::displayError()); $result = true; - foreach ($selection AS $id) + foreach ($selection as $id) { - $this->id = (int)($id); + $this->id = (int)$id; $this->id_address = self::getManufacturerAddress(); - $result = $result AND $this->delete(); + $result = $result && $this->delete(); } return $result; } protected function getManufacturerAddress() { - if (!(int)($this->id)) + if (!(int)$this->id) return false; - $result = Db::GetInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT `id_address` FROM '._DB_PREFIX_.'address WHERE `id_manufacturer` = '.(int)($this->id)); + $result = Db::GetInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT `id_address` + FROM '._DB_PREFIX_.'address + WHERE `id_manufacturer` = '.(int)$this->id + ); if (!$result) return false; return $result['id_address']; @@ -162,50 +172,51 @@ class ManufacturerCore extends ObjectModel /** * Return manufacturers * - * @param boolean $getNbProducts [optional] return products numbers for each + * @param boolean $get_nb_products [optional] return products numbers for each * @return array Manufacturers */ - static public function getManufacturers($getNbProducts = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_group_shop = false) + public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $id_group_shop = false) { if (!$id_lang) $id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); if (!$id_group_shop) $id_group_shop = Shop::getGroupFromShop(Configuration::get('PS_SHOP_DEFAULT')); $sql = 'SELECT m.*, ml.`description`'; - $sql.= 'FROM `'._DB_PREFIX_.'manufacturer_group_shop` mgs + $sql .= 'FROM `'._DB_PREFIX_.'manufacturer_group_shop` mgs LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.id_manufacturer = mgs.id_manufacturer) - LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)($id_lang).') + LEFT JOIN `'._DB_PREFIX_.'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = '.(int)$id_lang.') WHERE mgs.id_group_shop='.(int)$id_group_shop.($active ? ' AND m.`active` = 1' : ''); - $sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n) : ''); + $sql .= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''); $manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if ($manufacturers === false) return false; - if ($getNbProducts) + if ($get_nb_products) { - $sqlGroups = ''; + $sql_groups = ''; if (!$all_group) { $groups = FrontController::getCurrentCustomerGroups(); - $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); } foreach ($manufacturers as $key => $manufacturer) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`) - WHERE m.`id_manufacturer` = '.(int)($manufacturer['id_manufacturer']). + WHERE m.`id_manufacturer` = '.(int)$manufacturer['id_manufacturer']. ($active ? ' AND p.`active` = 1 ' : ''). ($all_group ? '' : ' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sqlGroups.')')); + WHERE cg.`id_group` '.$sql_groups.')')); - $manufacturers[$key]['nb_products'] = sizeof($result); + $manufacturers[$key]['nb_products'] = count($result); } } - for ($i = 0; $i < sizeof($manufacturers); $i++) - if ((int)(Configuration::get('PS_REWRITING_SETTINGS'))) + $total_manufacturers = count($manufacturers); + for ($i = 0; $i < $total_manufacturers; $i++) + if ((int)Configuration::get('PS_REWRITING_SETTINGS')) $manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false); else $manufacturers[$i]['link_rewrite'] = 0; @@ -223,7 +234,11 @@ class ManufacturerCore extends ObjectModel { if (!isset(self::$cacheName[$id_manufacturer])) self::$cacheName[$id_manufacturer] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `name` FROM `'._DB_PREFIX_.'manufacturer` WHERE `id_manufacturer` = '.(int)($id_manufacturer).' AND `active` = 1'); + SELECT `name` + FROM `'._DB_PREFIX_.'manufacturer` + WHERE `id_manufacturer` = '.(int)$id_manufacturer.' + AND `active` = 1' + ); return self::$cacheName[$id_manufacturer]; } @@ -234,7 +249,7 @@ class ManufacturerCore extends ObjectModel FROM `'._DB_PREFIX_.'manufacturer` WHERE `name` = \''.pSQL($name).'\''); if (isset($result['id_manufacturer'])) - return (int)($result['id_manufacturer']); + return (int)$result['id_manufacturer']; return false; } @@ -243,72 +258,91 @@ class ManufacturerCore extends ObjectModel return Tools::link_rewrite($this->name, false); } - static public function getProducts($id_manufacturer, $id_lang, $p, $n, $orderBy = NULL, $orderWay = NULL, $getTotal = false, $active = true, $active_category = true, Context $context = null) + public static function getProducts($id_manufacturer, $id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true, Context $context = null) { if (!$context) $context = Context::getContext(); - if ($p < 1) $p = 1; - if (empty($orderBy) ||$orderBy == 'position') $orderBy = 'name'; - if (empty($orderWay)) $orderWay = 'ASC'; - if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) + if ($p < 1) + $p = 1; + + if (empty($order_by) || $order_by == 'position') + $order_by = 'name'; + + if (empty($order_way)) $order_way = 'ASC'; + + if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)) die (Tools::displayError()); - + $groups = FrontController::getCurrentCustomerGroups(); - $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'; /* Return only the number of products */ - if ($getTotal) + if ($get_total) { $sql = ' SELECT p.`id_product` FROM `'._DB_PREFIX_.'product` p '.$context->shop->addSqlAssociation('product', 'p').' - WHERE p.id_manufacturer = '.(int)($id_manufacturer) + WHERE p.id_manufacturer = '.(int)$id_manufacturer .($active ? ' AND p.`active` = 1' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' - WHERE cg.`id_group` '.$sqlGroups.' + WHERE cg.`id_group` '.$sql_groups.' )'; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - return (int)(sizeof($result)); + return (int)count($result); } - $sql = 'SELECT p.*, sa.out_of_stock, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, - (p.`price` * ((100 + (t.`rate`))/100)) AS orderprice + $sql = 'SELECT p.*, sa.out_of_stock, pa.`id_product_attribute`, pl.`description`, pl.`description_short`, pl.`link_rewrite`, + pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, i.`id_image`, il.`legend`, m.`name` AS manufacturer_name, + tl.`name` AS tax_name, t.`rate`, DATEDIFF(p.`date_add`, DATE_SUB(NOW(), + INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new, + (p.`price` * ((100 + (t.`rate`))/100)) AS orderprice FROM `'._DB_PREFIX_.'product` p '.$context->shop->addSqlAssociation('product', 'p').' - LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').') - LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) - LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` - AND tr.`id_country` = '.(int)$context->country->id.' - AND tr.`id_state` = 0 - AND tr.`zipcode_from` = 0) - LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`) - LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) - LEFT JOIN `'._DB_PREFIX_.'stock_available` sa ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0) - WHERE p.`id_manufacturer` = '.(int)($id_manufacturer).($active ? ' AND p.`active` = 1' : '').' + LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa + ON (p.`id_product` = pa.`id_product` AND default_on = 1) + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').') + LEFT JOIN `'._DB_PREFIX_.'image` i + ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) + LEFT JOIN `'._DB_PREFIX_.'image_lang` il + ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr + ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` + AND tr.`id_country` = '.(int)$context->country->id.' + AND tr.`id_state` = 0 + AND tr.`zipcode_from` = 0) + LEFT JOIN `'._DB_PREFIX_.'tax` t + ON (t.`id_tax` = tr.`id_tax`) + LEFT JOIN `'._DB_PREFIX_.'tax_lang` tl + ON (t.`id_tax` = tl.`id_tax` AND tl.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m + ON (m.`id_manufacturer` = p.`id_manufacturer`) + LEFT JOIN `'._DB_PREFIX_.'stock_available` sa + ON (sa.`id_product` = p.`id_product` AND sa.id_product_attribute = 0) + WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.($active ? ' + AND p.`active` = 1' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg - LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)'. + LEFT JOIN `'._DB_PREFIX_.'category_product` cp + ON (cp.`id_category` = cg.`id_category`)'. ($active_category ? ' INNER JOIN `'._DB_PREFIX_.'category` ca ON cp.`id_category` = ca.`id_category` AND ca.`active` = 1' : '').' - WHERE cg.`id_group` '.$sqlGroups.' + WHERE cg.`id_group` '.$sql_groups.' ) - ORDER BY '.(($orderBy == 'id_product') ? 'p.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).' + ORDER BY '.(($order_by == 'id_product') ? 'p.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); if (!$result) return false; - if ($orderBy == 'price') - Tools::orderbyPrice($result, $orderWay); + if ($order_by == 'price') + Tools::orderbyPrice($result, $order_way); return Product::getProductsProperties($id_lang, $result); } @@ -316,7 +350,8 @@ class ManufacturerCore extends ObjectModel { $sql = 'SELECT p.`id_product`, pl.`name` FROM `'._DB_PREFIX_.'product` p - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').') + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('pl').') WHERE p.`id_manufacturer` = '.(int)$this->id; return Db::getInstance()->executeS($sql); } @@ -331,7 +366,7 @@ class ManufacturerCore extends ObjectModel $row = Db::getInstance()->getRow(' SELECT `id_manufacturer` FROM '._DB_PREFIX_.'manufacturer m - WHERE m.`id_manufacturer` = '.(int)($id_manufacturer)); + WHERE m.`id_manufacturer` = '.(int)$id_manufacturer); return isset($row['id_manufacturer']); } @@ -341,21 +376,21 @@ class ManufacturerCore extends ObjectModel return Db::getInstance()->executeS(' SELECT a.*, cl.name AS `country`, s.name AS `state` FROM `'._DB_PREFIX_.'address` AS a - LEFT JOIN `'._DB_PREFIX_.'country_lang` AS cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)($id_lang).') + LEFT JOIN `'._DB_PREFIX_.'country_lang` AS cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'state` AS s ON (s.`id_state` = a.`id_state`) - WHERE `id_manufacturer` = '.(int)($this->id).' + WHERE `id_manufacturer` = '.(int)$this->id.' AND a.`deleted` = 0'); } - + public function getWsAddresses() { return Db::getInstance()->executeS(' SELECT a.id_address as id FROM `'._DB_PREFIX_.'address` AS a - WHERE `id_manufacturer` = '.(int)($this->id).' + WHERE `id_manufacturer` = '.(int)$this->id.' AND a.`deleted` = 0'); } - + public function setWsAddresses($id_addresses) { $ids = array(); diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 561eed879..2db460596 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -157,6 +157,7 @@ class AdminCategoriesControllerCore extends AdminController $selected_cat = ''; $this->fields_form = array( + 'tinymce' => true, 'legend' => array( 'title' => $this->l('Category'), 'image' => '../img/admin/tab-categories.gif' diff --git a/controllers/admin/AdminManufacturersController.php b/controllers/admin/AdminManufacturersController.php new file mode 100644 index 000000000..52c567cab --- /dev/null +++ b/controllers/admin/AdminManufacturersController.php @@ -0,0 +1,652 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 8971 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminManufacturersControllerCore extends AdminController +{ + /** @var array countries list */ + private $countries_array = array(); + + public function __construct() + { + $this->table = 'manufacturer'; + $this->className = 'Manufacturer'; + $this->lang = false; + $this->deleted = false; + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $this->requiredDatabase = true; + + $this->context = Context::getContext(); + + $this->fieldImageSettings = array( + 'name' => 'logo', + 'dir' => 'm' + ); + + $this->fieldsDisplay = array( + 'id_manufacturer' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'name' => array( + 'title' => $this->l('Name'), + 'width' => 200 + ), + 'logo' => array( + 'title' => $this->l('Logo'), + 'image' => 'm', + 'orderby' => false, + 'search' => false + ), + 'addresses' => array( + 'title' => $this->l('Addresses'), + 'tmpTableFilter' => true, + 'width' => 20 + ), + 'products' => array( + 'title' => $this->l('Products'), + 'tmpTableFilter' => true, + 'width' => 20 + ), + 'active' => array( + 'title' => $this->l('Enabled'), + 'width' => 25, + 'active' => 'status', + 'type' => 'bool', + 'orderby' => false + ) + ); + + parent::__construct(); + } + + public function initList() + { + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->addRowAction('view'); + + $this->_select = ' + COUNT(`id_product`) AS `products`, ( + SELECT COUNT(ad.`id_manufacturer`) as `addresses` + FROM `'._DB_PREFIX_.'address` ad + WHERE ad.`id_manufacturer` = a.`id_manufacturer` + AND ad.`deleted` = 0 + GROUP BY ad.`id_manufacturer`) as `addresses`'; + $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_manufacturer` = p.`id_manufacturer`)'; + $this->_group = 'GROUP BY a.`id_manufacturer`'; + + $this->context->smarty->assign('title_list', $this->l('List of manufacturers:')); + + $this->initToolbar(); + $this->content .= parent::initList(); + + // reset actions and query vars + $this->actions = array(); + unset($this->fieldsDisplay, $this->_select, $this->_join, $this->_group, $this->_filterHaving, $this->_filter); + + $this->table = 'address'; + $this->identifier = 'id_address'; + $this->deleted = true; + + $this->addRowAction('editaddresses'); + $this->addRowAction('delete'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + // test if a filter is applied for this list + if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false) + $this->filter = true; + + // test if a filter reset request is required for this list + if (isset($_POST['submitReset'.$this->table])) + $this->action = 'reset_filters'; + else + $this->action = ''; + + // Sub tab addresses + $countries = Country::getCountries($this->context->language->id); + foreach ($countries as $country) + $this->countries_array[$country['id_country']] = $country['name']; + + $this->fieldsDisplay = array( + 'id_address' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'manufacturer_name' => array( + 'title' => $this->l('Manufacturer'), + 'width' => 100 + ), + 'firstname' => array( + 'title' => $this->l('First name'), + 'width' => 80 + ), + 'lastname' => array( + 'title' => $this->l('Last name'), + 'width' => 100, + 'filter_key' => 'a!name' + ), + 'postcode' => array( + 'title' => $this->l('Postcode/ Zip Code'), + 'align' => 'right', + 'width' => 50 + ), + 'city' => array( + 'title' => $this->l('City'), + 'width' => 150 + ), + 'country' => array( + 'title' => $this->l('Country'), + 'width' => 100, + 'type' => 'select', + 'select' => $this->countries_array, + 'filter_key' => 'cl!id_country' + ) + ); + + $this->_select = 'cl.`name` as country, m.`name` AS manufacturer_name'; + $this->_join = ' + LEFT JOIN `'._DB_PREFIX_.'country_lang` cl + ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.') '; + $this->_join .= ' + LEFT JOIN `'._DB_PREFIX_.'manufacturer` m + ON (a.`id_manufacturer` = m.`id_manufacturer`)'; + $this->_where = 'AND a.`id_customer` = 0'; + + $this->context->smarty->assign('title_list', $this->l('Manufacturers addresses:')); + + // call postProcess() for take care about actions and filters + $this->postProcess(); + + $this->initToolbar(); + $this->content .= parent::initList(); + } + + /** + * Display editaddresses action link + * @param string $token the token to add to the link + * @param int $id the identifier to add to the link + * @return string + */ + public function displayEditaddressesLink($token = null, $id) + { + if (!array_key_exists('editaddresses', self::$cache_lang)) + self::$cache_lang['editaddresses'] = $this->l('Edit Adresses'); + + $this->context->smarty->assign(array( + 'href' => self::$currentIndex. + '&'.$this->identifier.'='.$id. + '&editaddresses&token='.($token != null ? $token : $this->token), + 'action' => self::$cache_lang['editaddresses'], + )); + + return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/manufacturers/list_action_edit_adresses.tpl'); + } + + public function initForm() + { + $lang_tags = 'short_description¤description¤meta_title¤meta_keywords¤meta_description'; + $this->fields_form = array( + 'tinymce' => true, + 'legend' => array( + 'title' => $this->l('Manufacturers'), + 'image' => '../img/admin/manufacturers.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'size' => 40, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Short description:'), + 'name' => 'short_description', + 'lang' => true, + 'attributeLang' => $lang_tags, + 'cols' => 60, + 'rows' => 10, + 'class' => 'rte', + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'textarea', + 'label' => $this->l('Description:'), + 'name' => 'description', + 'lang' => true, + 'attributeLang' => $lang_tags, + 'cols' => 60, + 'rows' => 10, + 'class' => 'rte', + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'file', + 'label' => $this->l('Logo:'), + 'name' => 'logo', + 'display_image' => true, + 'p' => $this->l('Upload manufacturer logo from your computer') + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta title:'), + 'name' => 'meta_title', + 'lang' => true, + 'attributeLang' => $lang_tags, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta description:'), + 'name' => 'meta_description', + 'lang' => true, + 'attributeLang' => $lang_tags, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta keywords:'), + 'name' => 'meta_keywords', + 'lang' => true, + 'attributeLang' => $lang_tags, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ), + array( + 'type' => 'radio', + 'label' => $this->l('Enable:'), + 'name' => 'active', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ) + ) + ) + ); + + /* + * Where it used? You can not insert into a table or in the fields of a table + */ + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'group_shop', + 'label' => $this->l('Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form['submit'] = array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ); + + if (!($manufacturer = $this->loadObject(true))) + return; + + $image = cacheImage(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg', $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350, $this->imageType, true); + + $this->fields_value = array( + 'image' => $image ? $image : false, + 'size' => $image ? filesize(_PS_MANU_IMG_DIR_.'/'.$manufacturer->id.'.jpg') / 1000 : false + ); + + foreach ($this->_languages as $language) + { + $this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue( + $manufacturer, + 'short_description', + $language['id_lang'] + )), ENT_COMPAT, 'UTF-8'); + + $this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue( + $manufacturer, + 'description', + $language['id_lang'] + )), ENT_COMPAT, 'UTF-8'); + } + + return parent::initForm(); + } + + public function initFormAddress() + { + // Change table and className for addresses + $this->table = 'address'; + $this->className = 'Address'; + $id_address = Tools::getValue('id_address'); + + // Create Object Address + $address = new Address($id_address); + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Addresses'), + 'image' => '../img/admin/contact.gif' + ) + ); + + if (!$address->id_manufacturer || !Manufacturer::manufacturerExists($address->id_manufacturer)) + $this->fields_form['input'][] = array( + 'type' => 'select', + 'label' => $this->l('Choose the manufacturer:'), + 'name' => 'id_manufacturer', + 'options' => array( + 'query' => Manufacturer::getManufacturers(), + 'id' => 'id_manufacturer', + 'name' => 'name' + ) + ); + else + { + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Manufacturer:'), + 'name' => 'name', + 'disabled' => true, + ); + + $this->fields_form['input'][] = array( + 'type' => 'hidden', + 'name' => 'id_manufacturer' + ); + } + + $this->fields_form['input'][] = array( + 'type' => 'hidden', + 'name' => 'alias', + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Last name:'), + 'name' => 'lastname', + 'size' => 33, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:' + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('First name:'), + 'name' => 'firstname', + 'size' => 33, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:' + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Address:'), + 'name' => 'address1', + 'size' => 33, + 'required' => true, + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Address (2):'), + 'name' => 'address2', + 'size' => 33, + 'required' => false, + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Postcode / Zip Code:'), + 'name' => 'postcode', + 'size' => 33, + 'required' => false, + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('City:'), + 'name' => 'city', + 'size' => 33, + 'required' => true, + ); + $this->fields_form['input'][] = array( + 'type' => 'select', + 'label' => $this->l('Country:'), + 'name' => 'id_country', + 'required' => false, + 'options' => array( + 'query' => Country::getCountries($this->context->language->id), + 'id' => 'id_country', + 'name' => 'name' + ) + ); + $this->fields_form['input'][] = array( + 'type' => 'select', + 'label' => $this->l('State:'), + 'name' => 'id_state', + 'required' => false, + 'options' => array( + 'query' => array(), + 'id' => 'id_state', + 'name' => 'name' + ) + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Home phone:'), + 'name' => 'phone', + 'size' => 33, + 'required' => false, + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Mobile phone:'), + 'name' => 'phone_mobile', + 'size' => 33, + 'required' => false, + ); + $this->fields_form['input'][] = array( + 'type' => 'textarea', + 'label' => $this->l('Other:'), + 'name' => 'other', + 'cols' => 36, + 'rows' => 4, + 'required' => false, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ); + $this->fields_form['submit'] = array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ); + + $this->fields_value = array( + 'name' => Manufacturer::getNameById($address->id_manufacturer), + 'alias' => 'manufacturer' + ); + + $this->getlanguages(); + $helper = new HelperForm(); + $helper->currentIndex = self::$currentIndex; + $helper->token = $this->token; + $helper->table = $this->table; + $helper->identifier = $this->identifier; + $helper->id = $address->id; + $helper->languages = $this->_languages; + $helper->default_form_language = $this->default_form_language; + $helper->allow_employee_form_lang = $this->allow_employee_form_lang; + $helper->fields_value = $this->getFieldsValue($address); + $helper->toolbar_btn = $this->toolbar_btn; + $helper->tpl = 'manufacturers/form_addresses.tpl'; + $this->content .= $helper->generateForm($this->fields_form); + } + + public function initView() + { + if (!($manufacturer = $this->loadObject())) + return; + + $addresses = $manufacturer->getAddresses($this->context->language->id); + + $products = $manufacturer->getProductsLite($this->context->language->id); + $total_product = count($products); + for ($i = 0; $i < $total_product; $i++) + { + $products[$i] = new Product($products[$i]['id_product'], false, $this->context->language->id); + /* Build attributes combinaisons */ + $combinaisons = $products[$i]->getAttributeCombinaisons($this->context->language->id); + foreach ($combinaisons as $k => $combinaison) + { + $comb_array[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference']; + $comb_array[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13']; + $comb_array[$combinaison['id_product_attribute']]['upc'] = $combinaison['upc']; + $comb_array[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity']; + $comb_array[$combinaison['id_product_attribute']]['attributes'][] = array( + $combinaison['group_name'], + $combinaison['attribute_name'], + $combinaison['id_attribute'] + ); + } + + if (isset($comb_array)) + { + foreach ($comb_array as $key => $product_attribute) + { + $list = ''; + foreach ($product_attribute['attributes'] as $attribute) + $list .= $attribute[0].' - '.$attribute[1].', '; + $comb_array[$key]['attributes'] = rtrim($list, ', '); + } + isset($comb_array) ? $products[$i]->combinaison = $comb_array : ''; + unset($comb_array); + } + } + + $this->context->smarty->assign(array( + 'manufacturer' => $manufacturer, + 'addresses' => $addresses, + 'products' => $products + )); + } + + /** + * AdminController::init() override + * @see AdminController::init() + */ + public function init() + { + parent::init(); + + if (Tools::isSubmit('editaddresses')) + $this->display = 'editaddresses'; + else if (Tools::isSubmit('addaddress')) + $this->display = 'addaddress'; + else if (Tools::isSubmit('submitAddaddress')) + $this->action = 'save'; + else if (Tools::isSubmit('deleteaddress')) + $this->action = 'delete'; + else if (is_array($this->bulk_actions)) + { + foreach ($this->bulk_actions as $bulk_action => $params) + { + if (Tools::isSubmit('submitBulk'.$bulk_action.$this->table)) + { + $this->action = 'bulk'.$bulk_action; + $this->boxes = Tools::getValue($this->table.'Box'); + break; + } + } + if ($this->ajax && method_exists($this, 'ajaxPreprocess')) + $this->ajaxPreProcess(); + } + } + + public function initContent() + { + if ($this->display == 'edit' || $this->display == 'add') + { + if (!($this->object = $this->loadObject(true))) + return; + $this->content .= $this->initForm(); + } + else if ($this->display == 'editaddresses' || $this->display == 'addaddress') + $this->content .= $this->initFormAddress(); + else if ($this->display == 'view') + $this->content .= $this->initView(); + else + { + $this->content .= $this->initList(); + $this->content .= $this->initOptions(); + } + + $this->context->smarty->assign(array( + 'table' => $this->table, + 'current' => self::$currentIndex, + 'token' => $this->token, + 'content' => $this->content + )); + } + + public function postProcess() + { + if (Tools::getValue('submitAddaddress') || Tools::isSubmit('deleteaddress')) + { + $this->table = 'address'; + $this->className = 'Address'; + $this->identifier = 'id_address'; + $this->deleted = true; + } + parent::postProcess(); + } + + public function afterImageUpload() + { + /* Generate image with differents size */ + if (($id_manufacturer = (int)Tools::getValue('id_manufacturer')) && + isset($_FILES) && + count($_FILES) && + file_exists(_PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg')) + { + $images_types = ImageType::getImagesTypes('manufacturers'); + foreach ($images_types as $k => $image_type) + imageResize( + _PS_MANU_IMG_DIR_.$id_manufacturer.'.jpg', + _PS_MANU_IMG_DIR_.$id_manufacturer.'-'.stripslashes($image_type['name']).'.jpg', + (int)$image_type['width'], + (int)$image_type['height'] + ); + } + } +} + +