diff --git a/admin-dev/tabs/AdminAttributes.php b/admin-dev/tabs/AdminAttributes.php deleted file mode 100644 index 97edea1db..000000000 --- a/admin-dev/tabs/AdminAttributes.php +++ /dev/null @@ -1,203 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7465 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php'); - -class AdminAttributes extends AdminTab -{ - public function __construct() - { - $this->table = 'attribute'; - $this->className = 'Attribute'; - $this->lang = true; - $this->edit = true; - $this->delete = true; - $this->fieldImageSettings = array('name' => 'texture', 'dir' => 'co'); - - parent::__construct(); - } - - /** - * Display form - */ - public function displayForm($token = NULL) - { - if (!Combination::isFeatureActive()) - { - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); - return; - } - - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - $color = ($obj->color ? $obj->color : 0); - $attributes_groups = AttributeGroup::getAttributesGroups($this->_defaultFormLanguage); - $strAttributesGroups = ''; - echo ' - -
- '.($obj->id ? '' : '').' -
'.$this->l('Attribute').' - -
'; - foreach ($this->_languages as $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
'; - echo ' - '; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true); - echo ' -
-
- -
- * -
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop('group_shop'); - echo '
'; - } - echo ' - -
- -
- * -

'.$this->l('HTML colors only (e.g.,').' "lightblue", "#CC6600")

-
- -
- -

'.$this->l('Upload color texture from your computer').'
'.$this->l('This will override the HTML color!').'

-
- -
-

'.(file_exists(_PS_IMG_DIR_.$this->fieldImageSettings['dir'].'/'.$obj->id.'.jpg') - ? ' '.$this->l('Delete').'' - : $this->l('None') - ).'

-
-
- '.Module::hookExec('attributeForm', array('id_attribute' => $obj->id)).' -
- -
-
* '.$this->l('Required field').'
-
-
- '; - } - - /** - * Manage page processing - */ - public function postProcess($token = NULL) - { - if (!Combination::isFeatureActive()) - return; - - - Module::hookExec('postProcessAttribute', - array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessFeatureValue to stop saving process - - if (Tools::getValue('submitDel'.$this->table)) - { - if ($this->tabAccess['delete'] === '1') - { - if (isset($_POST[$this->table.$_POST['groupid'].'Box'])) - { - $object = new $this->className(); - if ($object->deleteSelection($_POST[$this->table.$_POST['groupid'].'Box'])) - Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.($token ? $token : $this->token)); - $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); - } - else - $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); - } - elseif (Tools::isSubmit('submitAdd'.$this->table)) - { - $id_attribute = (int)Tools::getValue('id_attribute'); - // Adding last position to the attribute if not exist - if ($id_attribute <= 0) - { - $sql = 'SELECT `position`+1 - FROM `'._DB_PREFIX_.'attribute` - WHERE id_attribute_group = '.(int)Tools::getValue('id_attribute_group').' - ORDER BY position DESC'; - // set the position of the new attribute in $_POST for postProcess() method - $_POST['position'] = DB::getInstance()->getValue($sql); - } - // clean \n\r characters - foreach ($_POST as $key => $value) - if (stripos($key, 'name_') !== false) - $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); - parent::postProcess(); - } - else - parent::postProcess(); - } - - - /** - * Modifying initial getList method to display position feature (drag and drop) - */ - public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) - { - if ($order_by && $this->context->cookie->__get($this->table.'Orderby')) - $order_by = $this->context->cookie->__get($this->table.'Orderby'); - else - $order_by = 'position'; - - parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); - } -} - - diff --git a/admin-dev/tabs/AdminAttributesGroups.php b/admin-dev/tabs/AdminAttributesGroups.php deleted file mode 100644 index 2e7eecbbb..000000000 --- a/admin-dev/tabs/AdminAttributesGroups.php +++ /dev/null @@ -1,360 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7465 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -include_once(_PS_ADMIN_DIR_.'/../classes/AdminTab.php'); -include_once(_PS_ADMIN_DIR_.'/tabs/AdminAttributes.php'); - -class AdminAttributesGroups extends AdminTab -{ - /** @var object AdminAttributes() instance */ - private $adminAttributes; - - public function __construct() - { - $this->adminAttributes = new AdminAttributes(); - $this->table = 'attribute_group'; - $this->className = 'AttributeGroup'; - $this->lang = true; - $this->edit = true; - $this->delete = true; - - $this->fieldsDisplay = array( - 'name' => array('title' => $this->l('Name'), 'width' => 140, 'filter_key' => 'b!name'), - 'attribute' => array('title' => $this->l('Attributes'), 'width' => 240, 'orderby' => false, 'search' => false), - 'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position')); - parent::__construct(); - } - - public function display() - { - if (Combination::isFeatureActive()) - { - if ((isset($_POST['submitAddattribute']) AND sizeof($this->adminAttributes->_errors)) - OR isset($_GET['updateattribute']) OR isset($_GET['addattribute'])) - { - $this->adminAttributes->displayForm($this->token); - echo '

