// Little refacto

This commit is contained in:
rMalie
2012-03-14 16:40:25 +00:00
parent dada1ccb00
commit ce70049cb6
+13 -15
View File
@@ -1367,25 +1367,23 @@ class CategoryCore extends ObjectModel
*/ */
public function addShop($id_shop) public function addShop($id_shop)
{ {
$sql = ' $data = array();
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES
';
$datas = '';
if (!$id_shop) if (!$id_shop)
{ {
foreach (Shop::getShops(true) as $shop) foreach (Shop::getShops(false) as $shop)
if (!$this->existsInShop($shop['id_shop'])) if (!$this->existsInShop($shop['id_shop']))
$datas .= '('.(int)$this->id.', '.(int)$shop['id_shop'].'),'; $data[] = array(
// removing last comma to avoid SQL error 'id_category' => (int)$this->id,
$datas = substr($datas, 0, strlen($datas) - 1); 'id_shop' => (int)$shop['id_shop'],
} else );
if (!$this->existsInShop($id_shop)) }
$datas .= '('.(int)$this->id.', '.(int)$id_shop.')'; else if (!$this->existsInShop($id_shop))
$data[] = array(
'id_category' => (int)$this->id,
'id_shop' => (int)$id_shop,
);
if (empty($datas)) return Db::getInstance()->insert('category_shop', $data);
return false;
else
return Db::getInstance()->execute($sql.$datas);
} }
public static function getRootCategories($id_lang = null, $active = true) public static function getRootCategories($id_lang = null, $active = true)