From d638ff44960a0f94ed853af9fe7d95bbdf9134e1 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Wed, 2 Nov 2011 16:02:53 +0000 Subject: [PATCH] [*] BO : #PSFV-94 - added AdminSuppliersController git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9806 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminSuppliers.php | 226 ------------------ admin-dev/themes/template/addresses/form.tpl | 9 - admin-dev/themes/template/attributes/form.tpl | 19 +- .../themes/template/helper/form/form.tpl | 19 +- .../template/helper/list/list_header.tpl | 19 +- .../themes/template/manufacturers/content.tpl | 39 +++ .../template/manufacturers/list_header.tpl | 202 ---------------- .../themes/template/manufacturers/view.tpl | 3 + admin-dev/themes/template/suppliers/view.tpl | 65 +++++ admin-dev/themes/template/toolbar.tpl | 40 ++++ classes/AdminController.php | 23 +- classes/HelperForm.php | 4 +- classes/HelperList.php | 3 + .../admin/AdminManufacturersController.php | 20 +- .../admin/AdminSuppliersController.php | 215 +++++++++++++++++ 15 files changed, 416 insertions(+), 490 deletions(-) delete mode 100644 admin-dev/tabs/AdminSuppliers.php create mode 100644 admin-dev/themes/template/manufacturers/content.tpl delete mode 100644 admin-dev/themes/template/manufacturers/list_header.tpl create mode 100644 admin-dev/themes/template/suppliers/view.tpl create mode 100644 admin-dev/themes/template/toolbar.tpl create mode 100644 controllers/admin/AdminSuppliersController.php diff --git a/admin-dev/tabs/AdminSuppliers.php b/admin-dev/tabs/AdminSuppliers.php deleted file mode 100644 index 8801a5032..000000000 --- a/admin-dev/tabs/AdminSuppliers.php +++ /dev/null @@ -1,226 +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 AdminSuppliers extends AdminTab -{ - public function __construct() - { - $this->table = 'supplier'; - $this->className = 'Supplier'; - $this->view = true; - $this->edit = true; - $this->delete = true; - $this->_select = 'COUNT(p.`id_product`) AS products'; - $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_supplier` = p.`id_supplier`)'; - - $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su'); - - $this->fieldsDisplay = array( - 'id_supplier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'name' => array('title' => $this->l('Name'), 'width' => 120), - 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false), - 'products' => array('title' => $this->l('Number of products'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true), - 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) - ); - - parent::__construct(); - } - - public function viewsupplier() - { - if (!($supplier = $this->loadObject())) - return; - echo '

'.$supplier->name.'

'; - - $products = $supplier->getProductsLite($this->context->language->id); - 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 ' - - - - '.(!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 ' -

'.$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'].'
'; - echo ''; - } - } - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($supplier = $this->loadObject(true))) - return; - - $langtags = 'description¤smeta_title¤smeta_keywords¤smeta_description'; - echo ' -
- '.($supplier->id ? '' : '').' -
'.$this->l('Suppliers').' - -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
- -
'; - foreach ($this->_languages as $language) - echo ' -
- - '.$this->l('Invalid characters:').' <>;=#{}  -

'.$this->l('Will appear in supplier list').'

-
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'description'); - echo '
-
- -
'; - echo $this->displayImage($supplier->id, _PS_SUPP_IMG_DIR_.$supplier->id.'.jpg', 350, NULL, NULL, true); - echo '
-

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