'.$this->l('Back to list').'
'; - } - else - parent::display(); - } - else - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); - } - - public function postProcess() - { - if (!Combination::isFeatureActive()) - return; - - $this->adminAttributes->tabAccess = Profile::getProfileAccess(Context::getContext()->employee->id_profile, $this->id); - if (Tools::isSubmit('submitAddattribute') || Tools::isSubmit('submitDelattribute') || (Tools::getValue('position') && Tools::getValue('id_attribute'))) - $this->adminAttributes->postProcess($this->token); - - Module::hookExec('postProcessAttributeGroup', - array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessAttributeGroup to stop saving process - - if(Tools::getValue('submitDel'.$this->table)) - { - if ($this->tabAccess['delete'] === '1') - { - if (isset($_POST[$this->table.'Box'])) - { - $object = new $this->className(); - if ($object->deleteSelection($_POST[$this->table.'Box'])) - Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.$this->token); - $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); - } - else - $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); - } - else - $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); - // clean position after delete - AttributeGroup::cleanPositions(); - } - else if (Tools::isSubmit('submitAdd'.$this->table)) - { - $id_attribute_group = (int)Tools::getValue('id_attribute_group'); - // Adding last position to the attribute if not exist - if ($id_attribute_group <= 0) - { - $sql = 'SELECT `position`+1 - FROM `'._DB_PREFIX_.'attribute_group` - ORDER BY position DESC'; - // set the position of the new group attribute in $_POST for postProcess() method - $_POST['position'] = DB::getInstance()->getValue($sql); - } - // clean \n\r characters - foreach ($_POST as $key => $value) - if (preg_match('/^name_/Ui', $key)) - $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); - parent::postProcess(); - } - else - parent::postProcess(); - } - - public function displayErrors() - { - $this->adminAttributes->displayErrors(); - parent::displayErrors(); - } - - /* Report to AdminTab::displayList() for more details */ - public function displayList() - { - echo '
'.$this->l('Add attributes group').'
- '.$this->l('Add attribute').'

- '.$this->l('Click on the group name to view its attributes. Click again to hide them.').'

'; - if ($this->_list === false) - Tools::displayError('No elements found'); - - $this->displayListHeader($this->token); - echo ''; - - if (!sizeof($this->_list)) - echo ''.$this->l('No elements found').''; - - //$this->displayListContent($this->token); - - - echo ' - - - - '; - - $irow = 0; - if ($this->_list AND isset($this->fieldsDisplay['position'])) - { - $positions = array_map(create_function('$elem', 'return (int)$elem[\'position\'];'), $this->_list); - sort($positions); - } - foreach ($this->_list AS $tr) - { - $id = (int)$tr['id_'.$this->table]; - echo ' - - - '.$tr['name'].' - '; - $this->displayListAttributes($id, $irow, $tr); - echo ' - '; - - echo ' - '; - - if ($this->_orderBy == 'position' AND $this->_orderWay != 'DESC') - { - echo ' - '.$this->l('Down').''; - - echo ' - '.$this->l('Up').''; - } - else - echo (int)($tr['position'] + 1); - - echo ' - - - - '.$this->l('Edit').'  - - '.$this->l('Delete').' - - '; - } - - $this->displayListFooter($this->token); - } - - public function displayForm($isMainTab = true) - { - if (!Combination::isFeatureActive()) - { - $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); - return; - } - - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - echo ' -
- '.($obj->id ? '' : '').' -
'.$this->l('Attributes group').' - -
'; - foreach ($this->_languages as $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -
- '; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true); - echo ' -
-
- -
'; - foreach ($this->_languages as $language) - echo ' -
- * - '.$this->l('Invalid characters:').' <>;=#{}  -

'.$this->l('Term or phrase displayed to the customer').'

-
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'public_name', false, true); - echo ' -
-
- -
- -

'.$this->l('Choose the type of the attribute group').'

