// Fix ObjectModel::updateMultishopTable() for Combination

This commit is contained in:
rMalie
2012-04-17 15:45:47 +00:00
parent 8f9df76397
commit 55da95aad3
+11 -13
View File
@@ -1129,12 +1129,13 @@ abstract class ObjectModelCore
* @param string $classname * @param string $classname
* @param array $data * @param array $data
* @param string $where * @param string $where
* @param string $specific_where Only executed for common table
* @return bool * @return bool
*/ */
public static function updateMultishopTable($classname, $data, $where) public static function updateMultishopTable($classname, $data, $where, $specific_where = '')
{ {
$def = ObjectModel::getDefinition($classname); $def = ObjectModel::getDefinition($classname);
$common_data = $shop_data = array(); $update_data = array();
$is_default_shop = Context::getContext()->shop->id == Configuration::get('PS_SHOP_DEFAULT'); $is_default_shop = Context::getContext()->shop->id == Configuration::get('PS_SHOP_DEFAULT');
foreach ($data as $field => $value) foreach ($data as $field => $value)
{ {
@@ -1144,21 +1145,18 @@ abstract class ObjectModelCore
if (!empty($def['fields'][$field]['shop'])) if (!empty($def['fields'][$field]['shop']))
{ {
if ($is_default_shop) if ($is_default_shop)
$common_data[$field] = $value; $update_data[] = "a.$field = '$value'";
$shop_data[$field] = $value; $update_data[] = "{$def['table']}_shop.$field = '$value'";
} }
else else
$common_data[$field] = $value; $update_data[] = "a.$field = '$value'";
} }
$result = true; $sql = 'UPDATE '._DB_PREFIX_.$def['table'].' a
if ($common_data) '.Shop::addSqlAssociation($def['table'], 'a').'
$result &= Db::getInstance()->update($def['table'], $common_data, $where); SET '.implode(', ', $update_data).'
WHERE '.$where;
if ($shop_data) return Db::getInstance()->execute($sql);
$result &= Db::getInstance()->update($def['table'].'_shop', $shop_data, $where.' AND id_shop = '.(int)Context::getContext()->shop->id);
return $result;
} }
/** /**