[+] BO : added a new option for the products : do they appear in the catalog, in the search, both or neither
This commit is contained in:
@@ -579,7 +579,11 @@ class CategoryCore extends ObjectModel
|
||||
$context = Context::getContext();
|
||||
if (!$check_access || !$this->checkAccess($context->customer->id))
|
||||
return false;
|
||||
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
if ($p < 1) $p = 1;
|
||||
|
||||
if (empty($order_by))
|
||||
@@ -618,6 +622,7 @@ class CategoryCore extends ObjectModel
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON p.`id_product` = cp.`id_product`
|
||||
WHERE cp.`id_category` = '.(int)$this->id.
|
||||
($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').
|
||||
($active ? ' AND p.`active` = 1' : '').
|
||||
($id_supplier ? 'AND p.id_supplier = '.(int)$id_supplier : '');
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
@@ -666,6 +671,7 @@ class CategoryCore extends ObjectModel
|
||||
WHERE asso_shop_product.`id_shop` = '.(int)Context::getContext()->shop->id.'
|
||||
AND cp.`id_category` = '.(int)$this->id
|
||||
.($active ? ' AND p.`active` = 1' : '')
|
||||
.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '')
|
||||
.($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '');
|
||||
|
||||
if ($random === true)
|
||||
|
||||
+23
-12
@@ -276,6 +276,10 @@ class ManufacturerCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
if ($p < 1)
|
||||
$p = 1;
|
||||
|
||||
@@ -299,6 +303,7 @@ class ManufacturerCore extends ObjectModel
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE p.id_manufacturer = '.(int)$id_manufacturer
|
||||
.($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -350,8 +355,9 @@ class ManufacturerCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m
|
||||
ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.($active ? '
|
||||
AND p.`active` = 1' : '').'
|
||||
WHERE p.`id_manufacturer` = '.(int)$id_manufacturer.'
|
||||
'.($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -376,15 +382,20 @@ class ManufacturerCore extends ObjectModel
|
||||
|
||||
public function getProductsLite($id_lang)
|
||||
{
|
||||
$sql = 'SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
WHERE p.`id_manufacturer` = '.(int)$this->id;
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
$context = Context::getContext();
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
|
||||
p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').'
|
||||
)
|
||||
WHERE p.`id_manufacturer` = '.(int)$this->id.
|
||||
($front ? ' AND p.`visibility` IN ("both", "catalog")' : ''));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -454,4 +465,4 @@ class ManufacturerCore extends ObjectModel
|
||||
|
||||
return ($result1 && $result2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
-1
@@ -174,8 +174,12 @@ class ProductCore extends ObjectModel
|
||||
/** @var boolean Show price of Product */
|
||||
public $show_price = true;
|
||||
|
||||
/** @var boolean is the product indexed in the search index? */
|
||||
public $indexed = 0;
|
||||
|
||||
/** @var string ENUM('both', 'catalog', 'search', 'none') front office visibility */
|
||||
public $visibility;
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
|
||||
@@ -260,6 +264,7 @@ class ProductCore extends ObjectModel
|
||||
'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
|
||||
'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
|
||||
'indexed' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'visibility' => array('type' => self::TYPE_STRING, 'validate' => 'isProductVisibility', 'values' => array('both', 'catalog', 'search', 'none'), 'default' => 'both'),
|
||||
'cache_is_pack' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'cache_default_attribute' => array('type' => self::TYPE_INT),
|
||||
'is_virtual' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
@@ -925,6 +930,10 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))
|
||||
die (Tools::displayError());
|
||||
if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add')
|
||||
@@ -955,6 +964,7 @@ class ProductCore extends ObjectModel
|
||||
($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'
|
||||
WHERE pl.`id_lang` = '.(int)$id_lang.
|
||||
($id_category ? ' AND c.`id_category` = '.(int)$id_category : '').
|
||||
($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').
|
||||
($only_active ? ' AND p.`active` = 1' : '').'
|
||||
ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).
|
||||
($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : '');
|
||||
@@ -969,11 +979,16 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
$sql = 'SELECT p.`id_product`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')
|
||||
WHERE pl.`id_lang` = '.(int)$id_lang.'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
ORDER BY pl.`name`';
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
}
|
||||
@@ -1775,6 +1790,10 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
if ($page_number < 0) $page_number = 0;
|
||||
if ($nb_products < 1) $nb_products = 10;
|
||||
@@ -1808,6 +1827,7 @@ class ProductCore extends ObjectModel
|
||||
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
|
||||
)
|
||||
) > 0
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -1851,6 +1871,8 @@ class ProductCore extends ObjectModel
|
||||
Product::sqlStock('p', 0, false, null, $sql);
|
||||
|
||||
$sql->where('p.`active` = 1');
|
||||
if ($front)
|
||||
$sql->where('p.`visibility` IN ("both", "catalog")');
|
||||
$sql->where('
|
||||
DATEDIFF(
|
||||
p.`date_add`,
|
||||
@@ -1923,6 +1945,10 @@ class ProductCore extends ObjectModel
|
||||
if (!$context)
|
||||
$context = Context::getContext();
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
$current_date = date('Y-m-d H:i:s');
|
||||
$ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context);
|
||||
|
||||
@@ -1965,7 +1991,8 @@ class ProductCore extends ObjectModel
|
||||
AND tr.`id_state` = 0)
|
||||
LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = tr.`id_tax`)
|
||||
'.Product::sqlStock('p', 0).'
|
||||
WHERE p.id_product = '.(int)$id_product;
|
||||
WHERE p.id_product = '.(int)$id_product.'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '');
|
||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||
|
||||
return Product::getProductProperties($id_lang, $row);
|
||||
@@ -2000,6 +2027,10 @@ class ProductCore extends ObjectModel
|
||||
$current_date = date('Y-m-d H:i:s');
|
||||
$ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context);
|
||||
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
|
||||
@@ -2010,6 +2041,7 @@ class ProductCore extends ObjectModel
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
WHERE p.`active` = 1
|
||||
AND p.`show_price` = 1
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
'.((!$beginning && !$ending) ? 'AND p.`id_product` IN('.((is_array($ids_product) && count($ids_product)) ? implode(', ', array_map('intval', $ids_product)) : 0).')' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
@@ -2053,6 +2085,7 @@ class ProductCore extends ObjectModel
|
||||
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
|
||||
WHERE p.`active` = 1
|
||||
AND p.`show_price` = 1
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
'.((!$beginning && !$ending) ? ' AND p.`id_product` IN ('.((is_array($ids_product) && count($ids_product)) ? implode(', ', $ids_product) : 0).')' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
|
||||
+6
-3
@@ -214,6 +214,7 @@ class SearchCore
|
||||
'.Shop::addSqlAssociation('product', 'p', false).'
|
||||
WHERE c.`active` = 1
|
||||
AND p.`active` = 1
|
||||
AND p.`visibility` IN ("both", "search")
|
||||
AND indexed = 1
|
||||
AND cg.`id_group` '.(!$id_customer ? '= 1' : 'IN (
|
||||
SELECT id_group FROM '._DB_PREFIX_.'customer_group
|
||||
@@ -381,7 +382,8 @@ class SearchCore
|
||||
LEFT JOIN '._DB_PREFIX_.'manufacturer m
|
||||
ON m.id_manufacturer = p.id_manufacturer
|
||||
WHERE p.indexed = 0
|
||||
'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
|
||||
AND p.visibility IN ("both", "search")
|
||||
'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
|
||||
LIMIT '.(int)$limit
|
||||
);
|
||||
}
|
||||
@@ -401,11 +403,12 @@ class SearchCore
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do it even if you already know the product id in order to be sure that it exists
|
||||
// Do it even if you already know the product id in order to be sure that it exists and it needs to be indexed
|
||||
$products = $db->executeS('
|
||||
SELECT id_product
|
||||
FROM '._DB_PREFIX_.'product
|
||||
WHERE '.($id_product ? 'id_product = '.(int)$id_product : 'indexed = 0')
|
||||
WHERE visibility IN ("both", "search")
|
||||
AND '.($id_product ? 'id_product = '.(int)$id_product : 'indexed = 0')
|
||||
);
|
||||
|
||||
$ids = array();
|
||||
|
||||
@@ -193,6 +193,11 @@ class SupplierCore extends ObjectModel
|
||||
public static function getProducts($id_supplier, $id_lang, $p, $n,
|
||||
$order_by = null, $order_way = null, $get_total = false, $active = true, $active_category = true)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
if ($p < 1) $p = 1;
|
||||
if (empty($order_by) || $order_by == 'position') $order_by = 'name';
|
||||
if (empty($order_way)) $order_way = 'ASC';
|
||||
@@ -213,6 +218,7 @@ class SupplierCore extends ObjectModel
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.'
|
||||
AND ps.id_product_attribute = 0'.
|
||||
($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -271,6 +277,7 @@ class SupplierCore extends ObjectModel
|
||||
'.Product::sqlStock('p').'
|
||||
WHERE ps.`id_supplier` = '.(int)$id_supplier.
|
||||
($active ? ' AND p.`active` = 1' : '').'
|
||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '').'
|
||||
AND p.`id_product` IN (
|
||||
SELECT cp.`id_product`
|
||||
FROM `'._DB_PREFIX_.'category_group` cg
|
||||
@@ -294,6 +301,11 @@ class SupplierCore extends ObjectModel
|
||||
|
||||
public function getProductsLite($id_lang)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$front = true;
|
||||
if (!in_array($context->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
$sql = '
|
||||
SELECT p.`id_product`,
|
||||
pl.`name`
|
||||
@@ -306,6 +318,7 @@ class SupplierCore extends ObjectModel
|
||||
ps.`id_product` = p.`id_product`
|
||||
AND ps.`id_supplier` = '.(int)$this->id.'
|
||||
)
|
||||
'.($front ? ' WHERE p.`visibility` IN ("both", "catalog")' : '').'
|
||||
GROUP BY p.`id_product`';
|
||||
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
@@ -608,6 +608,17 @@ class ValidateCore
|
||||
return preg_match('/^[^!<>;?=+#"°{}_$%]*$/u', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for product visibility
|
||||
*
|
||||
* @param string $s visibility to check
|
||||
* @return boolean Validity is ok or not
|
||||
*/
|
||||
public static function isProductVisibility($s)
|
||||
{
|
||||
return preg_match('/^both|catalog|search|none$/i', $s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for an integer validity
|
||||
*
|
||||
|
||||
@@ -259,6 +259,7 @@ class AdminControllerCore extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->controller_type = 'admin';
|
||||
$this->controller_name = get_class($this);
|
||||
if (strpos($this->controller_name, 'Controller'))
|
||||
$this->controller_name = substr($this->controller_name, 0, -10);
|
||||
|
||||
@@ -74,6 +74,8 @@ abstract class ControllerCore
|
||||
|
||||
protected $redirect_after = null;
|
||||
|
||||
public $controller_type;
|
||||
|
||||
/**
|
||||
* check that the controller is available for the current user/visitor
|
||||
*/
|
||||
|
||||
@@ -60,6 +60,8 @@ class FrontControllerCore extends Controller
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->controller_type = 'front';
|
||||
|
||||
global $useSSL;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
@@ -34,9 +34,11 @@ abstract class ModuleAdminControllerCore extends AdminController
|
||||
* @var Module
|
||||
*/
|
||||
public $module;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->controller_type = 'moduleadmin';
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$tab = new Tab($this->id);
|
||||
|
||||
@@ -37,6 +37,8 @@ class ModuleFrontControllerCore extends FrontController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->controller_type = 'modulefront';
|
||||
|
||||
$this->module = Module::getInstanceByName(Tools::getValue('module'));
|
||||
if (!$this->module->active)
|
||||
Tools::redirect('index');
|
||||
|
||||
Reference in New Issue
Block a user