[-] BO : BugFix : #PSFV-664 : Category import handles multishop now

This commit is contained in:
vChabot
2012-03-14 16:21:03 +00:00
parent c1b4f8aea7
commit ae41a646b5
2 changed files with 38 additions and 7 deletions
+22 -7
View File
@@ -1367,19 +1367,25 @@ class CategoryCore extends ObjectModel
*/
public function addShop($id_shop)
{
$sql = '';
$sql = '
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES
';
$datas = '';
if (!$id_shop)
{
foreach (Shop::getShops(true) as $shop)
$sql .= '('.(int)$this->id.', '.(int)$shop['id_shop'].'),';
if (!$this->existsInShop($shop['id_shop']))
$datas .= '('.(int)$this->id.', '.(int)$shop['id_shop'].'),';
// removing last comma to avoid SQL error
$sql = substr($sql, 0, strlen($sql) - 1);
$datas = substr($datas, 0, strlen($datas) - 1);
} else
$sql .= '('.(int)$this->id.', '.(int)$id_shop.')';
if (!$this->existsInShop($id_shop))
$datas .= '('.(int)$this->id.', '.(int)$id_shop.')';
return Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES
'.$sql);
if (empty($datas))
return false;
else
return Db::getInstance()->execute($sql.$datas);
}
public static function getRootCategories($id_lang = null, $active = true)
@@ -1524,4 +1530,13 @@ class CategoryCore extends ObjectModel
return $return;
}
public function existsInShop($id_shop)
{
return (bool)Db::getInstance()->getValue('
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_shop`
WHERE `id_category` = '.(int)$this->id.'
AND `id_shop` = '.(int)$id_shop);
}
}