[-] BO : Bug fixed #PSCFV-1975 - Combination import + multishop
This commit is contained in:
+34
-9
@@ -59,6 +59,8 @@ abstract class ObjectModelCore
|
||||
|
||||
protected $id_shop = null;
|
||||
|
||||
public $id_shop_list = null;
|
||||
|
||||
protected $get_shop_from_context = true;
|
||||
|
||||
protected static $fieldsRequiredDatabase = null;
|
||||
@@ -445,8 +447,17 @@ abstract class ObjectModelCore
|
||||
{
|
||||
$fields = $this->getFieldsShop();
|
||||
$fields[$this->def['primary']] = (int)$this->id;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
$result &= Db::getInstance()->insert($this->def['table'].'_shop', $fields, $null_values);
|
||||
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
foreach ($id_shop_list as $id_shop)
|
||||
{
|
||||
$fields['id_shop'] = (int)$id_shop;
|
||||
$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);
|
||||
@@ -527,10 +538,15 @@ abstract class ObjectModelCore
|
||||
else
|
||||
$all_fields = $fields;
|
||||
|
||||
foreach (Shop::getContextListShopID() as $id_shop)
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list) > 0)
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
foreach ($id_shop_list as $id_shop)
|
||||
{
|
||||
$fields['id_shop'] = $id_shop;
|
||||
$all_fields['id_shop'] = $id_shop;
|
||||
$fields['id_shop'] = (int)$id_shop;
|
||||
$all_fields['id_shop'] = (int)$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);
|
||||
@@ -554,10 +570,13 @@ abstract class ObjectModelCore
|
||||
// If this table is linked to multishop system, update / insert for all shops from context
|
||||
if ($this->isLangMultishop())
|
||||
{
|
||||
$list_shops = ($this->id_shop && !$this->get_shop_from_context) ? array($this->id_shop) : Shop::getContextListShopID();
|
||||
foreach ($list_shops as $shop)
|
||||
$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)
|
||||
{
|
||||
$field['id_shop'] = $shop;
|
||||
$field['id_shop'] = (int)$id_shop;
|
||||
$where = pSQL($this->def['primary']).' = '.(int)$this->id
|
||||
.' AND id_lang = '.(int)$field['id_lang']
|
||||
.' AND id_shop = '.$field['id_shop'];
|
||||
@@ -605,7 +624,13 @@ abstract class ObjectModelCore
|
||||
|
||||
// Remove association to multishop table
|
||||
if (!empty($this->def['multishop']))
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id.' AND id_shop IN ('.implode(', ', Shop::getContextListShopID()).')');
|
||||
{
|
||||
$id_shop_list = Shop::getContextListShopID();
|
||||
if (count($this->id_shop_list))
|
||||
$id_shop_list = $this->id_shop_list;
|
||||
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id.' AND id_shop IN ('.implode(', ', $id_shop_list).')');
|
||||
}
|
||||
else if (Shop::isTableAssociated($this->def['table']))
|
||||
$result &= Db::getInstance()->delete($this->def['table'].'_shop', '`'.$this->def['primary'].'`='.(int)$this->id);
|
||||
|
||||
|
||||
+60
-51
@@ -1047,56 +1047,6 @@ class ProductCore extends ObjectModel
|
||||
return $id_product_attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a product attribute
|
||||
* @since 1.5.0.1
|
||||
*
|
||||
* @param float $price Additional price
|
||||
* @param float $weight Additional weight
|
||||
* @param float $ecotax Additional ecotax
|
||||
* @param integer $id_images Image ids
|
||||
* @param string $reference Reference
|
||||
* @param string $location Location
|
||||
* @param string $ean13 Ean-13 barcode
|
||||
* @param boolean $default Is default attribute for product
|
||||
* @param integer $minimal_quantity Minimal quantity to add to cart
|
||||
* @return mixed $id_product_attribute or false
|
||||
*/
|
||||
public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13,
|
||||
$default, $location = null, $upc = null, $minimal_quantity = 1)
|
||||
{
|
||||
if (!$this->id)
|
||||
return;
|
||||
|
||||
$price = str_replace(',', '.', $price);
|
||||
$weight = str_replace(',', '.', $weight);
|
||||
|
||||
$combination = new Combination();
|
||||
$combination->id_product = (int)$this->id;
|
||||
$combination->price = (float)$price;
|
||||
$combination->ecotax = (float)$ecotax;
|
||||
$combination->quantity = 0;
|
||||
$combination->weight = (float)$weight;
|
||||
$combination->unit_price_impact = (float)$unit_impact;
|
||||
$combination->reference = pSQL($reference);
|
||||
$combination->location = pSQL($location);
|
||||
$combination->ean13 = pSQL($ean13);
|
||||
$combination->upc = pSQL($upc);
|
||||
$combination->default_on = (int)$default;
|
||||
$combination->minimal_quantity = (int)$minimal_quantity;
|
||||
$combination->add();
|
||||
|
||||
if (!$combination->id)
|
||||
return false;
|
||||
|
||||
Product::updateDefaultAttribute($this->id);
|
||||
|
||||
if (!empty($id_images))
|
||||
$combination->setImages($id_images);
|
||||
|
||||
return (int)$combination->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $quantity DEPRECATED
|
||||
* @param string $supplier_reference DEPRECATED
|
||||
@@ -1241,7 +1191,7 @@ 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 = null, $available_date = null, $update_all_fields = true)
|
||||
$id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = null, $available_date = null, $update_all_fields = true, array $id_shop_list = array())
|
||||
{
|
||||
$combination = new Combination($id_product_attribute);
|
||||
|
||||
@@ -1273,6 +1223,9 @@ class ProductCore extends ObjectModel
|
||||
$combination->minimal_quantity = (int)$minimal_quantity;
|
||||
$combination->available_date = $available_date ? pSQL($available_date) : '0000-00-00';
|
||||
|
||||
if (count($id_shop_list))
|
||||
$combination->id_shop_list = $id_shop_list;
|
||||
|
||||
$combination->save();
|
||||
|
||||
if (!empty($id_images))
|
||||
@@ -1285,6 +1238,61 @@ class ProductCore extends ObjectModel
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a product attribute
|
||||
* @since 1.5.0.1
|
||||
*
|
||||
* @param float $price Additional price
|
||||
* @param float $weight Additional weight
|
||||
* @param float $ecotax Additional ecotax
|
||||
* @param integer $id_images Image ids
|
||||
* @param string $reference Reference
|
||||
* @param string $location Location
|
||||
* @param string $ean13 Ean-13 barcode
|
||||
* @param boolean $default Is default attribute for product
|
||||
* @param integer $minimal_quantity Minimal quantity to add to cart
|
||||
* @return mixed $id_product_attribute or false
|
||||
*/
|
||||
public function addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13,
|
||||
$default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array())
|
||||
{
|
||||
if (!$this->id)
|
||||
return;
|
||||
|
||||
$price = str_replace(',', '.', $price);
|
||||
$weight = str_replace(',', '.', $weight);
|
||||
|
||||
$combination = new Combination();
|
||||
$combination->id_product = (int)$this->id;
|
||||
$combination->price = (float)$price;
|
||||
$combination->ecotax = (float)$ecotax;
|
||||
$combination->quantity = 0;
|
||||
$combination->weight = (float)$weight;
|
||||
$combination->unit_price_impact = (float)$unit_impact;
|
||||
$combination->reference = pSQL($reference);
|
||||
$combination->location = pSQL($location);
|
||||
$combination->ean13 = pSQL($ean13);
|
||||
$combination->upc = pSQL($upc);
|
||||
$combination->default_on = (int)$default;
|
||||
$combination->minimal_quantity = (int)$minimal_quantity;
|
||||
|
||||
if (count($id_shop_list))
|
||||
$combination->id_shop_list = $id_shop_list;
|
||||
|
||||
$combination->add();
|
||||
|
||||
if (!$combination->id)
|
||||
return false;
|
||||
|
||||
Product::updateDefaultAttribute($this->id);
|
||||
|
||||
if (!empty($id_images))
|
||||
$combination->setImages($id_images);
|
||||
|
||||
return (int)$combination->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated since 1.5.0
|
||||
*/
|
||||
@@ -4862,3 +4870,4 @@ class ProductCore extends ObjectModel
|
||||
return Product::PTYPE_SIMPLE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,10 @@ class AdminImportControllerCore extends AdminController
|
||||
'delete_existing_images' => array(
|
||||
'label' => $this->l('Delete existing images (0 = No, 1 = Yes)')
|
||||
),
|
||||
'shop' => array(
|
||||
'label' => $this->l('ID / Name of shop'),
|
||||
'help' => $this->l('Ignore this field if you don\'t use the multishop tool. If you leave this field empty, default shop will be used'),
|
||||
),
|
||||
);
|
||||
|
||||
self::$default_values = array(
|
||||
@@ -146,7 +150,8 @@ class AdminImportControllerCore extends AdminController
|
||||
'ecotax' => 0,
|
||||
'quantity' => 0,
|
||||
'weight' => 0,
|
||||
'default_on' => 0
|
||||
'default_on' => 0,
|
||||
'shop' => Configuration::get('PS_SHOP_DEFAULT'),
|
||||
);
|
||||
break;
|
||||
|
||||
@@ -1499,6 +1504,14 @@ class AdminImportControllerCore extends AdminController
|
||||
$this->errors[] = ($field_error !== true ? $field_error : '').($lang_field_error !== true ? $lang_field_error : '');
|
||||
}
|
||||
|
||||
$info['shop'] = explode(',', $info['shop']);
|
||||
$id_shop_list = array();
|
||||
foreach ($info['shop'] as $shop)
|
||||
if (!is_numeric($shop))
|
||||
$id_shop_list[] = Shop::getIdByName($shop);
|
||||
else
|
||||
$id_shop_list[] = $shop;
|
||||
|
||||
// if a reference is specified for this product, get the associate id_product_attribute to UPDATE
|
||||
if (isset($info['reference']) && !empty($info['reference']))
|
||||
{
|
||||
@@ -1527,7 +1540,9 @@ class AdminImportControllerCore extends AdminController
|
||||
0,
|
||||
strval($info['upc']),
|
||||
(int)$info['quantity'],
|
||||
0
|
||||
0,
|
||||
null,
|
||||
$id_shop_list
|
||||
);
|
||||
|
||||
$id_product_attribute_update = true;
|
||||
@@ -1550,7 +1565,8 @@ class AdminImportControllerCore extends AdminController
|
||||
(int)$info['default_on'],
|
||||
0,
|
||||
strval($info['upc']),
|
||||
(int)$info['quantity']
|
||||
(int)$info['quantity'],
|
||||
$id_shop_list
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2406,3 +2422,4 @@ class AdminImportControllerCore extends AdminController
|
||||
$this->warnings[] = $product_name.(isset($product_id) ? ' (ID '.$product_id.')' : '').' '.Tools::displayError($message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user