在prestashop 1.6.1.4中,我无法更改类别中的产品顺序, 当我更改管理员(产品目录>按类别筛选)时,它不会保存到数据库。
重新加载管理页面后,位置编号的值不正确,而不是1 ... N显示0,0,0,3,4,5 ......
答案 0 :(得分:0)
在classes / Product.php中,将updatePosition更改为:
public function updatePosition($way, $position)
{
$sql = '
SELECT cp.`id_product`, cp.`position`, cp.`id_category`
FROM `' . _DB_PREFIX_ . 'category_product` cp
WHERE cp.`id_category` = ' . (int)Tools::getValue('id_category', 1) . '
ORDER BY cp.`position` ASC';
if (!$res = Db::getInstance()->executeS($sql
)) {
return false;
}
$loop_position = -1;
foreach ($res as $product) {
$loop_position++;
$product['position'] = $loop_position;
$sql3 = '
UPDATE `' . _DB_PREFIX_ . 'category_product`
SET `position` = ' . (int)$loop_position . '
WHERE `id_product` = ' . (int)$product['id_product'] . '
AND `id_category`=' . (int)$product['id_category'];
Db::getInstance()->execute($sql3);
$loop_position = $product['position'];
if ((int)$product['id_product'] == (int)$this->id) {
$moved_product = $product;
}
}
if (!isset($moved_product) || !isset($position))
return false;
// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
$sql2 = '
UPDATE `' . _DB_PREFIX_ . 'category_product`
SET `position`= `position` ' . ($way ? '- 1' : '+ 1') . '
WHERE `position`
' . ($way
? '> ' . (int)$moved_product['position'] . ' AND `position` <= ' . (int)$position
: '< ' . (int)$moved_product['position'] . ' AND `position` >= ' . (int)$position) . '
AND `id_category`=' . (int)$moved_product['id_category'];
$sql3 = '
UPDATE `' . _DB_PREFIX_ . 'category_product`
SET `position` = ' . (int)$position . '
WHERE `id_product` = ' . (int)$moved_product['id_product'] . '
AND `id_category`=' . (int)$moved_product['id_category'];
return (Db::getInstance()->execute($sql2)
&& Db::getInstance()->execute($sql3));
}