// Improve multishop code
This commit is contained in:
@@ -901,39 +901,4 @@ class ShopCore extends ObjectModel
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $id_category
|
||||
* @return bool
|
||||
*/
|
||||
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->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @param $id_product
|
||||
* @return bool
|
||||
*/
|
||||
public static function isProductAvailable($id_product)
|
||||
{
|
||||
$id = Context::getContext()->shop->id;
|
||||
$id_shop = $id ? $id : Configuration::get('PS_SHOP_DEFAULT');
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT p.`id_product`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('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` AND cs.`id_shop` = '.(int)$id_shop.')
|
||||
WHERE p.`id_product` = '.(int)$id_product.'
|
||||
AND cs.`id_shop` = '.(int)Context::getContext()->shop->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP)
|
||||
unset($this->fields_list['position']);
|
||||
// shop restriction : if category is not available for current shop, we redirect to the list from default category
|
||||
if (!Shop::isCategoryAvailable($this->_category->id))
|
||||
if (!$this->_category->isAssociatedToShop())
|
||||
{
|
||||
$this->redirect_after = self::$currentIndex.'&id_category='.(int)$this->context->shop->getCategory().'&token='.$this->token;
|
||||
$this->redirect();
|
||||
|
||||
@@ -49,7 +49,7 @@ class CategoryControllerCore extends FrontController
|
||||
|
||||
public function canonicalRedirection($canonicalURL = '')
|
||||
{
|
||||
if (!Shop::isCategoryAvailable(Tools::getValue('id_category')))
|
||||
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop())
|
||||
{
|
||||
$this->redirect_after = '404';
|
||||
$this->redirect();
|
||||
@@ -64,8 +64,6 @@ class CategoryControllerCore extends FrontController
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Get category ID
|
||||
$id_category = (int)Tools::getValue('id_category');
|
||||
if (!$id_category || !Validate::isUnsignedId($id_category))
|
||||
@@ -73,14 +71,8 @@ class CategoryControllerCore extends FrontController
|
||||
|
||||
// Instantiate category
|
||||
$this->category = new Category($id_category, $this->context->language->id);
|
||||
if (!Validate::isLoadedObject($this->category) || !$this->category->inShop())
|
||||
{
|
||||
$this->errors[] = Tools::displayError('Category does not exist');
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
}
|
||||
else
|
||||
$this->canonicalRedirection();
|
||||
|
||||
parent::init();
|
||||
|
||||
if (!$this->category->checkAccess($this->context->customer->id))
|
||||
$this->errors[] = Tools::displayError('You do not have access to this category.');
|
||||
|
||||
Reference in New Issue
Block a user