[*] BO : product images can now be dragged and dropped to change position (CC021)
This commit is contained in:
@@ -335,6 +335,35 @@ if (array_key_exists('ajaxProductsPositions', $_POST))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('ajaxProductImagesPositions', $_POST))
|
||||||
|
{
|
||||||
|
$id_image = (int)(Tools::getValue('id_image'));
|
||||||
|
$way = (int)(Tools::getValue('way'));
|
||||||
|
$positions = Tools::getValue('imageTable');
|
||||||
|
|
||||||
|
if (is_array($positions))
|
||||||
|
foreach ($positions AS $key => $value)
|
||||||
|
{
|
||||||
|
$pos = explode('_', $value);
|
||||||
|
if ((isset($pos[1])) AND ($pos[1] == $id_image))
|
||||||
|
{
|
||||||
|
$position = $key;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$image = new Image($id_image);
|
||||||
|
if (Validate::isLoadedObject($image))
|
||||||
|
{
|
||||||
|
if (isset($position) && $image->updatePosition($way, $position))
|
||||||
|
die(true);
|
||||||
|
else
|
||||||
|
die('{"hasError" : true, "errors" : "Cannot update image position"}');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
die('{"hasError" : true, "errors" : "This image cannot be loaded"}');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isset($_GET['ajaxProductPackItems']))
|
if (isset($_GET['ajaxProductPackItems']))
|
||||||
{
|
{
|
||||||
$jsonArray = array();
|
$jsonArray = array();
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ class AdminProducts extends AdminTab
|
|||||||
/* Choose product image position */
|
/* Choose product image position */
|
||||||
elseif (isset($_GET['imgPosition']) AND isset($_GET['imgDirection']))
|
elseif (isset($_GET['imgPosition']) AND isset($_GET['imgDirection']))
|
||||||
{
|
{
|
||||||
$image->positionImage((int)(Tools::getValue('imgPosition')), (int)(Tools::getValue('imgDirection')));
|
$image->updatePosition(Tools::getValue('imgDirection'), Tools::getValue('imgPosition'));
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&id_product='.$image->id_product.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&add'.$this->table.'&tabs=1&token='.($token ? $token : $this->token));
|
Tools::redirectAdmin(self::$currentIndex.'&id_product='.$image->id_product.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&add'.$this->table.'&tabs=1&token='.($token ? $token : $this->token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3061,9 +3061,16 @@ class AdminProducts extends AdminTab
|
|||||||
</tr>
|
</tr>
|
||||||
<tr><td colspan="2" style="padding-bottom:10px;"><hr style="width:100%;" /></td></tr>
|
<tr><td colspan="2" style="padding-bottom:10px;"><hr style="width:100%;" /></td></tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
|
<script type="text/javascript" src="../js/jquery/jquery.tablednd_0_5.js"></script>
|
||||||
<table cellspacing="0" cellpadding="0" class="table" id="imageTable" style="display:'.($countImages == 0 ? 'none' : '').';">
|
<script type="text/javascript">
|
||||||
|
var token = \''.($token!=NULL ? $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>
|
||||||
|
<table cellspacing="0" cellpadding="0" class="table tableDnD" id="imageTable" style="display:'.($countImages == 0 ? 'none' : '').';">
|
||||||
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 100px;">'.$this->l('Image').'</th>
|
<th style="width: 100px;">'.$this->l('Image').'</th>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
@@ -3094,7 +3101,7 @@ class AdminProducts extends AdminTab
|
|||||||
echo '
|
echo '
|
||||||
<th>'.$this->l('Cover').'</th>
|
<th>'.$this->l('Cover').'</th>
|
||||||
<th>'.$this->l('Action').'</th>
|
<th>'.$this->l('Action').'</th>
|
||||||
</tr>';
|
</tr></thead>';
|
||||||
|
|
||||||
echo $this->_positionJS();
|
echo $this->_positionJS();
|
||||||
foreach ($images AS $k => $image)
|
foreach ($images AS $k => $image)
|
||||||
@@ -3138,15 +3145,14 @@ class AdminProducts extends AdminTab
|
|||||||
$imgObj = new Image((int)$image['id_image']);
|
$imgObj = new Image((int)$image['id_image']);
|
||||||
$image_obj = new Image($image['id_image']);
|
$image_obj = new Image($image['id_image']);
|
||||||
$img_path = $image_obj->getExistingImgPath();
|
$img_path = $image_obj->getExistingImgPath();
|
||||||
|
|
||||||
$html = '
|
$html = '
|
||||||
<tr id="'.$image['id_image'].'">
|
<tr id="tr_'.$image_obj->id.'_'.$image_obj->position.'">
|
||||||
<td style="padding: 4px;"><a href="'._THEME_PROD_DIR_.$img_path.'.jpg" target="_blank">
|
<td style="padding: 4px;"><a href="'._THEME_PROD_DIR_.$img_path.'.jpg" target="_blank">
|
||||||
<img src="'._THEME_PROD_DIR_.$img_path.'-small.jpg'.((int)(Tools::getValue('image_updated')) === (int)($image['id_image']) ? '?date='.time() : '').'"
|
<img src="'._THEME_PROD_DIR_.$img_path.'-small.jpg'.((int)(Tools::getValue('image_updated')) === (int)($image['id_image']) ? '?date='.time() : '').'"
|
||||||
alt="'.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').'" title="'.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').'" /></a>
|
alt="'.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').'" title="'.htmlentities(stripslashes($image['legend']), ENT_COMPAT, 'UTF-8').'" /></a>
|
||||||
</td>
|
</td>
|
||||||
<td class="center positionImage">'.(int)($image['position']).'</td>
|
<td class="center positionImage">'.(int)($image['position']).'</td>
|
||||||
<td class="position-cell">';
|
<td id="td_'.$image_obj->id.'" class="position-cell dragHandle">';
|
||||||
if ($image['position'] == 1)
|
if ($image['position'] == 1)
|
||||||
{
|
{
|
||||||
$html .= '
|
$html .= '
|
||||||
@@ -3156,16 +3162,16 @@ class AdminProducts extends AdminTab
|
|||||||
<span class="down">[ <img src="../img/admin/down_d.gif" alt="" border="0"> ]</span>';
|
<span class="down">[ <img src="../img/admin/down_d.gif" alt="" border="0"> ]</span>';
|
||||||
else
|
else
|
||||||
$html .= '
|
$html .= '
|
||||||
<span class="down">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.$image['position'].'&imgDirection=0&token='.($token ? $token : $this->token).'"><img src="../img/admin/down.gif" alt="" border="0"></a> ]</span>';
|
<span class="down">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.($image['position'] + 1).'&imgDirection=1&token='.($token ? $token : $this->token).'"><img src="../img/admin/down.gif" alt="" border="0"></a> ]</span>';
|
||||||
}
|
}
|
||||||
elseif ($image['position'] == $imagesTotal)
|
elseif ($image['position'] == $imagesTotal)
|
||||||
$html .= '
|
$html .= '
|
||||||
<span class="up">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.$image['position'].'&imgDirection=1&token='.($token ? $token : $this->token).'"><img src="../img/admin/up.gif" alt="" border="0"></a> ]</span>
|
<span class="up">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.($image['position'] - 1).'&imgDirection=0&token='.($token ? $token : $this->token).'"><img src="../img/admin/up.gif" alt="" border="0"></a> ]</span>
|
||||||
<span class="down">[ <img src="../img/admin/down_d.gif" alt="" border="0"> ]</span>';
|
<span class="down">[ <img src="../img/admin/down_d.gif" alt="" border="0"> ]</span>';
|
||||||
else
|
else
|
||||||
$html .= '
|
$html .= '
|
||||||
<span class="up">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.$image['position'].'&imgDirection=1&token='.($token ? $token : $this->token).'"><img src="../img/admin/up.gif" alt="" border="0"></a> ]</span>
|
<span class="up">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.($image['position'] - 1).'&imgDirection=0&token='.($token ? $token : $this->token).'"><img src="../img/admin/up.gif" alt="" border="0"></a> ]</span>
|
||||||
<span class="down">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.$image['position'].'&imgDirection=0&token='.($token ? $token : $this->token).'"><img src="../img/admin/down.gif" alt="" border="0"></a> ]</span>';
|
<span class="down">[ <a onclick="return hideLink();" href="'.self::$currentIndex.'&id_image='.$image['id_image'].'&imgPosition='.($image['position'] + 1).'&imgDirection=1&token='.($token ? $token : $this->token).'"><img src="../img/admin/down.gif" alt="" border="0"></a> ]</span>';
|
||||||
$html .= '
|
$html .= '
|
||||||
</td>';
|
</td>';
|
||||||
if (Shop::isMultiShopActivated())
|
if (Shop::isMultiShopActivated())
|
||||||
|
|||||||
@@ -283,9 +283,12 @@ class ImageCore extends ObjectModel
|
|||||||
*
|
*
|
||||||
* @param integer $position Position
|
* @param integer $position Position
|
||||||
* @param boolean $direction Direction
|
* @param boolean $direction Direction
|
||||||
|
* @deprecated since version 1.5.0.1 use Image::updatePosition() instead
|
||||||
*/
|
*/
|
||||||
public function positionImage($position, $direction)
|
public function positionImage($position, $direction)
|
||||||
{
|
{
|
||||||
|
Tools::displayAsDeprecated();
|
||||||
|
|
||||||
$position = (int)($position);
|
$position = (int)($position);
|
||||||
$direction = (int)($direction);
|
$direction = (int)($direction);
|
||||||
|
|
||||||
@@ -310,6 +313,36 @@ class ImageCore extends ObjectModel
|
|||||||
AND `position` = '.(int)($high_position));
|
AND `position` = '.(int)($high_position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change an image position and update relative positions
|
||||||
|
*
|
||||||
|
* @param int $way position is moved up if 0, moved down if 1
|
||||||
|
* @param int $position new position of the moved image
|
||||||
|
* @return int success
|
||||||
|
*/
|
||||||
|
public function updatePosition($way, $position)
|
||||||
|
{
|
||||||
|
if (!isset($this->id) || !$position)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// < and > statements rather than BETWEEN operator
|
||||||
|
// since BETWEEN is treated differently according to databases
|
||||||
|
$result = (Db::getInstance()->Execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'image`
|
||||||
|
SET `position`= `position` '.($way ? '- 1' : '+ 1').'
|
||||||
|
WHERE `position`
|
||||||
|
'.($way
|
||||||
|
? '> '.(int)($this->position).' AND `position` <= '.(int)($position)
|
||||||
|
: '< '.(int)($this->position).' AND `position` >= '.(int)($position)).'
|
||||||
|
AND `id_product`='.(int)($this->id_product))
|
||||||
|
&& Db::getInstance()->Execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'image`
|
||||||
|
SET `position` = '.(int)($position).'
|
||||||
|
WHERE `id_image` = '.(int)($this->id_image)));
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getSize($type)
|
public static function getSize($type)
|
||||||
{
|
{
|
||||||
if (!isset(self::$_cacheGetSize[$type]) OR self::$_cacheGetSize[$type] === NULL)
|
if (!isset(self::$_cacheGetSize[$type]) OR self::$_cacheGetSize[$type] === NULL)
|
||||||
|
|||||||
@@ -757,7 +757,6 @@ CREATE TABLE `PREFIX_image` (
|
|||||||
`cover` tinyint(1) unsigned NOT NULL default '0',
|
`cover` tinyint(1) unsigned NOT NULL default '0',
|
||||||
PRIMARY KEY (`id_image`),
|
PRIMARY KEY (`id_image`),
|
||||||
KEY `image_product` (`id_product`),
|
KEY `image_product` (`id_product`),
|
||||||
UNIQUE KEY `product_position` (`id_product`,`position`),
|
|
||||||
KEY `id_product_cover` (`id_product`,`cover`)
|
KEY `id_product_cover` (`id_product`,`cover`)
|
||||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
|||||||
@@ -75,3 +75,6 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL
|
|||||||
ALTER TABLE `PREFIX_product` ADD `available_date` DATETIME NOT NULL AFTER `available_for_order`;
|
ALTER TABLE `PREFIX_product` ADD `available_date` DATETIME NOT NULL AFTER `available_for_order`;
|
||||||
|
|
||||||
ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL;
|
ALTER TABLE `PREFIX_product_attribute` ADD `available_date` DATETIME NOT NULL;
|
||||||
|
|
||||||
|
/* Index was only used by deprecated function Image::positionImage() */
|
||||||
|
ALTER TABLE `PREFIX_image` DROP INDEX `product_position`;
|
||||||
|
|||||||
+9
-1
@@ -84,7 +84,15 @@ $(document).ready(function() {
|
|||||||
token: token
|
token: token
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (table.id == 'imageTable') {
|
||||||
|
params = {
|
||||||
|
ajaxProductImagesPositions: true,
|
||||||
|
id_image: ids[1],
|
||||||
|
way: way,
|
||||||
|
token: token
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
async: false,
|
async: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user