Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed products update in 'All shops' context #4601

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions classes/ObjectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ protected function formatFields($type, $id_lang = null)
if ((!empty($data['lang']) || (!empty($data['shop']) && $data['shop'] != 'both')) && (empty($this->update_fields[$field]) || ($type == self::FORMAT_LANG && empty($this->update_fields[$field][$id_lang])))) {
continue;
}
if(!isset($this->update_fields[$field])) {
continue;
}
}

// Get field value, if value is multilang and field is empty, use value from default lang
Expand Down Expand Up @@ -673,7 +676,7 @@ public function update($null_values = false)
$where = $this->def['primary'].' = '.(int)$this->id.' AND id_shop = '.(int)$id_shop;

// A little explanation of what we do here : we want to create multishop entry when update is called, but
// only if we are in a shop context (if we are in all context, we just want to update entries that alread exists)
// only if we are in a shop context (if we are in all context, we just want to update entries that already exists)
$shop_exists = Db::getInstance()->getValue('SELECT '.$this->def['primary'].' FROM '._DB_PREFIX_.$this->def['table'].'_shop WHERE '.$where);
if ($shop_exists) {
$result &= Db::getInstance()->update($this->def['table'].'_shop', $fields, $where, 0, $null_values);
Expand Down Expand Up @@ -1589,7 +1592,7 @@ public function isLangMultishop()
}

/**
* Updates a table and splits the common datas and the shop datas.
* Updates a table and splits the common data and the shop data.
*
* @since 1.5.0.1
* @param string $classname
Expand Down Expand Up @@ -1630,6 +1633,7 @@ public static function updateMultishopTable($classname, $data, $where = '', $spe
SET '.implode(', ', $update_data).
(!empty($where) ? ' WHERE '.$where : '');


return Db::getInstance()->execute($sql);
}

Expand Down
4 changes: 4 additions & 0 deletions controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1985,18 +1985,22 @@ public function processUpdate()
}

$id = (int)Tools::getValue('id_'.$this->table);

/* Update an existing product */
if (isset($id) && !empty($id)) {
/** @var Product $object */
$object = new $this->className((int)$id);

$this->object = $object;

if (Validate::isLoadedObject($object)) {

$this->_removeTaxFromEcotax();
$product_type_before = $object->getType();
$this->copyFromPost($object, $this->table);
$object->indexed = 0;

/* if we are in "All shops" context, only update checked fields */
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
$object->setFieldsToUpdate((array)Tools::getValue('multishop_check', array()));
}
Expand Down