// Fix deprecated warning on product attribute create
This commit is contained in:
+17
-9
@@ -105,13 +105,13 @@ class CombinationCore extends ObjectModel
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setWsProductOptionValues($values)
|
||||
|
||||
public function setAttributes($ids_attribute)
|
||||
{
|
||||
if ($this->deleteAssociations())
|
||||
{
|
||||
$sqlValues = array();
|
||||
foreach ($values as $value)
|
||||
foreach ($ids_attribute as $value)
|
||||
$sqlValues[] = '('.(int)$value['id'].', '.(int)$this->id.')';
|
||||
$result = Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_attribute_combination` (`id_attribute`, `id_product_attribute`)
|
||||
@@ -121,6 +121,11 @@ class CombinationCore extends ObjectModel
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setWsProductOptionValues($values)
|
||||
{
|
||||
return $this->setAttributes($values);
|
||||
}
|
||||
|
||||
public function getWsProductOptionValues()
|
||||
{
|
||||
@@ -136,15 +141,15 @@ class CombinationCore extends ObjectModel
|
||||
WHERE `id_product_attribute` = '.(int)($this->id).'
|
||||
');
|
||||
}
|
||||
|
||||
public function setWsImages($values)
|
||||
|
||||
public function setImages($ids_image)
|
||||
{
|
||||
if (Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_image`
|
||||
WHERE `id_product_attribute` = '.(int)($this->id)) === false)
|
||||
return false;
|
||||
$sqlValues = array();
|
||||
foreach ($values as $value)
|
||||
foreach ($ids_image as $value)
|
||||
$sqlValues[] = '('.(int)$this->id.', '.(int)$value['id'].')';
|
||||
Db::getInstance()->execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`)
|
||||
@@ -152,6 +157,11 @@ class CombinationCore extends ObjectModel
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setWsImages($values)
|
||||
{
|
||||
return $this->setImages($values);
|
||||
}
|
||||
|
||||
public function getAttributesName($id_lang)
|
||||
{
|
||||
@@ -182,6 +192,4 @@ class CombinationCore extends ObjectModel
|
||||
{
|
||||
return parent::isCurrentlyUsed('product_attribute');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+63
-119
@@ -1006,30 +1006,8 @@ class ProductCore extends ObjectModel
|
||||
return false;
|
||||
|
||||
StockAvailable::setQuantity($this->id, $id_product_attribute, $quantity);
|
||||
|
||||
//Try to set the default supplier reference
|
||||
if ($this->id_supplier > 0 && $supplier_reference != null)
|
||||
{
|
||||
$id_product_supplier = ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $this->id_supplier);
|
||||
|
||||
if (empty($id_product_supplier))
|
||||
{
|
||||
//create new record
|
||||
$product_supplier_entity = new ProductSupplier();
|
||||
$product_supplier_entity->id_product = $this->id;
|
||||
$product_supplier_entity->id_product_attribute = $id_product_attribute;
|
||||
$product_supplier_entity->id_supplier = $this->id_supplier;
|
||||
$product_supplier_entity->product_supplier_reference = pSQL($supplier_reference);
|
||||
$product_supplier_entity->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$product_supplier = new ProductSupplier($id_product_supplier);
|
||||
$product_supplier->product_supplier_reference = pSql($supplier_reference);
|
||||
$product_supplier->update();
|
||||
}
|
||||
}
|
||||
|
||||
$this->addSupplierReference($supplier_reference, $id_product_attribute);
|
||||
return $id_product_attribute;
|
||||
}
|
||||
|
||||
@@ -1056,37 +1034,31 @@ class ProductCore extends ObjectModel
|
||||
|
||||
$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();
|
||||
|
||||
Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', array(
|
||||
'id_product' => (int)$this->id,
|
||||
'price' => (float)$price,
|
||||
'ecotax' => (float)$ecotax,
|
||||
'quantity' => 0,
|
||||
'weight' => ($weight ? (float)$weight : 0),
|
||||
'unit_price_impact' => ($unit_impact ? (float)$unit_impact : 0),
|
||||
'reference' => pSQL($reference),
|
||||
'location' => pSQL($location),
|
||||
'ean13' => pSQL($ean13),
|
||||
'upc' => pSQL($upc),
|
||||
'default_on' => (int)$default,
|
||||
'minimal_quantity' => (int)$minimal_quantity,
|
||||
), 'INSERT');
|
||||
|
||||
$id_product_attribute = Db::getInstance()->Insert_ID();
|
||||
|
||||
if (!$combination->id)
|
||||
return false;
|
||||
|
||||
Product::updateDefaultAttribute($this->id);
|
||||
if (!$id_product_attribute)
|
||||
return false;
|
||||
|
||||
if (!empty($id_images))
|
||||
$combination->setImages($id_images);
|
||||
|
||||
if (empty($id_images))
|
||||
return (int)$id_product_attribute;
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES ';
|
||||
foreach ($id_images as $id_image)
|
||||
$query .= '('.(int)$id_product_attribute.', '.(int)$id_image.'), ';
|
||||
$query = trim($query, ', ');
|
||||
if (!Db::getInstance()->execute($query))
|
||||
return false;
|
||||
return (int)$id_product_attribute;
|
||||
return (int)$combination->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1096,11 +1068,12 @@ class ProductCore extends ObjectModel
|
||||
public function addCombinationEntity($wholesale_price, $price, $weight, $unit_impact, $ecotax, $quantity,
|
||||
$id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1)
|
||||
{
|
||||
$id_product_attribute = $this->addProductAttribute(
|
||||
$price, $weight, $unit_impact, $ecotax, $quantity, $id_images,
|
||||
$reference, $supplier_reference, $ean13, $default, $location, $upc, $minimal_quantity
|
||||
);
|
||||
|
||||
$id_product_attribute = $this->addAttribute(
|
||||
$price, $weight, $unit_impact, $ecotax, 0, $id_images,
|
||||
$reference, $ean13, $default, $location, $upc, $minimal_quantity);
|
||||
|
||||
$this->addSupplierReference($supplier_reference, $id_product_attribute);
|
||||
|
||||
$result = Db::getInstance()->execute(
|
||||
'UPDATE `'._DB_PREFIX_.'product_attribute`
|
||||
SET `wholesale_price` = '.(float)$wholesale_price.'
|
||||
@@ -1203,7 +1176,12 @@ class ProductCore extends ObjectModel
|
||||
$id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax,
|
||||
$id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date
|
||||
);
|
||||
|
||||
$this->addSupplierReference($supplier_reference, $id_product_attribute);
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function addSupplierReference($supplier_reference, $id_product_attribute = null, $id_currency = null)
|
||||
{
|
||||
//Try to set the default supplier reference
|
||||
if ($this->id_supplier > 0 && $supplier_reference != null)
|
||||
{
|
||||
@@ -1213,16 +1191,17 @@ class ProductCore extends ObjectModel
|
||||
{
|
||||
//create new record
|
||||
$product_supplier_entity = new ProductSupplier();
|
||||
$product_supplier_entity->id_product = $this->id;
|
||||
$product_supplier_entity->id_product_attribute = $id_product_attribute;
|
||||
$product_supplier_entity->id_supplier = $this->id_supplier;
|
||||
$product_supplier_entity->id_product = (int)$this->id;
|
||||
$product_supplier_entity->id_product_attribute = (int)$id_product_attribute;
|
||||
$product_supplier_entity->id_supplier = (int)$this->id_supplier;
|
||||
$product_supplier_entity->product_supplier_reference = pSQL($supplier_reference);
|
||||
$product_supplier_entity->id_currency = (int)$id_currency;
|
||||
$product_supplier_entity->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$product_supplier = new ProductSupplier($id_product_supplier);
|
||||
$product_supplier->product_supplier_reference = pSql($supplier_reference);
|
||||
$product_supplier = new ProductSupplier((int)$id_product_supplier);
|
||||
$product_supplier->product_supplier_reference = pSQL($supplier_reference);
|
||||
$product_supplier->update();
|
||||
}
|
||||
}
|
||||
@@ -1248,57 +1227,33 @@ class ProductCore extends ObjectModel
|
||||
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)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute);
|
||||
|
||||
$price = str_replace(',', '.', $price);
|
||||
$weight = str_replace(',', '.', $weight);
|
||||
$data = array(
|
||||
'wholesale_price' => (float)$wholesale_price,
|
||||
'price' => (float)$price,
|
||||
'ecotax' => (float)$ecotax,
|
||||
'weight' => ($weight ? (float)$weight : 0),
|
||||
'unit_price_impact' => ($unit ? (float)$unit : 0),
|
||||
'reference' => pSQL($reference),
|
||||
'location' => pSQL($location),
|
||||
'ean13' => pSQL($ean13),
|
||||
'upc' => pSQL($upc),
|
||||
'default_on' => (int)$default,
|
||||
'minimal_quantity' => (int)$minimal_quantity,
|
||||
'available_date' => pSQL($available_date)
|
||||
);
|
||||
|
||||
$res1 = Db::getInstance()->AutoExecute(
|
||||
_DB_PREFIX_.'product_attribute',
|
||||
$data,
|
||||
'UPDATE',
|
||||
'`id_product_attribute` = '.(int)$id_product_attribute
|
||||
);
|
||||
|
||||
$res2 = Db::getInstance()->execute(
|
||||
'DELETE FROM `'._DB_PREFIX_.'product_attribute_image`
|
||||
WHERE `id_product_attribute` = '.(int)$id_product_attribute
|
||||
);
|
||||
|
||||
if (!$res1 || !$res2)
|
||||
return false;
|
||||
|
||||
//if ($quantity)
|
||||
Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
|
||||
$combination = new Combination((int)$id_product_attribute);
|
||||
$combination->price = (float)$price;
|
||||
$combination->wholesale_price = (float)$wholesale_price;
|
||||
$combination->ecotax = (float)$ecotax;
|
||||
$combination->weight = (float)$weight;
|
||||
$combination->unit_price_impact = (float)$unit;
|
||||
$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->available_date = pSQL($available_date);
|
||||
$combination->save();
|
||||
|
||||
if (!empty($id_images))
|
||||
$combination->setImages($id_images);
|
||||
|
||||
Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
|
||||
|
||||
Product::updateDefaultAttribute($this->id);
|
||||
|
||||
if (empty($id_images))
|
||||
return true;
|
||||
|
||||
$query = 'INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES ';
|
||||
|
||||
foreach ($id_images as $id_image)
|
||||
$query .= '('.(int)$id_product_attribute.', '.(int)$id_image.'), ';
|
||||
$query = trim($query, ', ');
|
||||
|
||||
return Db::getInstance()->execute($query);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1482,20 +1437,9 @@ class ProductCore extends ObjectModel
|
||||
die(Tools::displayError());
|
||||
if (!count($attributes))
|
||||
return false;
|
||||
$attributes_list = '';
|
||||
foreach ($attributes as $id_attribute)
|
||||
$attributes_list .= '('.(int)$id_product_attribute.','.(int)$id_attribute.'),';
|
||||
$attributes_list = rtrim($attributes_list, ',');
|
||||
|
||||
if (!Validate::isValuesList($attributes_list))
|
||||
die(Tools::displayError());
|
||||
|
||||
$result = Db::getInstance()->execute(
|
||||
'INSERT INTO `'._DB_PREFIX_.'product_attribute_combination` (`id_product_attribute`, `id_attribute`)
|
||||
VALUES '.$attributes_list
|
||||
);
|
||||
|
||||
return $result;
|
||||
$combination = new Combination((int)$id_product_attribute);
|
||||
return $combination->setAttributes($attributes);
|
||||
}
|
||||
|
||||
public function addAttributeCombinationMultiple($id_attributes, $combinations)
|
||||
|
||||
@@ -738,9 +738,10 @@ class WebserviceRequestCore
|
||||
{
|
||||
$sql = 'SELECT 1
|
||||
FROM '._DB_PREFIX_.'webservice_account wsa LEFT JOIN '._DB_PREFIX_.'webservice_account_shop wsas ON (wsa.id_webservice_account = wsas.id_webservice_account)
|
||||
WHERE wsa.key = \''.$key.'\'';
|
||||
WHERE wsa.key = \''.pSQL($key).'\'';
|
||||
|
||||
foreach (self::$shopIDs as $id_shop)
|
||||
$OR[] = ' wsas.id_shop = '.$id_shop.' ';
|
||||
$OR[] = ' wsas.id_shop = '.(int)$id_shop.' ';
|
||||
$sql .= ' AND ('.implode('OR', $OR).') ';
|
||||
if (!Db::getInstance()->getValue($sql))
|
||||
{
|
||||
|
||||
@@ -636,7 +636,8 @@ class AdminProductsControllerCore extends AdminController
|
||||
}
|
||||
if (!count($this->_errors))
|
||||
{
|
||||
$product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list'));
|
||||
$combination = new Combination((int)$id_product_attribute);
|
||||
$combination->setAttributes(Tools::getValue('attribute_combinaison_list'));
|
||||
$product->checkDefaultAttributes();
|
||||
}
|
||||
if (!count($this->_errors))
|
||||
@@ -2324,52 +2325,26 @@ class AdminProductsControllerCore extends AdminController
|
||||
$existing_id = (int)ProductSupplier::getIdByProductAndSupplier($product->id, $attribute['id_product_attribute'], $supplier->id_supplier);
|
||||
if ($existing_id <= 0)
|
||||
{
|
||||
//create new record
|
||||
$product_supplier_entity = new ProductSupplier();
|
||||
$product_supplier_entity->id_product = $product->id;
|
||||
$product_supplier_entity->id_product_attribute = $attribute['id_product_attribute'];
|
||||
$product_supplier_entity->id_supplier = (int)$supplier->id_supplier;
|
||||
$product_supplier_entity->product_supplier_reference = $reference;
|
||||
$product_supplier_entity->id_currency = $id_currency;
|
||||
$product_supplier_entity->product_supplier_price_te = $price;
|
||||
$product_supplier_entity->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
//update existing record
|
||||
$product_supplier_entity = new ProductSupplier($existing_id);
|
||||
|
||||
if (($product_supplier_entity->product_supplier_reference != $reference)
|
||||
||
|
||||
($product_supplier_entity->product_supplier_price_te != $price)
|
||||
||
|
||||
($product_supplier_entity->id_currency != $id_currency))
|
||||
$product->addSupplierReference($reference, (int)$attribute['id_product_attribute'], (int)$id_currency);
|
||||
if ($product->id_supplier == $supplier->id_supplier)
|
||||
{
|
||||
$product_supplier_entity->product_supplier_reference = $reference;
|
||||
$product_supplier_entity->id_currency = $id_currency;
|
||||
$product_supplier_entity->product_supplier_price_te = $price;
|
||||
$product_supplier_entity->update();
|
||||
}
|
||||
}
|
||||
|
||||
if ($product->id_supplier == $supplier->id_supplier)
|
||||
{
|
||||
if ((int)$attribute['id_product_attribute'] > 0)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE '._DB_PREFIX_.'product_attribute
|
||||
SET supplier_reference = "'.$reference.'",
|
||||
wholesale_price = '.(float)Tools::convertPrice($price, $id_currency).'
|
||||
WHERE id_product = '.(int)$product->id.'
|
||||
AND id_product_attribute = '.(int)$attribute['id_product_attribute'].'
|
||||
LIMIT 1
|
||||
');
|
||||
}
|
||||
else
|
||||
{
|
||||
$product->wholesale_price = Tools::convertPrice($price, $id_currency); //converted in the default currency
|
||||
$product->supplier_reference = $reference;
|
||||
$update_product = true;
|
||||
if ((int)$attribute['id_product_attribute'] > 0)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE '._DB_PREFIX_.'product_attribute
|
||||
SET supplier_reference = "'.pSQL($reference).'",
|
||||
wholesale_price = '.(float)Tools::convertPrice($price, $id_currency).'
|
||||
WHERE id_product = '.(int)$product->id.'
|
||||
AND id_product_attribute = '.(int)$attribute['id_product_attribute'].'
|
||||
LIMIT 1
|
||||
');
|
||||
}
|
||||
else
|
||||
{
|
||||
$product->wholesale_price = Tools::convertPrice($price, $id_currency); //converted in the default currency
|
||||
$product->supplier_reference = $reference;
|
||||
$update_product = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user