-
- -
'; - foreach ($this->_languages as $language) - echo ' -
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_title'); - echo '
-
- -
'; - foreach ($this->_languages as $language) - echo '
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_description'); - echo '
-
- -
'; - foreach ($this->_languages as $language) - echo ' -
- - '.$this->l('Forbidden characters:').' <>;=#{}  -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'smeta_keywords'); - echo '
-
- -
- getFieldValue($supplier, 'active') ? 'checked="checked" ' : '').'/> - - getFieldValue($supplier, 'active') ? 'checked="checked" ' : '').'/> - -
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop('group_shop'); - echo '
'; - } - echo ' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } - - public function afterImageUpload() - { - /* Generate image with differents size */ - if (($id_supplier = (int)(Tools::getValue('id_supplier'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_SUPP_IMG_DIR_.$id_supplier.'.jpg')) - { - $imagesTypes = ImageType::getImagesTypes('suppliers'); - foreach ($imagesTypes AS $k => $imageType) - { - $file = _PS_SUPP_IMG_DIR_.$id_supplier.'.jpg'; - imageResize($file, _PS_SUPP_IMG_DIR_.$id_supplier.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); - } - } - } -} - - diff --git a/admin-dev/themes/template/addresses/form.tpl b/admin-dev/themes/template/addresses/form.tpl index 54283a25b..531694629 100644 --- a/admin-dev/themes/template/addresses/form.tpl +++ b/admin-dev/themes/template/addresses/form.tpl @@ -27,15 +27,6 @@ {extends file="../helper/form/form.tpl"} {block name="label"} -{* {if $input.type == 'text_customer'} - {if isset($customer)} - - {else} - - {/if} - {else if isset($input.label)} - - {/if} *} {/block} {block name="start_field_block"} diff --git a/admin-dev/themes/template/attributes/form.tpl b/admin-dev/themes/template/attributes/form.tpl index dcf0b1c5c..fc56b9135 100644 --- a/admin-dev/themes/template/attributes/form.tpl +++ b/admin-dev/themes/template/attributes/form.tpl @@ -71,20 +71,11 @@ {/if} -
- -
{* todo : what to display as title for each items (table_lang.name ? *} -

{$current_obj_name|default:' '}

-
-
+ +{if isset($toolbar) && $toolbar} + {include file="toolbar.tpl"} +{/if} + {if isset($fields.title)}

{$fields.title}

{/if}
{if $form_id} diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index f2aae2ae2..ca9c98109 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -62,20 +62,11 @@ {/if} -
- -
{* todo : what to display as title for each items (table_lang.name ? *} -

{$current_obj_name|default:' '}

-
-
+ +{if isset($toolbar) && $toolbar} + {include file="toolbar.tpl"} +{/if} + {if isset($fields.title)}

{$fields.title}

{/if} {if $form_id} diff --git a/admin-dev/themes/template/helper/list/list_header.tpl b/admin-dev/themes/template/helper/list/list_header.tpl index acdc5750f..d82e4a140 100644 --- a/admin-dev/themes/template/helper/list/list_header.tpl +++ b/admin-dev/themes/template/helper/list/list_header.tpl @@ -55,23 +55,12 @@ }); }); + + {if isset($toolbar) && $toolbar} + {include file="toolbar.tpl"} + {/if} -
- -
{* todo : what to display as title for each items (table_lang.name ? *} -

{$current_obj_name|default:' '}

-
-
  - {/if}{* End if simple_header *} diff --git a/admin-dev/themes/template/manufacturers/content.tpl b/admin-dev/themes/template/manufacturers/content.tpl new file mode 100644 index 000000000..2b4606810 --- /dev/null +++ b/admin-dev/themes/template/manufacturers/content.tpl @@ -0,0 +1,39 @@ +{* +* 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$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if isset($list_manufacturers)} + {include file="toolbar.tpl"} +

{l s='List of manufacturers:'}

+ {$list_manufacturers} +{/if} + +{if isset($list_addresses)} + {include file="toolbar.tpl"} +

{l s='Manufacturers addresses:'}

+ {$list_addresses} +{/if} + +{$content} diff --git a/admin-dev/themes/template/manufacturers/list_header.tpl b/admin-dev/themes/template/manufacturers/list_header.tpl deleted file mode 100644 index e4ad81c1c..000000000 --- a/admin-dev/themes/template/manufacturers/list_header.tpl +++ /dev/null @@ -1,202 +0,0 @@ -{* -* 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 index d14d5a5d3..37317c62e 100644 --- a/admin-dev/themes/template/manufacturers/view.tpl +++ b/admin-dev/themes/template/manufacturers/view.tpl @@ -72,6 +72,7 @@ {if !empty($product->reference)}{/if} {if !empty($product->ean13)}{/if} {if !empty($product->upc)}{/if} + {if $stock_management}{/if}
- {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} -
----
{l s='Ref:'} {$product->reference}{l s='EAN13:'} {$product->ean13}{l s='UPC:'} {$product->upc}{l s='Qty:'} {$product->quantity}
{else} @@ -86,6 +87,7 @@ {l s='Reference'} {l s='EAN13'} {l s='UPC'} + {if $stock_management}{l s='Quantity'}{/if} {foreach $product->combinaison AS $id_product_attribute => $product_attribute} @@ -93,6 +95,7 @@ {$product_attribute.reference} {$product_attribute.ean13} {$product_attribute.upc} + {if $stock_management}{$product_attribute.quantity}{/if} {/foreach} diff --git a/admin-dev/themes/template/suppliers/view.tpl b/admin-dev/themes/template/suppliers/view.tpl new file mode 100644 index 000000000..0d4c5a5fe --- /dev/null +++ b/admin-dev/themes/template/suppliers/view.tpl @@ -0,0 +1,65 @@ +{* +* 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$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +

{$supplier->name}

+ +

{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} + {if $stock_management}{/if} + +
{$product->name}{l s='Ref:'} {$product->reference}{l s='EAN13:'} {$product->ean13}{l s='UPC:'} {$product->upc}{l s='Qty:'} {$product->quantity}
+ {else} +

{$product->name}

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

+ {l s='Back to manufacturer list'}
diff --git a/admin-dev/themes/template/toolbar.tpl b/admin-dev/themes/template/toolbar.tpl new file mode 100644 index 000000000..29c1583e3 --- /dev/null +++ b/admin-dev/themes/template/toolbar.tpl @@ -0,0 +1,40 @@ +{* +* 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$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
+ +
{* todo : what to display as title for each items (table_lang.name ? *} +

{$current_obj_name|default:' '}

+
+
\ No newline at end of file diff --git a/classes/AdminController.php b/classes/AdminController.php index ab6d2e6ab..7c8be6dac 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -962,8 +962,8 @@ class AdminControllerCore extends Controller if (trim($tab['module']) != '') $img = _MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.png'; - - // retrocompatibility + + // retrocompatibility if(!file_exists($img)) $img = str_replace('png', 'gif', $img); @@ -1091,7 +1091,13 @@ class AdminControllerCore extends Controller return; $this->content .= $this->initForm(); } - elseif ($this->display != 'view' && !$this->ajax) + elseif ($this->display == 'view') + { + if (!($this->object = $this->loadObject(true))) + return; + $this->content .= $this->initView(); + } + elseif (!$this->ajax) { $this->content .= $this->initList(); $this->content .= $this->initOptions(); @@ -1169,10 +1175,17 @@ class AdminControllerCore extends Controller return $helper->generateList($this->_list, $this->fieldsDisplay); } + /** + * Override to init display of the view page + */ + public function initView() + { + } + /** * this function set various display option for helper list - * - * @param Helper $helper + * + * @param Helper $helper * @return void */ public function setHelperListDisplay(Helper $helper) diff --git a/classes/HelperForm.php b/classes/HelperForm.php index 63337fd67..456009724 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -31,6 +31,7 @@ class HelperFormCore extends Helper public $id; public $first_call = true; + public $toolbar = true; /** * @var array of forms fields @@ -98,7 +99,8 @@ class HelperFormCore extends Helper '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"]) + 'ad' => dirname($_SERVER["PHP_SELF"]), + 'toolbar' => $this->toolbar )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->tpl); diff --git a/classes/HelperList.php b/classes/HelperList.php index 18e34541e..83f6c0b72 100644 --- a/classes/HelperList.php +++ b/classes/HelperList.php @@ -62,6 +62,8 @@ class HelperListCore extends Helper protected $is_dnd_identifier = false; + public $toolbar = true; + /* Customize list display * * align : determine value alignment @@ -538,6 +540,7 @@ class HelperListCore extends Helper 'table_dnd' => isset($table_dnd) ? $table_dnd : null, 'name' => isset($name) ? $name : null, 'name_id' => isset($name_id) ? $name_id : null, + 'toolbar' => $this->toolbar )); return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/'.$this->header_tpl); diff --git a/controllers/admin/AdminManufacturersController.php b/controllers/admin/AdminManufacturersController.php index 288d2c0e9..3c56912f4 100644 --- a/controllers/admin/AdminManufacturersController.php +++ b/controllers/admin/AdminManufacturersController.php @@ -85,11 +85,17 @@ class AdminManufacturersControllerCore extends AdminController parent::__construct(); } + public function setHelperListDisplay(Helper $helper) + { + $helper->toolbar = false; + parent::setHelperListDisplay($helper); + } + public function initList() { + $this->addRowAction('view'); $this->addRowAction('edit'); $this->addRowAction('delete'); - $this->addRowAction('view'); $this->_select = ' COUNT(`id_product`) AS `products`, ( @@ -104,7 +110,7 @@ class AdminManufacturersControllerCore extends AdminController $this->context->smarty->assign('title_list', $this->l('List of manufacturers:')); $this->initToolbar(); - $this->content .= parent::initList(); + $list_manufacturers = parent::initList(); // reset actions and query vars $this->actions = array(); @@ -185,7 +191,12 @@ class AdminManufacturersControllerCore extends AdminController $this->postProcess(); $this->initToolbar(); - $this->content .= parent::initList(); + $list_addresses = parent::initList(); + + $this->context->smarty->assign(array( + 'list_manufacturers' => $list_manufacturers, + 'list_addresses' => $list_addresses + )); } /** @@ -563,7 +574,8 @@ class AdminManufacturersControllerCore extends AdminController $this->context->smarty->assign(array( 'manufacturer' => $manufacturer, 'addresses' => $addresses, - 'products' => $products + 'products' => $products, + 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), )); } diff --git a/controllers/admin/AdminSuppliersController.php b/controllers/admin/AdminSuppliersController.php new file mode 100644 index 000000000..84818a0b1 --- /dev/null +++ b/controllers/admin/AdminSuppliersController.php @@ -0,0 +1,215 @@ + +* @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 AdminSuppliersControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'supplier'; + $this->className = 'Supplier'; + + $this->addRowAction('view'); + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + $this->_select = 'COUNT(p.`id_product`) AS products'; + $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product` p ON (a.`id_supplier` = p.`id_supplier`)'; + $this->_group = 'GROUP BY a.`id_supplier`'; + + $this->fieldImageSettings = array('name' => 'logo', 'dir' => 'su'); + + $this->fieldsDisplay = array( + 'id_supplier' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), + 'name' => array('title' => $this->l('Name'), 'width' => 120), + 'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 'su', 'orderby' => false, 'search' => false), + 'products' => array('title' => $this->l('Number of products'), 'align' => 'right', 'filter_type' => 'int', 'tmpTableFilter' => true), + 'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) + ); + + parent::__construct(); + } + + public function initForm() + { + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Suppliers'), + 'image' => '../img/admin/suppliers.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'size' => 40, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}', + ), + array( + 'type' => 'text', + 'label' => $this->l('Description:'), + 'name' => 'description', + 'size' => 33, + 'lang' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}', + 'p' => $this->l('Will appear in supplier list') + ), + array( + 'type' => 'file', + 'label' => $this->l('Logo:'), + 'name' => 'logo', + 'display_image' => true, + 'p' => $this->l('Upload supplier logo from your computer') + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta title:'), + 'name' => 'smeta_title', + 'lang' => true, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta description:'), + 'name' => 'meta_description', + 'lang' => true, + 'hint' => $this->l('Forbidden characters:').' <>;=#{}' + ), + array( + 'type' => 'text', + 'label' => $this->l('Meta keywords:'), + 'name' => 'meta_keywords', + 'lang' => true, + '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') + ) + ) + ) + ), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ) + ); + + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'group_shop', + 'label' => $this->l('Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + // Set logo image + $image = cacheImage(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg', $this->table.'_'.(int)$this->object->id.'.'.$this->imageType, 350, $this->imageType, true); + $this->fields_value = array( + 'image' => $image ? $image : false, + 'size' => $image ? filesize(_PS_SUPP_IMG_DIR_.'/'.$this->object->id.'.jpg') / 1000 : false + ); + + return parent::initForm(); + } + + public function initView() + { + $products = $this->object->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( + 'supplier' => $this->object, + 'products' => $products, + 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), + )); + } + + public function afterImageUpload() + { + /* Generate image with differents size */ + if (($id_supplier = (int)(Tools::getValue('id_supplier'))) AND isset($_FILES) AND count($_FILES) AND file_exists(_PS_SUPP_IMG_DIR_.$id_supplier.'.jpg')) + { + $imagesTypes = ImageType::getImagesTypes('suppliers'); + foreach ($imagesTypes AS $k => $imageType) + { + $file = _PS_SUPP_IMG_DIR_.$id_supplier.'.jpg'; + imageResize($file, _PS_SUPP_IMG_DIR_.$id_supplier.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); + } + } + } +} + +