[*] BO : New category management with multi shop
This commit is contained in:
@@ -663,8 +663,10 @@ class CategoryCore extends ObjectModel
|
||||
SELECT c.`id_category`, cl.`name`, cl.`link_rewrite`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.Context::getContext()->shop->addSqlRestrictionOnLang('cl').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category`
|
||||
WHERE `id_lang` = '.(int)$id_lang.'
|
||||
AND c.`id_parent` = '.(int)$id_parent.'
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true).'
|
||||
'.($active ? 'AND `active` = 1' : '').'
|
||||
ORDER BY `position` ASC');
|
||||
}
|
||||
@@ -713,8 +715,10 @@ class CategoryCore extends ObjectModel
|
||||
)' : '0').' AS nbSelectedSubCat
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON c.`id_category` = cl.`id_category`'.$shop->addSqlRestrictionOnLang('cl').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON c.`id_category` = cs.`id_category`
|
||||
WHERE `id_lang` = '.(int)$id_lang.'
|
||||
AND c.`id_parent` = '.(int)$id_parent.'
|
||||
AND cs.`id_shop` = '.(int)$shop->getID(true).'
|
||||
ORDER BY `position` ASC';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
@@ -883,7 +887,10 @@ class CategoryCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
|
||||
ON (c.`id_category` = cl.`id_category`
|
||||
AND `id_lang` = '.(int)$id_lang.Context::getContext()->shop->addSqlRestrictionOnLang('cl').')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
ON c.`id_category` = cs.`id_category`
|
||||
WHERE c.`id_category` = '.(int)$id_current.'
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true).'
|
||||
AND c.`id_parent` != 0
|
||||
');
|
||||
|
||||
@@ -1197,5 +1204,16 @@ class CategoryCore extends ObjectModel
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function isParentCategoryAvailable($id_shop)
|
||||
{
|
||||
return Db::getInstance()->getValue('
|
||||
SELECT c.`id_category`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
ON c.`id_category` = cs.`id_category`
|
||||
WHERE cs.`id_shop` = '.(int)$id_shop.'
|
||||
AND c.`id_parent` = '.(int)$this->id_parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -595,7 +595,9 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`)
|
||||
WHERE p.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
@@ -629,8 +631,10 @@ class SearchCore
|
||||
LEFT JOIN `'._DB_PREFIX_.'tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = p.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs ON (cg.`id_category` = cs.`id_category`)
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE p.`active` = 1
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID().'
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
WHERE id_customer = '.(int)$id_customer.')').'
|
||||
|
||||
@@ -172,7 +172,7 @@ class HelperCore
|
||||
<span> <a href="#" id="check_all" >'.$trads['Check All'].'</a>
|
||||
|</span>
|
||||
<span><a href="#" id="uncheck_all" >'.$trads['Uncheck All'].'</a>|</span>
|
||||
' : '').($use_search ? '<form method="post" id="filternameForm"><span>'.$trads['search'].' : <input type="text" name="search_cat" id="search_cat"></form></span>' : '').'
|
||||
' : '').($use_search ? '<span>'.$trads['search'].' : <input type="text" name="search_cat" id="search_cat"></span>' : '').'
|
||||
</div>
|
||||
';
|
||||
|
||||
|
||||
@@ -889,4 +889,104 @@ class ShopCore extends ObjectModel
|
||||
$without[] = $shop;
|
||||
return $without;
|
||||
}
|
||||
|
||||
public static function getCategories($id = 0)
|
||||
{
|
||||
// build query
|
||||
$query = new DbQuery();
|
||||
$query->select('id_category');
|
||||
$query->from('category_shop');
|
||||
$query->where('id_shop = '.(int)$id
|
||||
);
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
|
||||
$array = array();
|
||||
foreach ($result as $row)
|
||||
$array[] = $row['id_category'];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update categories for a shop
|
||||
*
|
||||
* @param string $productCategories Categories list to associate a shop
|
||||
* @return array Update/insertion result
|
||||
*/
|
||||
public function updateCategories($categories)
|
||||
{
|
||||
// if array is empty or if the default category is not selected, return false
|
||||
if (empty($categories) || !in_array($this->id_category, $categories))
|
||||
return false;
|
||||
|
||||
// delete categories for this shop
|
||||
$this->deleteCategories();
|
||||
|
||||
// and add $categories to this shop
|
||||
return $this->addToCategories($categories);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete shop from category $id_category
|
||||
* @param int $id_category
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCategory($id_category)
|
||||
{
|
||||
return Db::getInstance()->execute(
|
||||
'DELETE FROM `'._DB_PREFIX_.'category_shop`
|
||||
WHERE `id_shop` = '.(int)$this->id.'
|
||||
AND id_category = '.(int)$id_category.''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete every categories
|
||||
* @return bool
|
||||
*/
|
||||
public function deleteCategories()
|
||||
{
|
||||
return Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'category_shop` WHERE `id_shop` = '.(int)$this->id.'
|
||||
');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some categories to a shop
|
||||
* @param array $categories
|
||||
* @return bool
|
||||
*/
|
||||
public function addToCategories($categories)
|
||||
{
|
||||
$sql = '
|
||||
INSERT INTO `'._DB_PREFIX_.'category_shop` (`id_category`, `id_shop`) VALUES';
|
||||
foreach ($categories as $c)
|
||||
$sql .= '("'.(int)$c.'", "'.(int)$this->id.'"),';
|
||||
// removing last comma to avoid SQL error
|
||||
$sql = substr($sql, 0, strlen($sql) - 1);
|
||||
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public static function isCategoryAvailable($id_category)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT `id_category`
|
||||
FROM `'._DB_PREFIX_.'category_shop`
|
||||
WHERE `id_category` = '.(int)$id_category.'
|
||||
AND `id_shop` = '.(int)Context::getContext()->shop->getID(true));
|
||||
}
|
||||
|
||||
public static function isProductAvailable($id_product)
|
||||
{
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp
|
||||
ON p.`id_product` = cp.`id_product`
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_shop` cs
|
||||
ON cp.`id_category` = cs.`id_category`
|
||||
WHERE p.`id_product` = '.(int)$id_product.'
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->getID(true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user