// Fix some bugs on multistore

This commit is contained in:
rMalie
2011-08-08 15:24:21 +00:00
parent 884a2f4a9e
commit 8537b83a14
3 changed files with 32 additions and 5 deletions
+2 -1
View File
@@ -293,7 +293,8 @@ class AdminProducts extends AdminTab
AND Pack::duplicate($id_product_old, $product->id)
AND Product::duplicateCustomizationFields($id_product_old, $product->id)
AND Product::duplicateTags($id_product_old, $product->id)
AND Product::duplicateDownload($id_product_old, $product->id))
AND Product::duplicateDownload($id_product_old, $product->id)
AND $product->duplicateShops($id_product_old))
{
if ($product->hasAttributes())
Product::updateDefaultAttribute($product->id);
+5 -3
View File
@@ -1299,7 +1299,9 @@ abstract class AdminTabCore
$this->_group = 'GROUP BY a.'.pSQL($this->identifier);
else if (!preg_match('#(\s|,)\s*a\.`?'.pSQL($this->identifier).'`?(\s|,|$)#', $this->_group))
$this->_group .= ', a.'.pSQL($this->identifier);
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))';
if (Shop::isMultiShopActivated() && Shop::context() == Shop::CONTEXT_ALL)
$filterShop = 'JOIN `'._DB_PREFIX_.$this->table.'_'.$filterKey.'` sa ON (sa.'.$this->identifier.' = a.'.$this->identifier.' AND sa.id_'.$filterKey.' IN ('.implode(', ', $idenfierShop).'))';
}
/* Query in order to get results with all fields */
@@ -1308,7 +1310,7 @@ abstract class AdminTabCore
'.($this->lang ? 'b.*, ' : '').'a.*'.(isset($this->_select) ? ', '.$this->_select.' ' : '').$selectShop.'
FROM `'._DB_PREFIX_.$sqlTable.'` a
'.$filterShop.'
'.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)($id_lang).($id_lang_shop ? ' AND b.`id_shop`='.(int)$id_lang_shop : '').')' : '').'
'.($this->lang ? 'LEFT JOIN `'._DB_PREFIX_.$this->table.'_lang` b ON (b.`'.$this->identifier.'` = a.`'.$this->identifier.'` AND b.`id_lang` = '.(int)$id_lang.($id_lang_shop ? ' AND b.`id_shop`='.(int)$id_lang_shop : '').')' : '').'
'.(isset($this->_join) ? $this->_join.' ' : '').'
'.$joinShop.'
WHERE 1 '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').(isset($this->_filter) ? $this->_filter : '').$whereShop.'
@@ -1316,7 +1318,7 @@ abstract class AdminTabCore
'.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').(isset($this->_having) ? $this->_having.' ' : '').'
ORDER BY '.(($orderBy == $this->identifier) ? 'a.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
($this->_tmpTableFilter ? ') tmpTable WHERE 1'.$this->_tmpTableFilter : '').'
LIMIT '.(int)($start).','.(int)($limit);
LIMIT '.(int)$start.','.(int)$limit;
$this->_list = Db::getInstance()->ExecuteS($sql);
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
+25 -1
View File
@@ -252,7 +252,7 @@ abstract class ObjectModelCore
if (!Shop::isMultishopActivated())
{
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'shop')
$result &= $this->associateTo(Context::getContext()->shop->getID(), 'shop');
$result &= $this->associateTo(Context::getContext()->shop->getID(true), 'shop');
$assos = GroupShop::getAssoTables();
if (isset($assos[$this->table]) && $assos[$this->table]['type'] == 'group_shop')
$result &= $this->associateTo(Context::getContext()->shop->getGroupID(), 'group_shop');
@@ -799,6 +799,7 @@ abstract class ObjectModelCore
return Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.$this->table.'_'.$context.'` (`'.$this->identifier.'`, `id_'.$context.'`) VALUES '.rtrim($sql,','));
return true;
}
/**
* Check if current object is associated to a group shop
*
@@ -817,6 +818,29 @@ abstract class ObjectModelCore
return (bool)Db::getInstance()->getValue($sql);
}
/**
* @since 1.5.0
*/
public function duplicateShops($id)
{
$asso = Shop::getAssoTables();
if (!isset($asso[$this->table]) || $asso[$this->table]['type'] != 'shop')
return false;
$sql = 'SELECT id_shop
FROM '._DB_PREFIX_.$this->table.'_shop
WHERE '.$this->identifier.' = '.(int)$id;
if ($results = Db::getInstance()->ExecuteS($sql))
{
$ids = array();
foreach ($results as $row)
$ids[] = $row['id_shop'];
return $this->associateTo($ids);
}
return false;
}
public function isLangMultishop()
{
return (int)$this->langMultiShop;