[*] BO : carriers are now sortable by position

// Carriers class is now normalized
// Attribute class is now normalized
This commit is contained in:
vChabot
2011-10-11 16:29:34 +00:00
parent 14edca152a
commit eecca47bfa
13 changed files with 587 additions and 440 deletions
+47 -20
View File
@@ -737,9 +737,9 @@ if (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEm
if (Tools::isSubmit('syncImapMail'))
{
if (!$url = Configuration::get('PS_SAV_IMAP_URL')
OR !$port = Configuration::get('PS_SAV_IMAP_PORT')
OR !$user = Configuration::get('PS_SAV_IMAP_USER')
OR !$password = Configuration::get('PS_SAV_IMAP_PWD'))
|| !$port = Configuration::get('PS_SAV_IMAP_PORT')
|| !$user = Configuration::get('PS_SAV_IMAP_USER')
|| !$password = Configuration::get('PS_SAV_IMAP_PWD'))
die('{"hasError" : true, "errors" : ["Configuration is not correct"]}');
if (!function_exists('imap_open'))
@@ -798,7 +798,7 @@ if (Tools::isSubmit('syncImapMail'))
preg_match('/\#ct([0-9]*)/', $subject, $matches1);
preg_match('/\#tc([0-9-a-z-A-Z]*)/', $subject, $matches2);
if (isset($matches1[1]) AND isset($matches2[1]))
if (isset($matches1[1]) && isset($matches2[1]))
{
//check if order exist in database
$ct = new CustomerThread((int)$matches1[1]);
@@ -822,18 +822,18 @@ if (Tools::isSubmit('syncImapMail'))
/* Modify attribute position */
if (Tools::isSubmit('ajaxAttributesPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_attribute = (int)(Tools::getValue('id_attribute'));
$id_attribute_group = (int)(Tools::getValue('id_attribute_group'));
$positions = Tools::getValue('attribute_'.(int)(Tools::getValue('id_attribute_group')));
$way = (int)Tools::getValue('way');
$id_attribute = (int)Tools::getValue('id_attribute');
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
$positions = Tools::getValue('attribute_'.(int)Tools::getValue('id_attribute_group'));
if (is_array($positions))
foreach ($positions AS $position => $value)
foreach ($positions as $position => $value)
{
// pos[1] = id_attribute_group, pos[2] = id_attribute, pos[3]=old position
$pos = explode('_', $value);
if ((isset($pos[1]) AND isset($pos[2])) AND ($pos[1] == $id_attribute_group AND (int)$pos[2] === $id_attribute))
if ((isset($pos[1]) && isset($pos[2])) && ($pos[1] == $id_attribute_group && (int)$pos[2] === $id_attribute))
{
if ($attribute = new Attribute((int)$pos[2]))
if (isset($position) && $attribute->updatePosition($way, $position))
@@ -851,8 +851,8 @@ if (Tools::isSubmit('ajaxAttributesPositions'))
/* Modify group attribute position */
if (Tools::isSubmit('ajaxGroupsAttributesPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_attribute_group = (int)(Tools::getValue('id_attribute_group'));
$way = (int)Tools::getValue('way');
$id_attribute_group = (int)Tools::getValue('id_attribute_group');
$positions = Tools::getValue('attribute_group');
$new_positions = array();
@@ -860,12 +860,12 @@ if (Tools::isSubmit('ajaxGroupsAttributesPositions'))
if (count(explode('_', $v)) == 3)
$new_positions[] = $v;
foreach ($new_positions AS $position => $value)
foreach ($new_positions as $position => $value)
{
// pos[1] = id_attribute_group, pos[2] = old position
$pos = explode('_', $value);
if (isset($pos[1]) AND (int)$pos[1] === $id_attribute_group)
if (isset($pos[1]) && (int)$pos[1] === $id_attribute_group)
{
if ($group_attribute = new AttributeGroup((int)$pos[1]))
if (isset($position) && $group_attribute->updatePosition($way, $position))
@@ -883,8 +883,8 @@ if (Tools::isSubmit('ajaxGroupsAttributesPositions'))
/* Modify feature position */
if (Tools::isSubmit('ajaxFeaturesPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_feature = (int)(Tools::getValue('id_feature'));
$way = (int)Tools::getValue('way');
$id_feature = (int)Tools::getValue('id_feature');
$positions = Tools::getValue('feature');
$new_positions = array();
@@ -892,20 +892,47 @@ if (Tools::isSubmit('ajaxFeaturesPositions'))
if (!empty($v))
$new_positions[] = $v;
foreach ($new_positions AS $position => $value)
foreach ($new_positions as $position => $value)
{
// pos[1] = id_feature, pos[2] = old position
$pos = explode('_', $value);
if (isset($pos[1]) AND (int)$pos[1] === $id_feature)
if (isset($pos[1]) && (int)$pos[1] === $id_feature)
{
if ($feature = new Feature((int)$pos[1]))
if (isset($position) && $feature->updatePosition($way, $position))
echo "ok position $position for feature $pos[1]\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update feature '. $id_attribute_group . ' to position '.$position.' "}';
echo '{"hasError" : true, "errors" : "Can not update feature '. $id_feature . ' to position '.$position.' "}';
else
echo '{"hasError" : true, "errors" : "This feature ('.$id_attribute_group.') can t be loaded"}';
echo '{"hasError" : true, "errors" : "This feature ('.$id_feature.') can t be loaded"}';
break;
}
}
}
/* Modify carrier position */
if (Tools::isSubmit('ajaxCarriersPositions'))
{
$way = (int)(Tools::getValue('way'));
$id_carrier = (int)(Tools::getValue('id_carrier'));
$positions = Tools::getValue('carrier');
foreach ($positions as $position => $value)
{
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_carrier)
{
if ($carrier = new Carrier((int)$pos[2]))
if (isset($position) && $carrier->updatePosition($way, $position))
echo "ok position $position for carrier $pos[1]\r\n";
else
echo '{"hasError" : true, "errors" : "Can not update carrier '. $id_carrier . ' to position '.$position.' "}';
else
echo '{"hasError" : true, "errors" : "This carrier ('.$id_carrier.') can t be loaded"}';
break;
}
+29 -17
View File
@@ -45,7 +45,8 @@ class AdminCarriers extends AdminTab
'logo' => array('title' => $this->l('Logo'), 'align' => 'center', 'image' => 's', 'orderby' => false, 'search' => false),
'delay' => array('title' => $this->l('Delay'), 'width' => 300, 'orderby' => false),
'active' => array('title' => $this->l('Status'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false)
'is_free' => array('title' => $this->l('Is Free'), 'align' => 'center', 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif', 'default' => 'disabled.gif'), 'type' => 'bool', 'orderby' => false),
'position' => array('title' => $this->l('Position'), 'width' => 40,'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position')
);
$this->optionsList = array(
@@ -81,7 +82,7 @@ class AdminCarriers extends AdminTab
</ul>
</div><br />';
}
public function displayForm($isMainTab = true)
{
parent::displayForm();
@@ -163,7 +164,7 @@ class AdminCarriers extends AdminTab
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
<td><input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_'.$group['id_group'].'" value="'.$group['id_group'].'"
'.((Db::getInstance()->getValue('SELECT id_group FROM '._DB_PREFIX_.'carrier_group
WHERE id_carrier='.(int)($obj->id).' AND id_group='.(int)($group['id_group'])) || (!isset($obj->id))) ? 'checked="checked" ' : '').'/></td>
WHERE id_carrier='.(int)$obj->id.' AND id_group='.(int)$group['id_group']) || (!isset($obj->id))) ? 'checked="checked" ' : '').'/></td>
<td>'.$group['id_group'].'</td>
<td><label for="groupBox_'.$group['id_group'].'" class="t">'.$group['name'].'</label></td>
</tr>';
@@ -290,7 +291,7 @@ class AdminCarriers extends AdminTab
$this->validateRules();
if (!count($this->_errors))
{
$id = (int)(Tools::getValue('id_'.$this->table));
$id = (int)Tools::getValue('id_'.$this->table);
/* Object update */
if (isset($id) && !empty($id))
@@ -303,22 +304,23 @@ class AdminCarriers extends AdminTab
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'carrier_group WHERE id_carrier = '.(int)$id);
$object->deleted = 1;
$object->update();
$objectNew = new $this->className();
$this->copyFromPost($objectNew, $this->table);
$result = $objectNew->add();
if (Validate::isLoadedObject($objectNew))
$object_new = new $this->className();
$this->copyFromPost($object_new, $this->table);
$object_new->position = $object->position;
$result = $object_new->add();
if (Validate::isLoadedObject($object_new))
{
$this->afterDelete($objectNew, $object->id);
Hook::updateCarrier((int)($object->id), $objectNew);
$this->afterDelete($object_new, $object->id);
Hook::updateCarrier((int)$object->id, $object_new);
}
$this->changeGroups($objectNew->id);
$this->changeGroups($object_new->id);
if (!$result)
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b>';
else if ($this->postImage($objectNew->id))
{
$this->changeZones($objectNew->id);
Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4'.'&token='.$this->token);
}
else if ($this->postImage($object_new->id))
{
$this->changeZones($object_new->id);
Tools::redirectAdmin(self::$currentIndex.'&id_'.$this->table.'='.$object->id.'&conf=4&token='.$this->token);
}
}
else
$this->_errors[] = Tools::displayError('An error occurred while updating object.').' <b>'.$this->table.'</b> '.Tools::displayError('(cannot load object)');
@@ -334,6 +336,7 @@ class AdminCarriers extends AdminTab
{
$object = new $this->className();
$this->copyFromPost($object, $this->table);
$object->position = Carrier::getHigherPosition() + 1;
if (!$object->add())
$this->_errors[] = Tools::displayError('An error occurred while creating object.').' <b>'.$this->table.'</b>';
else if (($_POST['id_'.$this->table] = $object->id /* voluntary */) && $this->postImage($object->id) && $this->_redirect)
@@ -348,7 +351,7 @@ class AdminCarriers extends AdminTab
}
}
}
elseif ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier))
else if ((isset($_GET['status'.$this->table]) || isset($_GET['status'])) && Tools::getValue($this->identifier))
{
if ($this->tabAccess['edit'] === '1')
{
@@ -395,4 +398,13 @@ class AdminCarriers extends AdminTab
$this->_list[$key]['name'] = Configuration::get('PS_SHOP_NAME');
parent::displayListContent($token);
}
/**
* 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)
{
$order_by = ($order_by && $this->context->cookie->__get($this->table.'Orderby')) ? $this->context->cookie->__get($this->table.'Orderby'): 'position';
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
}
}