diff --git a/admin-dev/themes/default/template/controllers/products/informations.tpl b/admin-dev/themes/default/template/controllers/products/informations.tpl index 5ef144efb..d7d3aaef6 100644 --- a/admin-dev/themes/default/template/controllers/products/informations.tpl +++ b/admin-dev/themes/default/template/controllers/products/informations.tpl @@ -85,24 +85,32 @@
| - - - | + +
|
| + | + + | +
| diff --git a/classes/Category.php b/classes/Category.php index 33338e903..fbbb1fea0 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -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) diff --git a/classes/Manufacturer.php b/classes/Manufacturer.php index fc45a96a3..35d800eda 100644 --- a/classes/Manufacturer.php +++ b/classes/Manufacturer.php @@ -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); } -} +} \ No newline at end of file diff --git a/classes/Product.php b/classes/Product.php index c6efa4c60..c94fc4a18 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -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` diff --git a/classes/Search.php b/classes/Search.php index 64d476338..329486fea 100644 --- a/classes/Search.php +++ b/classes/Search.php @@ -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(); diff --git a/classes/Supplier.php b/classes/Supplier.php index 477c998bb..6f2beeb07 100644 --- a/classes/Supplier.php +++ b/classes/Supplier.php @@ -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); diff --git a/classes/Validate.php b/classes/Validate.php index 67d94449d..be2067e79 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -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 * diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index dc406ba23..ee1eae5f8 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -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); diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index 87fdcb342..2a908f4f5 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -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 */ diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index a58532806..3298320e6 100755 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -60,6 +60,8 @@ class FrontControllerCore extends Controller public function __construct() { + $this->controller_type = 'front'; + global $useSSL; parent::__construct(); diff --git a/classes/controller/ModuleAdminController.php b/classes/controller/ModuleAdminController.php index ae222e517..dc0a4b835 100644 --- a/classes/controller/ModuleAdminController.php +++ b/classes/controller/ModuleAdminController.php @@ -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); diff --git a/classes/controller/ModuleFrontController.php b/classes/controller/ModuleFrontController.php index 2e6dc545c..5064369e2 100644 --- a/classes/controller/ModuleFrontController.php +++ b/classes/controller/ModuleFrontController.php @@ -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'); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 8e16ef706..76e034818 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -440,7 +440,8 @@ class AdminProductsControllerCore extends AdminController else { Hook::exec('actionProductAdd', array('product' => $product)); - Search::indexation(false, $product->id); + if (in_array($product->visibility, array('both', 'search'))) + Search::indexation(false, $product->id); $this->redirect_after = self::$currentIndex.(Tools::getIsset('id_category') ? '&id_category='.(int)Tools::getValue('id_category') : '').'&conf=19&token='.($token ? $token : $this->token); } } @@ -1436,7 +1437,8 @@ class AdminProductsControllerCore extends AdminController else { Hook::exec('actionProductAdd', array('product' => $this->object)); - Search::indexation(false, $this->object->id); + if (in_array($this->object->visibility, array('both', 'search'))) + Search::indexation(false, $this->object->id); } // If the product is virtual, set out_of_stock = 1 (allow sales when out of stock) @@ -1505,7 +1507,8 @@ class AdminProductsControllerCore extends AdminController { $this->_removeTaxFromEcotax(); $this->copyFromPost($object, $this->table); - + $object->indexed = 0; + if ($object->update()) { $this->addCarriers(); @@ -1529,7 +1532,8 @@ class AdminProductsControllerCore extends AdminController elseif (empty($this->errors)) { Hook::exec('actionProductUpdate', array('product' => $object)); - Search::indexation(false, $object->id); + if (in_array($object->visibility, array('both', 'search'))) + Search::indexation(false, $object->id); // Save and preview if (Tools::isSubmit('submitAddProductAndPreview')) diff --git a/install-dev/data/db_structure.sql b/install-dev/data/db_structure.sql index 61bb2d44b..347936ccd 100644 --- a/install-dev/data/db_structure.sql +++ b/install-dev/data/db_structure.sql @@ -1366,6 +1366,7 @@ CREATE TABLE `PREFIX_product` ( `condition` ENUM('new', 'used', 'refurbished') NOT NULL DEFAULT 'new', `show_price` tinyint(1) NOT NULL default '1', `indexed` tinyint(1) NOT NULL default '0', + `visibility` ENUM('both', 'catalog', 'search', 'none') NOT NULL default 'both', `cache_is_pack` tinyint(1) NOT NULL default '0', `cache_has_attachments` tinyint(1) NOT NULL default '0', `is_virtual` tinyint(1) NOT NULL default '0', diff --git a/install-dev/upgrade/sql/1.5.0.8.sql b/install-dev/upgrade/sql/1.5.0.8.sql new file mode 100644 index 000000000..82d4d5d8f --- /dev/null +++ b/install-dev/upgrade/sql/1.5.0.8.sql @@ -0,0 +1,5 @@ +SET NAMES 'utf8'; + +ALTER TABLE `PREFIX_product` ADD `visibility` ENUM('both', 'catalog', 'search', 'none') NOT NULL default 'both' AFTER `indexed`; + + \ No newline at end of file |