// Combination multishop

This commit is contained in:
rMalie
2012-04-20 10:01:05 +00:00
parent f5fc3769a9
commit 84d1e57ad9
12 changed files with 213 additions and 138 deletions
+1 -1
View File
@@ -70,7 +70,6 @@ class CombinationCore extends ObjectModel
'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13),
'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12),
'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'size' => 10),
'weight' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'),
'reference' => array('type' => self::TYPE_STRING, 'size' => 32),
'supplier_reference' => array('type' => self::TYPE_STRING, 'size' => 32),
@@ -78,6 +77,7 @@ class CombinationCore extends ObjectModel
'wholesale_price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 27),
'price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isNegativePrice', 'size' => 20),
'ecotax' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),
'weight' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isFloat'),
'unit_price_impact' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),
'minimal_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId', 'required' => true),
'default_on' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isBool'),
+19 -19
View File
@@ -339,8 +339,9 @@ abstract class ObjectModelCore
|| ($type == self::FORMAT_COMMON && (!empty($data['shop']) || !empty($data['lang']))))
continue;
if (is_array($this->update_fields) && (empty($this->update_fields[$field]) || ($type == self::FORMAT_LANG && empty($this->update_fields[$field][$id_lang]))))
continue;
if (is_array($this->update_fields))
if ((!empty($data['lang']) || !empty($data['shop'])) && (empty($this->update_fields[$field]) || ($type == self::FORMAT_LANG && empty($this->update_fields[$field][$id_lang]))))
continue;
// Get field value, if value is multilang and field is empty, use value from default lang
$value = $this->$field;
@@ -433,12 +434,7 @@ abstract class ObjectModelCore
$this->date_upd = date('Y-m-d H:i:s');
// Database insertion
if ($null_values)
$result = Db::getInstance()->insert($this->def['table'], $this->getFields(), true);
else
$result = Db::getInstance()->insert($this->def['table'], $this->getFields());
if (!$result)
if (!$result = Db::getInstance()->insert($this->def['table'], $this->getFields(), $null_values))
return false;
// Get object id in database
@@ -450,10 +446,7 @@ abstract class ObjectModelCore
$fields = $this->getFieldsShop();
$fields[$this->def['primary']] = (int)$this->id;
$fields['id_shop'] = (int)$this->id_shop;
if ($null_values)
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, true);
else
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields);
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, $null_values);
}
else if (!Shop::isFeatureActive() && Shop::isTableAssociated($this->def['table']))
$result &= $this->associateTo(Context::getContext()->shop->id);
@@ -515,12 +508,7 @@ abstract class ObjectModelCore
$this->date_upd = date('Y-m-d H:i:s');
// Database update
if ($null_values)
$result = Db::getInstance()->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id, 0, true);
else
$result = Db::getInstance()->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id);
if (!$result)
if (!$result = Db::getInstance()->update($this->def['table'], $this->getFields(), '`'.pSQL($this->def['primary']).'` = '.(int)$this->id, 0, $null_values))
return false;
// Database insertion for multishop fields related to the object
@@ -528,14 +516,26 @@ abstract class ObjectModelCore
{
$fields = $this->getFieldsShop();
$fields[$this->def['primary']] = (int)$this->id;
if (is_array($this->update_fields))
{
$update_fields = $this->update_fields;
$this->update_fields = null;
$all_fields = $this->getFieldsShop();
$all_fields[$this->def['primary']] = (int)$this->id;
$this->update_fields = $update_fields;
}
else
$all_fields = $fields;
foreach (Shop::getContextListShopID() as $id_shop)
{
$fields['id_shop'] = $id_shop;
$all_fields['id_shop'] = $id_shop;
$where = $this->def['primary'].' = '.(int)$this->id.' AND id_shop = '.(int)$id_shop;
if (Db::getInstance()->getValue('SELECT '.$this->def['primary'].' FROM '._DB_PREFIX_.$this->def['table'].'_shop WHERE '.$where))
$result &= Db::getInstance()->update($this->def['table'].'_shop', $fields, $where, 0, $null_values);
else
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, $null_values);
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $all_fields, $null_values);
}
}
+17 -3
View File
@@ -1231,12 +1231,25 @@ class ProductCore extends ObjectModel
* @return array Update result
*/
public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
$id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date)
$id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true)
{
$combination = new Combination($id_product_attribute);
if (!$update_all_fields)
$combination->setFieldsToUpdate(array(
'price' => !is_null($price),
'wholesale_price' => !is_null($wholesale_price),
'ecotax' => !is_null($ecotax),
'weight' => !is_null($weight),
'unit_price_impact' => !is_null($unit),
'default_on' => !is_null($ecotax),
'minimal_quantity' => !is_null($minimal_quantity),
'available_date' => !is_null($available_date),
));
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$combination = new Combination($id_product_attribute);
$combination->price = (float)$price;
$combination->wholesale_price = (float)$wholesale_price;
$combination->ecotax = (float)$ecotax;
@@ -1248,7 +1261,8 @@ class ProductCore extends ObjectModel
$combination->upc = pSQL($upc);
$combination->default_on = (int)$default;
$combination->minimal_quantity = (int)$minimal_quantity;
$combination->available_date = pSQL($available_date);
$combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00';
$combination->save();
if (!empty($id_images))