[*] BO : #PSFV-94 - added AdminAttributesGroupController

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9774 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
lLefevre
2011-11-01 20:57:27 +00:00
parent cb2307abaf
commit ab4795f617
10 changed files with 1144 additions and 636 deletions
-203
View File
@@ -1,203 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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:').' <a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'#featuresDetachables">'.$this->l('Performances').'</a>');
return;
}
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
$color = ($obj->color ? $obj->color : 0);
$attributes_groups = AttributeGroup::getAttributesGroups($this->_defaultFormLanguage);
$strAttributesGroups = '';
echo '
<script type="text/javascript">
var attributesGroups = {';
foreach ($attributes_groups AS $attribute_group)
$strAttributesGroups .= '"'.$attribute_group['id_attribute_group'].'" : '.($attribute_group['group_type'] == 'color' ? '1' : '0' ) .',';
echo $strAttributesGroups.'};
</script>
<form action="'.self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.($token ? $token : $this->token).'" method="post" enctype="multipart/form-data">
'.($obj->id ? '<input type="hidden" name="id_attribute" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/asterisk.gif" />'.$this->l('Attribute').'</legend>
<label>'.$this->l('Name:').' </label>
<div class="margin-form">';
foreach ($this->_languages as $language)
echo '
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlspecialchars($this->getFieldValue($obj, 'name', (int)($language['id_lang']))).'" /><sup> *</sup>
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</div>';
echo '
<script type="text/javascript">
var flag_fields = \'name\';
</script>';
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true);
echo '
<div class="clear"></div>
</div>
<label>'.$this->l('Group:').' </label>
<div class="margin-form">
<select name="id_attribute_group" id="id_attribute_group" onchange="showAttributeColorGroup(\'id_attribute_group\', \'colorAttributeProperties\')">';
foreach ($attributes_groups AS $attribute_group)
echo '<option value="'.$attribute_group['id_attribute_group'].'"'.($this->getFieldValue($obj, 'id_attribute_group') == $attribute_group['id_attribute_group'] ? ' selected="selected"' : '').'>'.$attribute_group['name'].'</option>';
echo '
</select><sup> *</sup>
</div>';
if (Shop::isFeatureActive())
{
echo '<label>'.$this->l('GroupShop association:').'</label><div class="margin-form">';
$this->displayAssoShop('group_shop');
echo '</div>';
}
echo '
<script type="text/javascript" src="../js/jquery/jquery-colorpicker.js"></script>
<div id="colorAttributeProperties" style="'.((Validate::isLoadedObject($obj) AND $obj->isColorAttribute()) ? 'display: block;' : 'display: none;').'">
<label>'.$this->l('Color').'</label>
<div class="margin-form">
<input width="20px" type="color" data-hex="true" class="color mColorPickerInput" name="color" value="'.(Tools::getValue('color', $color) ? htmlentities(Tools::getValue('color', $color)) : '#000000').'" /> <sup>*</sup>
<p class="clear">'.$this->l('HTML colors only (e.g.,').' "lightblue", "#CC6600")</p>
</div>
<label>'.$this->l('Texture:').' </label>
<div class="margin-form">
<input type="file" name="texture" />
<p>'.$this->l('Upload color texture from your computer').'<br />'.$this->l('This will override the HTML color!').'</p>
</div>
<label>'.$this->l('Current texture:').' </label>
<div class="margin-form">
<p>'.(file_exists(_PS_IMG_DIR_.$this->fieldImageSettings['dir'].'/'.$obj->id.'.jpg')
? '<img src="../img/'.$this->fieldImageSettings['dir'].'/'.$obj->id.'.jpg" alt="" title="" /> <a href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&deleteImage=1"><img src="../img/admin/delete.gif" alt="" title="'.$this->l('Delete').'" />'.$this->l('Delete').'</a>'
: $this->l('None')
).'</p>
</div>
</div>
'.Module::hookExec('attributeForm', array('id_attribute' => $obj->id)).'
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAddattribute" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>
<script>
showAttributeColorGroup(\'id_attribute_group\', \'colorAttributeProperties\');
</script>';
}
/**
* 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);
}
}
-360
View File
@@ -1,360 +0,0 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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 '<br /><br /><a href="'.self::$currentIndex.'&token='.$this->token.'"><img src="../img/admin/arrow2.gif" /> '.$this->l('Back to list').'</a><br />';
}
else
parent::display();
}
else
$this->displayWarning($this->l('This feature has been disabled, you can active this feature at this page:').' <a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'#featuresDetachables">'.$this->l('Performances').'</a>');
}
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 '<br /><a href="'.self::$currentIndex.'&add'.$this->table.'&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> <b>'.$this->l('Add attributes group').'</b></a><br />
<a href="'.self::$currentIndex.'&addattribute&token='.$this->token.'"><img src="../img/admin/add.gif" border="0" /> '.$this->l('Add attribute').'</a><br /><br />
'.$this->l('Click on the group name to view its attributes. Click again to hide them.').'<br /><br />';
if ($this->_list === false)
Tools::displayError('No elements found');
$this->displayListHeader($this->token);
echo '<input type="hidden" name="groupid" value="0">';
if (!sizeof($this->_list))
echo '<tr><td class="center" colspan="'.sizeof($this->_list).'">'.$this->l('No elements found').'</td></tr>';
//$this->displayListContent($this->token);
echo '
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
<script type="text/javascript">
var token = \''.$this->token.'\';
var come_from = \''.$this->table.'\';
var alternate = \''.($this->_orderWay == 'DESC' ? '1' : '0' ).'\';
</script>
<script type="text/javascript" src="../js/admin-dnd.js"></script>
';
$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'.($irow++ % 2 ? ' class="alt_row"' : '').' id="tr_'.$id.'_'.$tr['position'].'">
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center"><input type="checkbox" name="'.$this->table.'Box[]" value="'.$id.'" class="noborder" /></td>
<td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" onclick="$(\'#attributes_'.$id.'\').slideToggle();">'.$tr['name'].'</td>
<td style="vertical-align: top; padding: 4px 0 4px 0; width: 340px">';
$this->displayListAttributes($id, $irow, $tr);
echo '
</td>';
echo '
<td style="width: 140px; vertical-align: top; padding: 4px 0 4px 0; cursor: pointer" class="dragHandle">';
if ($this->_orderBy == 'position' AND $this->_orderWay != 'DESC')
{
echo '<a'.(!($tr['position'] != $positions[sizeof($positions) - 1]) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&'.$this->identifiersDnd[$this->identifier].'='.$id.'
&way=1&position='.((int)$tr['position'] + 1).'&token='.$this->token.'">
<img src="../img/admin/'.($this->_orderWay == 'ASC' ? 'down' : 'up').'.gif"
alt="'.$this->l('Down').'" title="'.$this->l('Down').'" /></a>';
echo '<a'.(!($tr['position'] != $positions[0]) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&'.$this->identifiersDnd[$this->identifier].'='.$id.'
&way=0&position='.((int)$tr['position'] - 1).'&token='.$this->token.'">
<img src="../img/admin/'.($this->_orderWay == 'ASC' ? 'up' : 'down').'.gif"
alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a>';
}
else
echo (int)($tr['position'] + 1);
echo '
</td>
<td style="vertical-align: top; padding: 4px 0 4px 0" class="center">
<a href="'.self::$currentIndex.'&id_'.$this->table.'='.$id.'&update'.$this->table.'&token='.$this->token.'">
<img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>&nbsp;
<a href="'.self::$currentIndex.'&id_'.$this->table.'='.$id.'&delete'.$this->table.'&token='.$this->token.'" onclick="return confirm(\''.$this->l('Delete item', __CLASS__, true, false).' : '.$tr['name'].'?\');">
<img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
</td>
</tr>';
}
$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:').' <a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'#featuresDetachables">'.$this->l('Performances').'</a>');
return;
}
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
echo '
<form action="'.self::$currentIndex.'&token='.$this->token.'" method="post">
'.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
<fieldset><legend><img src="../img/admin/asterisk.gif" />'.$this->l('Attributes group').'</legend>
<label>'.$this->l('Name:').' </label>
<div class="margin-form">';
foreach ($this->_languages as $language)
echo '
<div id="name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="name_'.$language['id_lang'].'" value="'.htmlspecialchars($this->getFieldValue($obj, 'name', (int)($language['id_lang']))).'" /><sup> *</sup>
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
</div>
<script type="text/javascript">
var flag_fields = \'name¤public_name\';
</script>';
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'name', false, true);
echo '
<div class="clear"></div>
</div>
<label>'.$this->l('Public name:').' </label>
<div class="margin-form">';
foreach ($this->_languages as $language)
echo '
<div id="public_name_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $this->_defaultFormLanguage ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="public_name_'.$language['id_lang'].'" value="'.htmlspecialchars($this->getFieldValue($obj, 'public_name', (int)($language['id_lang']))).'" /><sup> *</sup>
<span class="hint" name="help_box">'.$this->l('Invalid characters:').' <>;=#{}<span class="hint-pointer">&nbsp;</span></span>
<p style="clear: both">'.$this->l('Term or phrase displayed to the customer').'</p>
</div>';
$this->displayFlags($this->_languages, $this->_defaultFormLanguage, 'flag_fields', 'public_name', false, true);
echo '
<div class="clear"></div>
</div>
<label>'.$this->l('Group type:').' </label>
<div class="margin-form">
<select name="group_type">
<option value="select" '.($this->getFieldValue($obj, 'group_type') == 'select' ? 'selected="selected" ' : '').'>'.$this->l('Select').'</option>
<option value="radio" '.($this->getFieldValue($obj, 'group_type') == 'radio' ? 'selected="selected" ' : '').'>'.$this->l('Radio button').'</option>
<option value="color" '.($this->getFieldValue($obj, 'group_type') == 'color' ? 'selected="selected" ' : '').'>'.$this->l('Color').'</option>
</select>
<p>'.$this->l('Choose the type of the attribute group').'</p>
</div>';
if (Shop::isFeatureActive())
{
echo '<label>'.$this->l('GroupShop association:').'</label><div class="margin-form">';
$this->displayAssoShop('group_shop');
echo '</div>';
}
echo '
'.Module::hookExec('attributeGroupForm', array('id_attribute_group' => $obj->id)).'
<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
</div>
<div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
</fieldset>
</form>';
}
/**
* 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 '
<div id="attributes_'.$id.'" style="display: none">
<table class="attribute table tableDnD" cellpadding="0" cellspacing="0" id="attribute_'.$id.'">
<thead>
<tr class="nodrag nodrop">
<th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'attribute'.$id.'Box[]\', this.checked)" /></th>
<th width="100%">'.$this->l('Attribute').'</th>
<th>'.$this->l('Position').'</th>
<th>'.$this->l('Actions').'</th>
</tr>
</thead>
<tbody>';
$attributes = AttributeGroup::getAttributes(Context::getContext()->language->id, $id);
$nbrow = 0;
foreach ($attributes as $attribute)
{
$id_category = 1;
$class = ($irow % 2) ? '': 'not_';
echo '
<tr'.($nbrow++ % 2 ? ' class="'.$class.'alt_row"' : '').' id="tr_'.$attribute['id_attribute_group'].'_'.$attribute['id_attribute'].'_'.$attribute['position'].'">
<td class="center"><input type="checkbox" name="attribute'.$id.'Box[]" value="'.$attribute['id_attribute'].'" class="noborder" /></td>
<td>
'.($tr['is_color_group'] ? '<div style="float: left; width: 18px; height: 12px; border: 1px solid #996633; background-color: '.$attribute['color'].'; margin-right: 4px;"></div>' : '')
.$attribute['name'].'
</td>
<td class="dragHandle" '.(isset($attribute['position']) ? ' id="td_'.(isset($id_category) && $id_category ? $id_category : 0).'_'.$attribute['id_attribute'].'"' : '').'">';
echo '<a'.(!($attribute['position'] != $attributes[sizeof($attributes) - 1]['position']) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&id_attribute_group='.(int)($attribute['id_attribute_group']).'&id_attribute='.$attribute['id_attribute'].'
&way=1&position='.(int)($attribute['position'] + 1).'&token='.$this->token.'">
<img src="../img/admin/down.gif"
alt="'.$this->l('Down').'" title="'.$this->l('Down').'" /></a>';
echo '<a'.(!($attribute['position'] != $attributes[0]['position']) ? ' style="display: none;"' : '').' href="'.self::$currentIndex.
'&id_attribute_group='.(int)($attribute['id_attribute_group']).'&&id_attribute='.$attribute['id_attribute'].'
&way=0&position='.(int)($attribute['position'] - 1).'&token='.$this->token.'">
<img src="../img/admin/up.gif"
alt="'.$this->l('Up').'" title="'.$this->l('Up').'" /></a>';
echo'
</td>
<td class="center">
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&updateattribute&token='.$this->token.'">
<img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>&nbsp;
<a href="'.self::$currentIndex.'&id_attribute='.$attribute['id_attribute'].'&deleteattribute&token='.$this->token.'"
onclick="return confirm(\''.$this->l('Delete attribute', __CLASS__, true, false).' : '.$attribute['name'].'?\');">
<img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
</td>
</tr>';
}
echo '
</tbody>
</table>
<p><input type="Submit" class="button" name="submitDelattribute" value="'.$this->l('Delete selection').'"
onclick="changeFormParam(this.form, \''.self::$currentIndex.'\', '.$id.'); return confirm(\''.$this->l('Delete selected items?', __CLASS__, true, false).'\');" /></p>
</div>';
}
/**
* 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);
}
}
+1 -1
View File
@@ -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);}
@@ -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 <contact@prestashop.com>
* @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}
<script type="text/javascript">
var attributesGroups = {ldelim}{$strAttributesGroups}{rdelim};
var vat_number = {$vat_number};
var module_dir = '{$module_dir}';
var id_language = {$defaultFormLanguage};
var languages = new Array();
$(document).ready(function() {ldelim}
{foreach $languages as $k => $language}
languages[{$k}] = {ldelim}
id_lang: {$language.id_lang},
iso_code: '{$language.iso_code}',
name: '{$language.name}'
{rdelim};
{/foreach}
displayFlags(languages, id_language, {$allowEmployeeFormLang});
{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}
if ($(".datepicker").length > 0)
$(".datepicker").datepicker({
prevText: '',
nextText: '',
dateFormat: 'yy-mm-dd'
});
$('#id_attribute_group').change(function() {
var val = $(this).val();
if (attributesGroups[val])
$('#colorAttributeProperties').show();
else
$('#colorAttributeProperties').hide();
});
{rdelim});
</script>
<script type="text/javascript" src="../js/form.js"></script>
{/if}
<div class="toolbarBox">
<ul class="cc_button">
{foreach from=$toolbar_btn item=btn key=k}
<li>
<a class="toolbar_btn" href="{$btn.href}" title="{$btn.desc}">
<span class="process-icon-{$btn.imgclass|default:$k} {$btn.class|default:'' }" ></span>{$btn.desc}
</a>
</li>
{/foreach}
</ul>
<div class="pageTitle">{* todo : what to display as title for each items (table_lang.name ? *}
<h3><span id="current_obj" style="font-weight: normal;">{$current_obj_name|default:'&nbsp;'}</span></h3>
</div>
</div>
{if isset($fields.title)}<h2>{$fields.title}</h2>{/if}
<form class="defaultForm" action="{$current}&{$submit_action}=1&token={$token}" method="post" enctype="multipart/form-data">
{if $form_id}
<input type="hidden" name="id_{$table}" value="{$form_id}" />
{/if}
<fieldset>
{foreach $fields as $key => $field}
{if $key == 'legend'}
<legend>
{if isset($field.image)}<img src="{$field.image}" alt="{$field.title}" />{/if}
{$field.title}
</legend>
{elseif $key == 'input'}
{foreach $field as $input}
{if $input.name == 'id_state'}
<div id="contains_states" {if $contains_states}style="display:none;"{/if}>
{/if}
{if $input.type == 'color'}
<div id="colorAttributeProperties" style="display:{if $colorAttributeProperties}block{else}none{/if}";>
{/if}
{block name="label"}
{if isset($input.label)}
<label>{$input.label} </label>
{/if}
{/block}
{if $input.type == 'hidden'}
<input type="hidden" name="{$input.name}" value="{$fields_value[$input.name]}" />
{else}
{block name="start_field_block"}
<div class="margin-form">
{/block}
{if $input.type == 'text' && $input.name == 'texture'}
<p>
{if $imageTextureExists}
<img src="{$imageTexture}" alt="" />
<a href="{$imageTextureUrl}"><img src="../img/admin/delete.gif" alt="" title="{l s='Delete'}" />{l s='Delete'}</a>
{else}
{l s='None'}
{/if}
</p>
{elseif $input.type == 'text'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<input type="text"
name="{$input.name}_{$language.id_lang}"
value="{$fields_value[$input.name][$language.id_lang]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{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.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<input type="text"
name="{$input.name}"
id="{$input.name}"
value="{$fields_value[$input.name]}"
{if isset($input.size)}size="{$input.size}"{/if}
{if isset($input.maxlength)}maxlength="{$input.maxlength}"{/if}
{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)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/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}
<select name="{$input.name}" id="{$input.name}" {if isset($input.multiple)}multiple="multiple" {/if}{if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
{if isset($input.options.default)}
<option value="{$input.options.default.value}">{$input.options.default.label}</option>
{/if}
{if isset($input.options.optiongroup)}
{foreach $input.options.optiongroup.query AS $optiongroup}
<optgroup label="{$optiongroup[$input.options.optiongroup.label]}">
{foreach $optiongroup[$input.options.options.query] as $option}
<option value="{$option[$input.options.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{if $field_value == $option[$input.options.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
</optgroup>
{/foreach}
{else}
{foreach $input.options.query AS $option}
<option value="{$option[$input.options.id]}"
{if isset($input.multiple)}
{foreach $fields_value[$input.name] as $field_value}
{$field_value}
{if $field_value == $option[$input.options.id]}selected="selected"{/if}
{/foreach}
{else}
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}
{/if}
>{$option[$input.options.name]|escape:'htmlall':'UTF-8'}</option>
{/foreach}
{/if}
</select>
{if isset($input.hint)}<span class="hint" name="help_box">{$input.hint}<span class="hint-pointer">&nbsp;</span></span>{/if}
{/if}
{elseif $input.type == 'radio'}
{foreach $input.values as $value}
<input type="radio"
name="{$input.name}"
id="{$value.id}"
value="{$value.value|escape:'htmlall':'UTF-8'}"
{if $fields_value[$input.name] == $value.value}checked="checked"{/if} />
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}">
{if isset($input.is_bool) && $input.is_bool == true}
{if $value.value == 1}
<img src="../img/admin/enabled.gif" alt="{$value.label}" title="{$value.label}" />
{else}
<img src="../img/admin/disabled.gif" alt="{$value.label}" title="{$value.label}" />
{/if}
{else}
{$value.label}
{/if}
</label>
{if isset($input.br) && $input.br}<br />{/if}
{/foreach}
{elseif $input.type == 'textarea'}
{if isset($input.lang) && isset($input.attributeLang)}
{foreach $languages as $language}
<div id="{$input.name}_{$language.id_lang}" style="display:{if $language.id_lang == $defaultFormLanguage}block{else}none{/if}; float: left;">
<textarea cols="{$input.cols}" rows="{$input.rows}" name="{$input.name}_{$language.id_lang}">{$fields_value[$input.name][$language.id_lang]}</textarea>
</div>
{/foreach}
{if count($languages) > 1}
<div class="displayed_flag">
<img src="../img/l/{$defaultFormLanguage}.jpg"
class="pointer"
id="language_current_{$input.name}"
onclick="toggleLanguageFlags(this);" />
</div>
<div id="languages_{$input.name}" class="language_flags">
{l s='Choose language:'}<br /><br />
{foreach $languages as $language}
<img src="../img/l/{$language.id_lang}.jpg"
class="pointer"
alt="{$language.name}"
title="{$language.name}"
onclick="changeLanguage('{$input.name}', '{$input.attributeLang}', {$language.id_lang}, '{$language.iso_code}');" />
{/foreach}
</div>
{/if}
{else}
<textarea name="{$input.name}" id="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
{/if}
{elseif $input.type == 'checkbox'}
{foreach $input.values.query as $value}
{assign var=id_checkbox value=$input.name|cat:'_'|cat:$value[$input.values.id]}
<input type="checkbox" name="{$id_checkbox}" id="{$id_checkbox}" {if $fields_value[$id_checkbox]}checked="checked"{/if} />
<label for="{$id_checkbox}" class="t"><strong>{$value[$input.values.name]}</strong></label><br />
{/foreach}
{elseif $input.type == 'file'}
{if isset($input.display_image) && $input.display_image}
{if isset($fields_value.image) && $fields_value.image}
<div id="image">
{$fields_value.image}
<p align="center">{l s='File size'} {$fields_value.size}kb</p>
<a href="{$current}&id_category={$form_id}&token={$token}&deleteImage=1">
<img src="../img/admin/delete.gif" alt="{l s='Delete'}" /> {l s='Delete'}
</a>
</div><br />
{/if}
{/if}
<input type="file" name="{$input.name}" />
{elseif $input.type == 'password'}
<input type="password"
name="{$input.name}"
size="{$input.size}"
value="" />
{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}
<label>{l s='Shop association:'}</label>
<div class="margin-form">
{$asso_shop}
</div>
{elseif $input.type == 'color'}
<script type="text/javascript" src="../js/jquery/jquery-colorpicker.js"></script>
<input type="color"
size="{$input.size}"
data-hex="true"
{if isset($input.class)}class="{$input.class}"
{else}class="color mColorPickerInput"{/if}
name="{$input.name}"
value="{$fields_value[$input.name]}" />
{elseif $input.type == 'date'}
<script type="text/javascript" src="../js/jquery/jquery-colorpicker.js"></script>
<input type="text"
size="{$input.size}"
data-hex="true"
{if isset($input.class)}class="{$input.class}"
{else}class="datepicker"{/if}
name="{$input.name}"
value="{$fields_value[$input.name]}" />
{/if}
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
{if isset($input.p)}
<p class="clear">
{if is_array($input.p)}
{foreach $input.p as $p}
{if is_array($p)}
<span id="{$p.id}">{$p.text}</span><br />
{else}
{$p}<br />
{/if}
{/foreach}
{else}
{$input.p}
{/if}
</p>
{/if}
{if isset($languages)}<div class="clear"></div>{/if}
{block name="end_field_block"}</div>{/block}
{/if}
{if $input.name == 'id_state'}
</div>
{/if}
{if $input.type == 'text' && $input.name == 'texture'}
</div>
{/if}
{/foreach}
{elseif $key == 'submit'}
<div class="margin-form">
<input type="submit" value="{$field.title}" name="{$submit_action}" {if isset($field.class)}class="{$field.class}"{/if} />
</div>
{/if}
{/foreach}
{if $required_fields}
<div class="small"><sup>*</sup> {l s ='Required field'}</div>
{/if}
{if isset($fields.tinymce) && $fields.tinymce}
<script type="text/javascript">
var iso = '{$iso}';
var pathCSS = '{$path_css}';
var ad = '{$ad}';
</script>
<script type="text/javascript" src="../js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="'../js/tinymce.inc.js"></script>
{/if}
</fieldset>
</form>
<br /><br />
{if $firstCall && !$no_back}
{if $back}
<a href="{$back}"><img src="../img/admin/arrow2.gif" />{l s='Back'}</a>
{else}
<a href="{$current}&token={$token}"><img src="../img/admin/arrow2.gif" />{l s='Back to list'}</a>
{/if}
<br />
{/if}
@@ -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 <contact@prestashop.com>
* @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
*}
<tbody>
{foreach $list AS $index => $tr}
<tr
{if $is_dnd_identifier}id="tr_{$id_category}_{$tr.$identifier}_{$tr.position}"{/if}
{if $index is odd}class="alt_row"{/if}
{if isset($tr.color) && $color_on_bg}style="background-color: {$tr.color}"{/if}
>
<td class="center">
{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}
<input type="checkbox" name="{$table}Box[]" value="{$tr.$identifier}" class="noborder" />
{/if}
{/if}
</td>
{foreach $fields_display AS $key => $params}
<td
{if isset($params.position)}
id="td_{if $id_category}{$id_category}{else}0{/if}_{$tr.$identifier}"
{/if}
class="{if !$no_link}pointer{/if}
{if isset($params.position) && $order_by == 'position'} dragHandle{/if}
{if isset($params.align)} {$params.align}{/if}"
{if (!isset($params.position) && !$no_link)}
onclick="document.location = '{$current_index}&{$identifier}={$tr.$identifier}{if $view}&view{else}&update{/if}{$table}&token={$token}'">{if isset($params.prefix)}{$params.prefix}{/if}
{else}
>
{/if}
{if isset($params.active)}
{$tr.$key}
{elseif isset($params.activeVisu)}
<img src="../img/admin/{if $tr.$key}enabled.gif{else}disabled.gif{/if}"
alt="{if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if}" title="{if $tr.$key}{l s='Enabled'}{else}{l s='Disabled'}{/if}" />
{elseif isset($params.position)}
{if $order_by == 'position' && $order_way != 'DESC'}
<a href="{$tr.$key.position_url_down}" {if !($tr.$key.position != $positions[count($positions) - 1])}style="display: none;"{/if}>
<img src="../img/admin/{if $order_way == 'ASC'}down{else}up{/if}.gif" alt="{l s='Down'}" title="{l s='Down'}" />
</a>
<a href="{$tr.$key.position_url_up}" {if !($tr.$key.position != $positions.0)}style="display: none;"{/if}>
<img src="../img/admin/{if $order_way == 'ASC'}up{else}down{/if}.gif" alt="{l s='Up'}" title="{l s='Up'}" />
</a>
{else}
{$tr.$key.position + 1}
{/if}
{elseif isset($params.image)}
{$tr.$key}
{elseif (isset($params.icon))}
<img src="../img/admin/{$tr[$key]}" alt="{$tr[$key]}" title="{$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'}
<div style="float: left; width: 18px; height: 12px; border: 1px solid #996633; background-color: {$tr.$key}; margin-right: 4px;"></div>
{elseif isset($tr.$key)}
{$tr.$key|escape:'htmlall':'UTF-8'}
{else}
--
{/if}
{if isset($params.suffix)}{$params.suffix}{/if}
</td>
{/foreach}
{if $shop_link_type}
<td class="center" {if $name != $tr.shop_name}title="{$tr.shop_name}"{/if}>{if isset($tr.shop_short_name)}{$tr.shop_short_name}{else}{$tr.shop_name}{/if}</td>
{/if}
{if $has_actions}
<td class="center" style="white-space: nowrap;">
{foreach $actions AS $action}
{if isset($tr.$action)}
{$tr.$action}
{/if}
{/foreach}
</td>
{/if}
</tr>
{/foreach}
</tbody>
+27 -17
View File
@@ -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;
+80 -50
View File
@@ -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;
}
@@ -0,0 +1,542 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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.').' <b>'.$this->table.'</b> '.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:').' <a href="index.php?tab=AdminPerformance&token='.Tools::getAdminTokenLite('AdminPerformance').'#featuresDetachables">'.$this->l('Performances').'</a>');
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.'&amp;updateattribute&amp;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.').' <b>'.$this->table.'</b> '.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);
}
}
@@ -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(
@@ -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,