-
'; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop('group_shop'); - echo '
'; - } - echo ' - '.Module::hookExec('attributeGroupForm', array('id_attribute_group' => $obj->id)).' -
- -
-
* '.$this->l('Required field').'
-
-
'; - } - - /** - * displayListAttributes - * - * Display a list of attributes from a group - * @param integer $id - * @param integer $irow - * @param array $tr - * @return void - */ - public function displayListAttributes($id, $irow, $tr) - { - echo ' - '; - } - - /** - * Modifying initial getList method to display position feature (drag and drop) - */ - public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) - { - if ($order_by && $this->context->cookie->__get($this->table.'Orderby')) - $order_by = $this->context->cookie->__get($this->table.'Orderby'); - else - $order_by = 'position'; - - parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); - } -} - - diff --git a/admin-dev/themes/default/admin.css b/admin-dev/themes/default/admin.css index 3a9f2f07e..fefe712f7 100644 --- a/admin-dev/themes/default/admin.css +++ b/admin-dev/themes/default/admin.css @@ -116,7 +116,7 @@ a.module_toggle_all{color: #268CCD;} .toolbarBox .process-icon-preview { background-image: url(process-icon-preview.png);} .toolbarBox .process-icon-stats { background-image: url(process-icon-stats.png);} .toolbarBox .process-icon-cancel { background-image: url(process-icon-cancel.png);} -.toolbarBox .process-icon-new{ background-image: url(process-icon-new.png);} +.toolbarBox .process-icon-new, .toolbarBox .process-icon-newAttributes{ background-image: url(process-icon-new.png);} .toolbarBox .process-icon-save { background-image: url(process-icon-save.png);} .toolbarBox .process-icon-save-and-stay { background-image: url(process-icon-save-and-stay.png);} diff --git a/admin-dev/themes/template/attributes/form.tpl b/admin-dev/themes/template/attributes/form.tpl new file mode 100644 index 000000000..dcf0b1c5c --- /dev/null +++ b/admin-dev/themes/template/attributes/form.tpl @@ -0,0 +1,376 @@ +{* +* 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: 8971 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if $firstCall} + + +{/if} +
+ +
{* todo : what to display as title for each items (table_lang.name ? *} +

{$current_obj_name|default:' '}

+
+
+{if isset($fields.title)}

{$fields.title}

{/if} +
+ {if $form_id} + + {/if} +
+ {foreach $fields as $key => $field} + {if $key == 'legend'} + + {if isset($field.image)}{$field.title}{/if} + {$field.title} + + {elseif $key == 'input'} + {foreach $field as $input} + {if $input.name == 'id_state'} +
+ {/if} + {if $input.type == 'color'} +
+ {/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' && $input.name == 'texture'} +

+ {if $imageTextureExists} + + {l s='Delete'} + {else} + {l s='None'} + {/if} +

+ {elseif $input.type == 'text'} + {if isset($input.lang) && isset($input.attributeLang)} + {foreach $languages as $language} +
+ + {if isset($input.hint)}{$input.hint} {/if} +
+ {/foreach} + {if count($languages) > 1} +
+ +
+
+ {l s='Choose language:'}

+ {foreach $languages as $language} + {$language.name} + {/foreach} +
+ {/if} + {else} + + {if isset($input.suffix)}{$input.suffix}{/if} + {if isset($input.hint)}{$input.hint} {/if} + {/if} + {elseif $input.type == 'select'} + {if isset($input.options.query) && !$input.options.query && isset($input.empty_message)} + {$input.empty_message} + {$input.required = false} + {$input.p = null} + {else} + + {if isset($input.hint)}{$input.hint} {/if} + {/if} + {elseif $input.type == 'radio'} + {foreach $input.values as $value} + + + {if isset($input.br) && $input.br}
{/if} + {/foreach} + {elseif $input.type == 'textarea'} + {if isset($input.lang) && isset($input.attributeLang)} + {foreach $languages as $language} +
+ +
+ {/foreach} + {if count($languages) > 1} +
+ +
+
+ {l s='Choose language:'}

+ {foreach $languages as $language} + {$language.name} + {/foreach} +
+ {/if} + {else} + + {/if} + {elseif $input.type == 'checkbox'} + {foreach $input.values.query as $value} + {assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]} + +
+ {/foreach} + {elseif $input.type == 'file'} + {if isset($input.display_image) && $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'} + {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'} + {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} + +
+ {$asso_shop} +
+ {elseif $input.type == 'color'} + + + {elseif $input.type == 'date'} + + + {/if} + {if isset($input.required) && $input.required} *{/if} + {if isset($input.p)} +

+ {if is_array($input.p)} + {foreach $input.p as $p} + {if is_array($p)} + {$p.text}
+ {else} + {$p}
+ {/if} + {/foreach} + {else} + {$input.p} + {/if} +

+ {/if} + {if isset($languages)}
{/if} + {block name="end_field_block"}
{/block} + {/if} + {if $input.name == 'id_state'} +
+ {/if} + {if $input.type == 'text' && $input.name == 'texture'} +
+ {/if} + {/foreach} + {elseif $key == 'submit'} +
+ +
+ {/if} + {/foreach} + {if $required_fields} +
* {l s ='Required field'}
+ {/if} + {if isset($fields.tinymce) && $fields.tinymce} + + + + {/if} +
+
+ +

+{if $firstCall && !$no_back} + {if $back} + {l s='Back'} + {else} + {l s='Back to list'} + {/if} +
+{/if} diff --git a/admin-dev/themes/template/attributes/list_content.tpl b/admin-dev/themes/template/attributes/list_content.tpl new file mode 100644 index 000000000..1e5364a21 --- /dev/null +++ b/admin-dev/themes/template/attributes/list_content.tpl @@ -0,0 +1,116 @@ +{* +* 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: 9608 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{foreach $list AS $index => $tr} + + + {if $bulk_actions} + {assign var=bulkActionPossible value=true} + {foreach $list_skip_actions as $key => $value} + {if in_array($tr.$identifier, $value) == true} + {assign var=bulkActionPossible value=false} + {/if} + {/foreach} + {if $bulkActionPossible == true} + + {/if} + {/if} + + {foreach $fields_display AS $key => $params} + {if isset($params.prefix)}{$params.prefix}{/if} + {else} + > + {/if} + {if isset($params.active)} + {$tr.$key} + {elseif isset($params.activeVisu)} + {if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if} + {elseif isset($params.position)} + {if $order_by == 'position' && $order_way != 'DESC'} + + {l s='Down'} + + + + {l s='Up'} + + {else} + {$tr.$key.position + 1} + {/if} + {elseif isset($params.image)} + {$tr.$key} + {elseif (isset($params.icon))} + {$tr[$key]} + {elseif isset($params.price)} + {$tr.$key} + {elseif isset($params.float)} + {$tr.$key} + {elseif isset($params.type) && $params.type == 'date'} + {$tr.$key} + {elseif isset($params.type) && $params.type == 'datetime'} + {$tr.$key} + {elseif isset($params.callback)} + {$tr.$key} + {elseif isset($tr.$key) && $key == 'color'} +
+ {elseif isset($tr.$key)} + {$tr.$key|escape:'htmlall':'UTF-8'} + {else} + -- + {/if} + {if isset($params.suffix)}{$params.suffix}{/if} + + {/foreach} + + {if $shop_link_type} + {if isset($tr.shop_short_name)}{$tr.shop_short_name}{else}{$tr.shop_name}{/if} + {/if} + {if $has_actions} + + {foreach $actions AS $action} + {if isset($tr.$action)} + {$tr.$action} + {/if} + {/foreach} + + {/if} + +{/foreach} + \ No newline at end of file diff --git a/classes/Attribute.php b/classes/Attribute.php index deaa9587d..39cd43c06 100644 --- a/classes/Attribute.php +++ b/classes/Attribute.php @@ -51,7 +51,7 @@ class AttributeCore extends ObjectModel 'objectNodeName' => 'product_option_value', 'fields' => array( 'id_attribute_group' => array('xlink_resource'=> 'product_options'), - ), + ) ); public function __construct($id = null, $id_lang = null, $id_shop = null) @@ -145,13 +145,17 @@ class AttributeCore extends ObjectModel if (!Combination::isFeatureActive()) return array(); return Db::getInstance()->executeS(' - SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group` - FROM `'._DB_PREFIX_.'attribute_group` ag - LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute_group` = ag.`id_attribute_group` - LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.') - '.($not_null ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').' - ORDER BY agl.`name` ASC, a.`position` ASC'); + SELECT ag.*, agl.*, a.`id_attribute`, al.`name`, agl.`name` AS `attribute_group` + FROM `'._DB_PREFIX_.'attribute_group` ag + LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl + ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.') + LEFT JOIN `'._DB_PREFIX_.'attribute` a + ON a.`id_attribute_group` = ag.`id_attribute_group` + LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al + ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.') + '.($not_null ? 'WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL' : '').' + ORDER BY agl.`name` ASC, a.`position` ASC + '); } /** @@ -188,9 +192,10 @@ class AttributeCore extends ObjectModel Tools::displayAsDeprecated(); $row = Db::getInstance()->getRow(' - SELECT SUM(quantity) as quantity - FROM `'._DB_PREFIX_.'product_attribute` - WHERE `id_product` = '.(int)$id_product); + SELECT SUM(quantity) as quantity + FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product` = '.(int)$id_product + ); if ($row['quantity'] !== null) return (int)$row['quantity']; @@ -228,9 +233,13 @@ class AttributeCore extends ObjectModel public function isColorAttribute() { if (!Db::getInstance()->getRow(' - SELECT `group_type` FROM `'._DB_PREFIX_.'attribute_group` WHERE `id_attribute_group` = ( - SELECT `id_attribute_group` FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute` = '.(int)$this->id.') - AND group_type = \'color\'')) + SELECT `group_type` + FROM `'._DB_PREFIX_.'attribute_group` + WHERE `id_attribute_group` = ( + SELECT `id_attribute_group` + FROM `'._DB_PREFIX_.'attribute` + WHERE `id_attribute` = '.(int)$this->id.') + AND group_type = \'color\'')) return false; return Db::getInstance()->numRows(); } @@ -245,9 +254,10 @@ class AttributeCore extends ObjectModel public static function getAttributeMinimalQty($id_product_attribute) { $minimal_quantity = Db::getInstance()->getValue(' - SELECT `minimal_quantity` - FROM `'._DB_PREFIX_.'product_attribute` - WHERE `id_product_attribute` = '.(int)$id_product_attribute); + SELECT `minimal_quantity` + FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product_attribute` = '.(int)$id_product_attribute + ); if ($minimal_quantity > 1) return (int)$minimal_quantity; diff --git a/classes/AttributeGroup.php b/classes/AttributeGroup.php index 76e543b1f..0e7ff40f6 100644 --- a/classes/AttributeGroup.php +++ b/classes/AttributeGroup.php @@ -28,32 +28,33 @@ class AttributeGroupCore extends ObjectModel { /** @var string Name */ - public $name; - public $is_color_group; - public $position; - public $group_type; + public $name; + public $is_color_group; + public $position; + public $group_type; /** @var string Public Name */ - public $public_name; + public $public_name; - protected $fieldsRequired = array(); - protected $fieldsValidate = array('is_color_group' => 'isBool'); - protected $fieldsRequiredLang = array('name', 'public_name'); - protected $fieldsSizeLang = array('name' => 64, 'public_name' => 64); - protected $fieldsValidateLang = array('name' => 'isGenericName', 'public_name' => 'isGenericName', 'position' => 'isInt'); + protected $fieldsRequired = array(); + protected $fieldsValidate = array('is_color_group' => 'isBool'); + protected $fieldsRequiredLang = array('name', 'public_name'); + protected $fieldsSizeLang = array('name' => 64, 'public_name' => 64); + protected $fieldsValidateLang = array('name' => 'isGenericName', 'public_name' => 'isGenericName', 'position' => 'isInt'); - protected $table = 'attribute_group'; - protected $identifier = 'id_attribute_group'; + protected $table = 'attribute_group'; + protected $identifier = 'id_attribute_group'; - protected $webserviceParameters = array( + protected $webserviceParameters = array( 'objectsNodeName' => 'product_options', 'objectNodeName' => 'product_option', 'fields' => array(), 'associations' => array( - 'product_option_values' => array('resource' => 'product_option_value', - 'fields' => array( - 'id' => array(), - ), + 'product_option_values' => array( + 'resource' => 'product_option_value', + 'fields' => array( + 'id' => array() + ), ), ), ); @@ -62,9 +63,9 @@ class AttributeGroupCore extends ObjectModel { $this->validateFields(); - $fields['is_color_group'] = (int)($this->is_color_group); + $fields['is_color_group'] = (int)$this->is_color_group; $fields['group_type'] = pSQL($this->group_type); - $fields['position'] = (int)($this->position); + $fields['position'] = (int)$this->position; return $fields; } @@ -99,12 +100,20 @@ class AttributeGroupCore extends ObjectModel public static function cleanDeadCombinations() { - $attributeCombinations = Db::getInstance()->executeS('SELECT pac.`id_attribute`, pa.`id_product_attribute` FROM `'._DB_PREFIX_.'product_attribute` pa LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pa.`id_product_attribute` = pac.`id_product_attribute`)'); + $attributeCombinations = Db::getInstance()->executeS(' + SELECT pac.`id_attribute`, pa.`id_product_attribute` + FROM `'._DB_PREFIX_.'product_attribute` pa + LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac + ON (pa.`id_product_attribute` = pac.`id_product_attribute`) + '); $toRemove = array(); - foreach ($attributeCombinations AS $attributeCombination) - if ((int)($attributeCombination['id_attribute']) == 0) - $toRemove[] = (int)($attributeCombination['id_product_attribute']); - if (!empty($toRemove) AND Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute` WHERE `id_product_attribute` IN ('.implode(', ', $toRemove).')') === false) + foreach ($attributeCombinations as $attributeCombination) + if ((int)$attributeCombination['id_attribute'] == 0) + $toRemove[] = (int)$attributeCombination['id_product_attribute']; + if (!empty($toRemove) AND Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_attribute` + WHERE `id_product_attribute` + IN ('.implode(', ', $toRemove).')') === false) return false; return true; } @@ -112,20 +121,31 @@ class AttributeGroupCore extends ObjectModel public function delete() { /* Select children in order to find linked combinations */ - $attributeIds = Db::getInstance()->executeS('SELECT `id_attribute` FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)($this->id)); + $attributeIds = Db::getInstance()->executeS(' + SELECT `id_attribute` + FROM `'._DB_PREFIX_.'attribute` + WHERE `id_attribute_group` = '.(int)$this->id + ); if ($attributeIds === false) return false; /* Removing attributes to the found combinations */ $toRemove = array(); - foreach ($attributeIds AS $attribute) - $toRemove[] = (int)($attribute['id_attribute']); - if (!empty($toRemove) AND Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` WHERE `id_attribute` IN ('.implode(', ', $toRemove).')') === false) + foreach ($attributeIds as $attribute) + $toRemove[] = (int)$attribute['id_attribute']; + if (!empty($toRemove) && Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` + WHERE `id_attribute` + IN ('.implode(', ', $toRemove).')') === false) return false; /* Remove combinations if they do not possess attributes anymore */ if (!self::cleanDeadCombinations()) return false; /* Also delete related attributes */ - if (Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'attribute_lang` WHERE `id_attribute` IN (SELECT id_attribute FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)($this->id).')') === false OR Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)($this->id)) === false) + if (Db::getInstance()->execute(' + DELETE FROM `'._DB_PREFIX_.'attribute_lang` + WHERE `id_attribute` + IN (SELECT id_attribute FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)$this->id.')') === false || + Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'attribute` WHERE `id_attribute_group` = '.(int)$this->id) === false) return false; $return = parent::delete(); if($return) @@ -145,11 +165,13 @@ class AttributeGroupCore extends ObjectModel if (!Combination::isFeatureActive()) return array(); return Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'attribute` a - LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)($id_lang).') - WHERE a.`id_attribute_group` = '.(int)($id_attribute_group).' - ORDER BY `position` ASC'); + SELECT * + FROM `'._DB_PREFIX_.'attribute` a + LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al + ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.') + WHERE a.`id_attribute_group` = '.(int)$id_attribute_group.' + ORDER BY `position` ASC + '); } /** @@ -162,11 +184,14 @@ class AttributeGroupCore extends ObjectModel { if (!Combination::isFeatureActive()) return array(); + return Db::getInstance()->executeS(' - SELECT * - FROM `'._DB_PREFIX_.'attribute_group` ag - LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND `id_lang` = '.(int)($id_lang).') - ORDER BY `name` ASC'); + SELECT * + FROM `'._DB_PREFIX_.'attribute_group` ag + LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl + ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND `id_lang` = '.(int)$id_lang.') + ORDER BY `name` ASC + '); } /** @@ -177,7 +202,7 @@ class AttributeGroupCore extends ObjectModel public function deleteSelection($selection) { /* Also delete Attributes */ - foreach ($selection AS $value) + foreach ($selection as $value) { $obj = new AttributeGroup($value); if (!$obj->delete()) @@ -212,7 +237,10 @@ class AttributeGroupCore extends ObjectModel public function getWsProductOptionValues() { - $result = Db::getInstance()->executeS('SELECT id_attribute AS id from `'._DB_PREFIX_.'attribute` WHERE id_attribute_group = '.(int)$this->id); + $result = Db::getInstance()->executeS(' + SELECT id_attribute AS id from `'._DB_PREFIX_.'attribute` + WHERE id_attribute_group = '.(int)$this->id + ); return $result; } @@ -232,7 +260,7 @@ class AttributeGroupCore extends ObjectModel )) return false; - foreach ($res AS $group_attribute) + foreach ($res as $group_attribute) if ((int)$group_attribute['id_attribute_group'] == (int)$this->id) $movedGroupAttribute = $group_attribute; @@ -247,11 +275,12 @@ class AttributeGroupCore extends ObjectModel WHERE `position` '.($way ? '> '.(int)$movedGroupAttribute['position'].' AND `position` <= '.(int)$position - : '< '.(int)$movedGroupAttribute['position'].' AND `position` >= '.(int)$position)) - AND Db::getInstance()->execute(' + : '< '.(int)$movedGroupAttribute['position'].' AND `position` >= '.(int)$position) + ) && Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'attribute_group` SET `position` = '.(int)$position.' - WHERE `id_attribute_group`='.(int)$movedGroupAttribute['id_attribute_group'])); + WHERE `id_attribute_group`='.(int)$movedGroupAttribute['id_attribute_group']) + ); } /** @@ -265,17 +294,18 @@ class AttributeGroupCore extends ObjectModel $return = true; $sql = ' - SELECT `id_attribute_group` - FROM `'._DB_PREFIX_.'attribute_group` - ORDER BY `position`'; + SELECT `id_attribute_group` + FROM `'._DB_PREFIX_.'attribute_group` + ORDER BY `position`'; $result = Db::getInstance()->executeS($sql); $i = 0; foreach ($result as $value) $return = Db::getInstance()->execute(' - UPDATE `'._DB_PREFIX_.'attribute_group` - SET `position` = '.(int)$i++.' - WHERE `id_attribute_group` = '.(int)$value['id_attribute_group']); + UPDATE `'._DB_PREFIX_.'attribute_group` + SET `position` = '.(int)$i++.' + WHERE `id_attribute_group` = '.(int)$value['id_attribute_group'] + ); return $return; } diff --git a/controllers/admin/AdminAttributesGroupsController.php b/controllers/admin/AdminAttributesGroupsController.php new file mode 100644 index 000000000..68a134163 --- /dev/null +++ b/controllers/admin/AdminAttributesGroupsController.php @@ -0,0 +1,542 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 7307 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminAttributesGroupsControllerCore extends AdminController +{ + public function __construct() + { + $this->context = Context::getContext(); + $this->table = 'attribute_group'; + $this->className = 'AttributeGroup'; + $this->lang = true; + + $this->fieldsDisplay = array( + 'id_attribute_group' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'name' => array( + 'title' => $this->l('Name'), + 'width' => 140, + 'filter_key' => 'b!name' + ), + 'position' => array( + 'title' => $this->l('Position'), + 'width' => 40, + 'filter_key' => 'cp!position', + 'position' => 'position' + ) + ); + + parent::__construct(); + } + + /** + * AdminController::initList() override + * @see AdminController::initList() + */ + public function initList() + { + $this->addRowAction('edit'); + $this->addRowAction('delete'); + $this->addRowAction('details'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + return parent::initList(); + } + + /** + * method call when ajax request is made with the details row action + * @see AdminController::postProcess() + */ + public function ajaxProcess() + { + // test if an id is submit + if (($id = Tools::getValue('id')) && Tools::isSubmit('id')) + { + $this->table = 'attribute'; + $this->className = 'Attribute'; + $this->identifier = 'id_attribute'; + $this->lang = true; + + if (!Validate::isLoadedObject($obj = new AttributeGroup((int)$id))) + $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); + + $this->fieldsDisplay = array( + 'id_attribute' => array( + 'title' => $this->l('ID'), + 'width' => 25 + ), + 'name' => array( + 'title' => $this->l('Name'), + 'width' => 140, + 'filter_key' => 'b!name' + ) + ); + + if ($obj->group_type == 'color') + $this->fieldsDisplay['color'] = array( + 'title' => $this->l('Color'), + 'width' => 40, + 'filter_key' => 'b!color' + ); + + $this->fieldsDisplay['position'] = array( + 'title' => $this->l('Position'), + 'width' => 40, + 'filter_key' => 'cp!position', + 'position' => 'position' + ); + + $this->addRowAction('edit'); + $this->addRowAction('delete'); + + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + + // override attributes + $this->display = 'list'; + $this->tpl_folder = 'attributes/'; + + $this->_where = 'AND a.`id_attribute_group` = '.(int)$id; + $this->_orderBy = 'position'; + + // get list and force no limit clause in the request + $this->getList($this->context->language->id); + + // Render list + $helper = new HelperList(); + $helper->actions = $this->actions; + $helper->no_link = true; + $helper->shopLinkType = ''; + $helper->identifier = $this->identifier; + $helper->orderBy = 'position'; + $helper->orderWay = 'ASC'; + $helper->currentIndex = self::$currentIndex; + $helper->token = $this->token; + $helper->table = $this->table; + $helper->simple_header = true; + $helper->bulk_actions = $this->bulk_actions; + if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'list_content.tpl')) + $helper->content_tpl = $this->tpl_folder.'list_content.tpl'; + $content = $helper->generateList($this->_list, $this->fieldsDisplay); + + echo Tools::jsonEncode(array('use_parent_structure' => false, 'data' => $content)); + } + + die; + } + + /** + * AdminController::initForm() override + * @see AdminController::initForm() + */ + public function initForm() + { + $group_type = array( + array( + 'id' => 'select', + 'name' => $this->l('Select') + ), + array( + 'id' => 'radio', + 'name' => $this->l('Radio button') + ), + array( + 'id' => 'color', + 'name' => $this->l('Color') + ), + ); + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Attributes group'), + 'image' => '../img/admin/asterisk.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'lang' => true, + 'attributeLang' => 'name¤public_name', + 'size' => 33, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'text', + 'label' => $this->l('Public name:'), + 'name' => 'public_name', + 'lang' => true, + 'attributeLang' => 'name¤public_name', + 'size' => 33, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}', + 'p' => $this->l('Term or phrase displayed to the customer') + ), + array( + 'type' => 'select', + 'label' => $this->l('Group type:'), + 'name' => 'group_type', + 'required' => true, + 'options' => array( + 'query' => $group_type, + 'id' => 'id', + 'name' => 'name' + ), + 'p' => $this->l('Choose the type of the attribute group') + ) + ) + ); + + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'group_shop', + 'label' => $this->l('Group Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form['submit'] = array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ); + + if (!($obj = $this->loadObject(true))) + return; + + //Added values of object Shop + if ($obj->id) + { + $assos = array(); + $sql = 'SELECT `id_group_shop`, `'.pSQL($this->identifier).'` + FROM `'._DB_PREFIX_.pSQL($this->table).'_group_shop` + WHERE `'.pSQL($this->identifier).'` = '.(int)$obj->id; + foreach (Db::getInstance()->executeS($sql) as $row) + $this->fields_value['shop'][$row['id_group_shop']][] = $row[$this->identifier]; + } + + return parent::initForm(); + } + + public function initFormAttributes() + { + $attributes_groups = AttributeGroup::getAttributesGroups($this->context->language->id); + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Attributes group'), + 'image' => '../img/admin/asterisk.gif' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name:'), + 'name' => 'name', + 'lang' => true, + 'attributeLang' => 'name', + 'size' => 33, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'select', + 'label' => $this->l('Group type:'), + 'name' => 'id_attribute_group', + 'required' => true, + 'options' => array( + 'query' => $attributes_groups, + 'id' => 'id_attribute_group', + 'name' => 'name' + ), + 'p' => $this->l('Choose the type of the attribute group') + ) + ) + ); + + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'group_shop', + 'label' => $this->l('Group Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form['input'][] = array( + 'type' => 'color', + 'label' => $this->l('Color:'), + 'name' => 'color', + 'size' => 33, + 'p' => $this->l('HTML colors only (e.g.,').' "lightblue", "#CC6600")' + ); + + $this->fields_form['input'][] = array( + 'type' => 'file', + 'label' => $this->l('Texture:'), + 'name' => 'texture', + 'p' => array( + $this->l('Upload color texture from your computer'), + $this->l('This will override the HTML color!') + ) + ); + + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Current texture:'), + 'name' => 'texture' + ); + + $this->fields_form['submit'] = array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ); + + // Override var of Controller + $this->table = 'attribute'; + $this->className = 'Attribute'; + $this->identifier = 'id_attribute'; + $this->lang = true; + $this->tpl_folder = 'attributes/'; + $this->fieldImageSettings = array('name' => 'texture', 'dir' => 'co'); + + // Create object Attribute + if (!$obj = new Attribute((int)Tools::getValue($this->identifier))) + return; + + // known fields are filled + $this->fields_value = array( + 'id_attribute_group' => $this->getFieldValue($obj, 'id_attribute_group'), + 'name' => $this->getFieldValue($obj, 'name'), + 'color' => $this->getFieldValue($obj, 'color'), + 'id_attribute' => $this->getFieldValue($obj, 'id'), + ); + + // Added values of object GroupShop + if ($obj->id) + { + $assos = array(); + $sql = 'SELECT `id_group_shop`, `'.pSQL($this->identifier).'` + FROM `'._DB_PREFIX_.pSQL($this->table).'_group_shop` + WHERE `'.pSQL($this->identifier).'` = '.(int)$obj->id; + foreach (Db::getInstance()->executeS($sql) as $row) + $this->fields_value['shop'][$row['id_group_shop']][] = $row[$this->identifier]; + } + + $str_attributes_groups = ''; + foreach ($attributes_groups AS $attribute_group) + $str_attributes_groups .= '"'.$attribute_group['id_attribute_group'].'" : '.($attribute_group['group_type'] == 'color' ? '1' : '0' ) .', '; + + $image = _PS_IMG_DIR_.$this->fieldImageSettings['dir'].'/'.$obj->id.'.jpg'; + $this->context->smarty->assign(array( + 'strAttributesGroups' => $str_attributes_groups, + 'colorAttributeProperties' => Validate::isLoadedObject($obj) && $obj->isColorAttribute(), + 'imageTextureExists' => file_exists($image), + 'imageTexture' => $image, + 'imageTextureUrl' => Tools::safeOutput($_SERVER['REQUEST_URI']).'&deleteImage=1' + )); + + return parent::initForm(); + } + + /** + * AdminController::init() override + * @see AdminController::init() + */ + public function init() + { + if (Tools::isSubmit('updateattribute')) + $this->display = 'editAttributes'; + + parent::init(); + } + + /** + * AdminController::initContent() override + * @see AdminController::initContent() + */ + public function initContent() + { + if (!Combination::isFeatureActive()) + { + $this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' '.$this->l('Performances').''); + return; + } + + if ($this->display == 'edit' || $this->display == 'add') + { + if (!($this->object = $this->loadObject(true))) + return; + $this->content .= $this->initForm(); + } + else if ($this->display == 'editAttributes') + { + if (!$this->object = new Attribute((int)Tools::getValue('id_attribute'))) + return; + + $this->content .= $this->initFormAttributes(); + } + else if ($this->display != 'view' && !$this->ajax) + { + $this->toolbar_btn['newAttributes'] = array( + 'href' => self::$currentIndex.'&updateattribute&token='.$this->token, + 'desc' => $this->l('Add new Attributes') + ); + + // toolbar (save, cancel, new, ..) + $this->initToolbar(); + + $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, + 'url_post' => self::$currentIndex.'&token='.$this->token, + )); + } + + public function postProcess() + { + if (!Combination::isFeatureActive()) + return; + + Module::hookExec('postProcessAttributeGroup', + array('errors' => &$this->_errors)); // send _errors as reference to allow postProcessAttributeGroup to stop saving process + + /** + * If it's an attribute, load object Attribute() + */ + if (Tools::getValue('id_attribute') || Tools::isSubmit('deleteattribute') || Tools::isSubmit('submitAddattribute')) + { + // Override var of Controller + $this->table = 'attribute'; + $this->className = 'Attribute'; + $this->identifier = 'id_attribute'; + + if ($this->tabAccess['edit'] !== '1') + $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + else if (!$object = new Attribute((int)Tools::getValue($this->identifier))) + $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); + + if (Tools::getValue('position') && Tools::getValue('id_attribute')) + { + $_POST['id_attribute_group'] = $object->id_attribute_group; + if (!$object->updatePosition((int)Tools::getValue('way'), (int)Tools::getValue('position'))) + $this->_errors[] = Tools::displayError('Failed to update the position.'); + else + Tools::redirectAdmin(self::$currentIndex.'&conf=5&token='.Tools::getAdminTokenLite('AdminAttributesGroups')); + } + else if(Tools::isSubmit('deleteattribute') && Tools::getValue('id_attribute')) + { + if (!$object->delete()) + $this->_errors[] = Tools::displayError('Failed to delete attribute.'); + else + Tools::redirectAdmin(self::$currentIndex.'&conf=1&token='.Tools::getAdminTokenLite('AdminAttributesGroups')); + } + else if (Tools::isSubmit('submitAddattribute')) + { + $this->action = 'save'; + $id_attribute = (int)Tools::getValue('id_attribute'); + // Adding last position to the attribute if not exist + if ($id_attribute <= 0) + { + $sql = 'SELECT `position`+1 + FROM `'._DB_PREFIX_.'attribute` + WHERE `id_attribute_group` = '.(int)Tools::getValue('id_attribute_group').' + ORDER BY position DESC'; + // set the position of the new group attribute in $_POST for postProcess() method + $_POST['position'] = DB::getInstance()->getValue($sql); + } + $_POST['id_parent'] = 0; + parent::postProcess(); + } + } + else + { + if(Tools::getValue('submitDel'.$this->table)) + { + if ($this->tabAccess['delete'] === '1') + { + if (isset($_POST[$this->table.'Box'])) + { + $object = new $this->className(); + if ($object->deleteSelection($_POST[$this->table.'Box'])) + Tools::redirectAdmin(self::$currentIndex.'&conf=2'.'&token='.$this->token); + $this->_errors[] = Tools::displayError('An error occurred while deleting selection.'); + } + else + $this->_errors[] = Tools::displayError('You must select at least one element to delete.'); + } + else + $this->_errors[] = Tools::displayError('You do not have permission to delete here.'); + // clean position after delete + AttributeGroup::cleanPositions(); + } + else if (Tools::isSubmit('submitAdd'.$this->table)) + { + $id_attribute_group = (int)Tools::getValue('id_attribute_group'); + // Adding last position to the attribute if not exist + if ($id_attribute_group <= 0) + { + $sql = 'SELECT `position`+1 + FROM `'._DB_PREFIX_.'attribute_group` + ORDER BY position DESC'; + // set the position of the new group attribute in $_POST for postProcess() method + $_POST['position'] = DB::getInstance()->getValue($sql); + } + // clean \n\r characters + foreach ($_POST as $key => $value) + if (preg_match('/^name_/Ui', $key)) + $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); + parent::postProcess(); + } + else + parent::postProcess(); + } + } + + /** + * Modifying initial getList method to display position feature (drag and drop) + */ + public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false) + { + if ($order_by && $this->context->cookie->__get($this->table.'Orderby')) + $order_by = $this->context->cookie->__get($this->table.'Orderby'); + else + $order_by = 'position'; + + parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop); + } +} \ No newline at end of file diff --git a/controllers/admin/AdminManufacturersController.php b/controllers/admin/AdminManufacturersController.php index 83c00e5d5..288d2c0e9 100644 --- a/controllers/admin/AdminManufacturersController.php +++ b/controllers/admin/AdminManufacturersController.php @@ -306,9 +306,6 @@ class AdminManufacturersControllerCore extends AdminController if (!($manufacturer = $this->loadObject(true))) return; - /* - * 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( diff --git a/controllers/admin/AdminOrderMessageController.php b/controllers/admin/AdminOrderMessageController.php index 08b9bfa82..4e9054882 100644 --- a/controllers/admin/AdminOrderMessageController.php +++ b/controllers/admin/AdminOrderMessageController.php @@ -70,7 +70,7 @@ class AdminOrderMessageController extends AdminController array( 'type' => 'text', 'lang' => true, - 'attributeLang' => 'name¤message', + 'attributeLang' => 'name¤message', 'label' => $this->l('Name:'), 'name' => 'name', 'size' => 53, @@ -79,7 +79,7 @@ class AdminOrderMessageController extends AdminController array( 'type' => 'textarea', 'lang' => true, - 'attributeLang' => 'name¤message', + 'attributeLang' => 'name¤message', 'label' => $this->l('Message:'), 'name' => 'message', 'cols' => 50,