[*] BO : Changed the default list view for products and categories when multistore is activated
This commit is contained in:
@@ -47,6 +47,9 @@ class CategoryCore extends ObjectModel
|
||||
/** @var integer Parent category ID */
|
||||
public $id_parent;
|
||||
|
||||
/** @var integer default Category id */
|
||||
public $id_category_default;
|
||||
|
||||
/** @var integer Parents number */
|
||||
public $level_depth;
|
||||
|
||||
@@ -95,6 +98,7 @@ class CategoryCore extends ObjectModel
|
||||
'level_depth' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
|
||||
'id_parent' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'is_root_category' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'position' => array('type' => self::TYPE_INT),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
|
||||
+16
-7
@@ -449,9 +449,19 @@ abstract class ObjectModelCore
|
||||
if ($autodate && property_exists($this, 'date_upd'))
|
||||
$this->date_upd = date('Y-m-d H:i:s');
|
||||
|
||||
|
||||
if (Shop::isTableAssociated($this->def['table']))
|
||||
{
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
}
|
||||
|
||||
// Database insertion
|
||||
if (isset($this->id))
|
||||
unset($this->id);
|
||||
if (Shop::checkIdShopDefault($this->def['table']))
|
||||
$this->id_shop_default = min($id_shop_list);
|
||||
if (!$result = ObjectModel::$db->insert($this->def['table'], $this->getFields(), $null_values))
|
||||
return false;
|
||||
|
||||
@@ -461,10 +471,6 @@ abstract class ObjectModelCore
|
||||
// Database insertion for multishop fields related to the object
|
||||
if (Shop::isTableAssociated($this->def['table']))
|
||||
{
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
$fields = $this->getFieldsShop();
|
||||
$fields[$this->def['primary']] = (int)$this->id;
|
||||
|
||||
@@ -534,7 +540,13 @@ abstract class ObjectModelCore
|
||||
// Automatically fill dates
|
||||
if (array_key_exists('date_upd', $this))
|
||||
$this->date_upd = date('Y-m-d H:i:s');
|
||||
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
if (Shop::checkIdShopDefault($this->def['table']))
|
||||
$this->id_shop_default = min($id_shop_list);
|
||||
// Database update
|
||||
if (!$result = ObjectModel::$db->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id, 0, $null_values))
|
||||
return false;
|
||||
@@ -555,9 +567,6 @@ abstract class ObjectModelCore
|
||||
else
|
||||
$all_fields = $fields;
|
||||
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
foreach ($id_shop_list as $id_shop)
|
||||
{
|
||||
|
||||
+5
-1
@@ -51,6 +51,9 @@ class ProductCore extends ObjectModel
|
||||
/** @var integer default Category id */
|
||||
public $id_category_default;
|
||||
|
||||
/** @var integer default Shop id */
|
||||
public $id_shop_default;
|
||||
|
||||
/** @var string Manufacturer name */
|
||||
public $manufacturer_name;
|
||||
|
||||
@@ -237,6 +240,7 @@ class ProductCore extends ObjectModel
|
||||
'multilang_shop' => true,
|
||||
'fields' => array(
|
||||
// Classic fields
|
||||
'id_shop_default' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'reference' => array('type' => self::TYPE_STRING, 'validate' => 'isReference', 'size' => 32),
|
||||
@@ -2451,7 +2455,7 @@ class ProductCore extends ObjectModel
|
||||
LIMIT 1
|
||||
) as default_on');
|
||||
$sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = '.(int)$id_product);
|
||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
|
||||
$sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.id_shop = p.id_shop_default'));
|
||||
}
|
||||
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
|
||||
|
||||
|
||||
@@ -109,6 +109,9 @@ class AdminControllerCore extends Controller
|
||||
|
||||
protected $shopLink;
|
||||
|
||||
/** @var string SQL query */
|
||||
protected $_listsql = '';
|
||||
|
||||
/** @var array Cache for query results */
|
||||
protected $_list = array();
|
||||
|
||||
@@ -248,6 +251,7 @@ class AdminControllerCore extends Controller
|
||||
public $controller_name;
|
||||
|
||||
public $multishop_context = -1;
|
||||
public $multishop_context_group = true;
|
||||
|
||||
/**
|
||||
* Current breadcrumb position as an array of tab names
|
||||
@@ -1927,6 +1931,9 @@ class AdminControllerCore extends Controller
|
||||
*/
|
||||
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
|
||||
{
|
||||
if (!empty($this->_listsql))
|
||||
return;
|
||||
|
||||
/* Manage default params values */
|
||||
$use_limit = true;
|
||||
if ($limit === false)
|
||||
@@ -1997,22 +2004,19 @@ class AdminControllerCore extends Controller
|
||||
$where_shop = Shop::addSqlRestriction($this->shopShareDatas, 'a', $this->shopLinkType);
|
||||
}
|
||||
|
||||
$filter_shop = '';
|
||||
if ($this->multishop_context && Shop::isTableAssociated($this->table) && !empty($this->className))
|
||||
{
|
||||
if (Shop::getContext() != Shop::CONTEXT_ALL || Shop::isTableAssociated($this->table) || !$this->context->employee->isSuperAdmin())
|
||||
{
|
||||
$idenfier_shop = Shop::getContextListShopID();
|
||||
if (!$this->_group)
|
||||
$this->_group = ' GROUP BY a.'.pSQL($this->identifier);
|
||||
elseif (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
|
||||
$this->_group .= ', a.'.pSQL($this->identifier);
|
||||
|
||||
$identifier_shop = Shop::getContextListShopID();
|
||||
$test_join = !preg_match('#`?'.preg_quote(_DB_PREFIX_.$this->table.'_shop').'`? *sa#', $this->_join);
|
||||
if (Shop::isFeatureActive() && $test_join)
|
||||
{
|
||||
$filter_shop = ' JOIN `'._DB_PREFIX_.$this->table.'_shop` sa ';
|
||||
$filter_shop .= 'ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_shop IN ('.implode(', ', $idenfier_shop).'))';
|
||||
$this->_where .= ' AND a.'.$this->identifier.' IN (
|
||||
SELECT sa.'.$this->identifier.'
|
||||
FROM `'._DB_PREFIX_.$this->table.'_shop` sa
|
||||
WHERE sa.id_shop IN ('.implode(', ', $identifier_shop).')
|
||||
)';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2021,13 +2025,14 @@ class AdminControllerCore extends Controller
|
||||
$lang_join = '';
|
||||
if ($this->lang)
|
||||
{
|
||||
$lang_join = 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'`';
|
||||
$lang_join .= ' AND b.`id_lang` = '.(int)$id_lang;
|
||||
$lang_join = 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)$id_lang;
|
||||
if ($id_lang_shop)
|
||||
{
|
||||
if (Shop::getContext() == Shop::CONTEXT_SHOP)
|
||||
$lang_join .= ' AND b.`id_shop`='.(int)$id_lang_shop;
|
||||
$lang_join .= ' AND b.`id_shop` = '.(int)$id_lang_shop;
|
||||
else
|
||||
$lang_join .= ' AND b.`id_shop` IN ('.implode(',', array_map('intval', Shop::getContextListShopID())).')';
|
||||
$lang_join .= ' AND b.`id_shop` = a.id_shop_default';
|
||||
}
|
||||
$lang_join .= ')';
|
||||
}
|
||||
|
||||
@@ -2047,23 +2052,23 @@ class AdminControllerCore extends Controller
|
||||
$order_by = pSQL($order_by[0]).'.`'.pSQL($order_by[1]).'`';
|
||||
}
|
||||
|
||||
$sql = 'SELECT SQL_CALC_FOUND_ROWS
|
||||
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
|
||||
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$select_shop.'
|
||||
FROM `'._DB_PREFIX_.$sql_table.'` a
|
||||
'.$filter_shop.'
|
||||
'.$lang_join.'
|
||||
'.(isset($this->_join) ? $this->_join.' ' : '').'
|
||||
'.$join_shop.'
|
||||
WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').
|
||||
(isset($this->_filter) ? $this->_filter : '').$where_shop.'
|
||||
'.(isset($this->_group) ? $this->_group.' ' : '').'
|
||||
'.$having_clause.'
|
||||
ORDER BY '.(($order_by == $this->identifier) ? 'a.' : '').pSQL($order_by).' '.pSQL($order_way).
|
||||
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').
|
||||
(($use_limit === true) ? ' LIMIT '.(int)$start.','.(int)$limit : '');
|
||||
$this->_listsql = '
|
||||
SELECT SQL_CALC_FOUND_ROWS
|
||||
'.($this->_tmpTableFilter ? ' * FROM (SELECT ' : '').'
|
||||
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$select_shop.'
|
||||
FROM `'._DB_PREFIX_.$sql_table.'` a
|
||||
'.$lang_join.'
|
||||
'.(isset($this->_join) ? $this->_join.' ' : '').'
|
||||
'.$join_shop.'
|
||||
WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').
|
||||
(isset($this->_filter) ? $this->_filter : '').$where_shop.'
|
||||
'.(isset($this->_group) ? $this->_group.' ' : '').'
|
||||
'.$having_clause.'
|
||||
ORDER BY '.(($order_by == $this->identifier) ? 'a.' : '').pSQL($order_by).' '.pSQL($order_way).
|
||||
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').
|
||||
(($use_limit === true) ? ' LIMIT '.(int)$start.','.(int)$limit : '');
|
||||
|
||||
$this->_list = Db::getInstance()->executeS($sql);
|
||||
$this->_list = Db::getInstance()->executeS($this->_listsql);
|
||||
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
|
||||
}
|
||||
|
||||
|
||||
@@ -361,9 +361,10 @@ class HelperCore
|
||||
$context = Context::getContext();
|
||||
|
||||
// Get default value
|
||||
if (Shop::getContext() == Shop::CONTEXT_ALL)
|
||||
$shop_context = Shop::getContext();
|
||||
if ($shop_context == Shop::CONTEXT_ALL || ($context->controller->multishop_context_group == false && $shop_context == Shop::CONTEXT_GROUP))
|
||||
$value = '';
|
||||
else if (Shop::getContext() == Shop::CONTEXT_GROUP)
|
||||
else if ($shop_context == Shop::CONTEXT_GROUP)
|
||||
$value = 'g-'.Shop::getContextShopGroupID();
|
||||
else
|
||||
$value = 's-'.Shop::getContextShopID();
|
||||
@@ -376,9 +377,9 @@ class HelperCore
|
||||
foreach ($tree as $gID => $group_data)
|
||||
{
|
||||
if ((!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_GROUP))
|
||||
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').'>'.Translate::getAdminTranslation('Group:').' '.htmlspecialchars($group_data['name']).'</option>';
|
||||
$html .= '<option class="group" value="g-'.$gID.'" '.(($value == 'g-'.$gID) ? 'selected="selected"' : '').' '.($context->controller->multishop_context_group == false ? 'disabled="disabled"' : '').'>'.Translate::getAdminTranslation('Group:').' '.htmlspecialchars($group_data['name']).'</option>';
|
||||
else
|
||||
$html .= '<optgroup class="group" label="'.Translate::getAdminTranslation('Group:').' '.htmlspecialchars($group_data['name']).'">';
|
||||
$html .= '<optgroup class="group" label="'.Translate::getAdminTranslation('Group:').' '.htmlspecialchars($group_data['name']).'" '.($context->controller->multishop_context_group == false ? 'disabled="disabled"' : '').'>';
|
||||
|
||||
if (!isset($context->controller->multishop_context) || $context->controller->multishop_context & Shop::CONTEXT_SHOP)
|
||||
foreach ($group_data['shops'] as $sID => $shopData)
|
||||
|
||||
+20
-3
@@ -86,6 +86,7 @@ class ShopCore extends ObjectModel
|
||||
protected static $shops;
|
||||
|
||||
protected static $asso_tables = array();
|
||||
protected static $id_shop_default_tables = array();
|
||||
protected static $initialized = false;
|
||||
|
||||
protected $webserviceParameters = array(
|
||||
@@ -139,6 +140,7 @@ class ShopCore extends ObjectModel
|
||||
*/
|
||||
protected static function init()
|
||||
{
|
||||
Shop::$id_shop_default_tables = array('product', 'category');
|
||||
Shop::$asso_tables = array(
|
||||
'carrier' => array('type' => 'shop'),
|
||||
'carrier_lang' => array('type' => 'fk_shop'),
|
||||
@@ -503,6 +505,18 @@ class ShopCore extends ObjectModel
|
||||
Shop::init();
|
||||
return (isset(Shop::$asso_tables[$table]) ? Shop::$asso_tables[$table] : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the table has an id_shop_default
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function checkIdShopDefault($table)
|
||||
{
|
||||
if (!Shop::$initialized)
|
||||
Shop::init();
|
||||
return in_array($table, self::$id_shop_default_tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of associated tables to shop
|
||||
@@ -888,9 +902,12 @@ class ShopCore extends ObjectModel
|
||||
return;
|
||||
|
||||
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
|
||||
ON '.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table.'
|
||||
AND '.$table_alias.'.id_shop IN ('.implode(', ', Shop::getContextListShopID()).')
|
||||
'.(($on) ? ' AND '.$on : '');
|
||||
ON ('.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table;
|
||||
if ((int)self::$context_id_shop)
|
||||
$sql .= ' AND '.$table_alias.'.id_shop = '.(int)self::$context_id_shop;
|
||||
elseif (Shop::checkIdShopDefault($table))
|
||||
$sql .= ' AND '.$table_alias.'.id_shop = '.$alias.'.id_shop_default';
|
||||
$sql .= (($on) ? ' AND '.$on : '').')';
|
||||
return $sql;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user