Merge pull request #630 from rimas-kudelis/development
[*] CORE :ProductCore::addSupplierReference() if a reference already exists update it
This commit is contained in:
commit
1b93d251aa
1 file changed
+13
-18
+13
-18
@@ -1339,7 +1339,7 @@ class ProductCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Supplier Reference
|
* Sets or updates Supplier Reference
|
||||||
*
|
*
|
||||||
* @param int $id_supplier
|
* @param int $id_supplier
|
||||||
* @param int $id_product_attribute
|
* @param int $id_product_attribute
|
||||||
@@ -1352,30 +1352,25 @@ class ProductCore extends ObjectModel
|
|||||||
//in some case we need to add price without supplier reference
|
//in some case we need to add price without supplier reference
|
||||||
if ($supplier_reference === null)
|
if ($supplier_reference === null)
|
||||||
$supplier_reference = '';
|
$supplier_reference = '';
|
||||||
|
|
||||||
//Try to set the default supplier reference
|
//Try to set the default supplier reference
|
||||||
if ($id_supplier > 0)
|
if (($id_supplier > 0) && ($id_product > 0))
|
||||||
{
|
{
|
||||||
$id_product_supplier = (int)ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $id_supplier);
|
$id_product_supplier = (int)ProductSupplier::getIdByProductAndSupplier($this->id, $id_product_attribute, $id_supplier);
|
||||||
|
|
||||||
|
$product_supplier = new ProductSupplier($id_product_supplier);
|
||||||
|
|
||||||
if (!$id_product_supplier)
|
if (!$id_product_supplier)
|
||||||
{
|
{
|
||||||
//create new record
|
$product_supplier->id_product = (int)$this->id;
|
||||||
$product_supplier_entity = new ProductSupplier();
|
$product_supplier->id_product_attribute = (int)$id_product_attribute;
|
||||||
$product_supplier_entity->id_product = (int)$this->id;
|
$product_supplier->id_supplier = (int)$id_supplier;
|
||||||
$product_supplier_entity->id_product_attribute = (int)$id_product_attribute;
|
|
||||||
$product_supplier_entity->id_supplier = (int)$id_supplier;
|
|
||||||
$product_supplier_entity->product_supplier_reference = pSQL($supplier_reference);
|
|
||||||
$product_supplier_entity->product_supplier_price_te = (float)$price;
|
|
||||||
$product_supplier_entity->id_currency = (int)$id_currency;
|
|
||||||
$product_supplier_entity->save();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$product_supplier = new ProductSupplier((int)$id_product_supplier);
|
|
||||||
$product_supplier->product_supplier_reference = pSQL($supplier_reference);
|
|
||||||
$product_supplier->update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$product_supplier->product_supplier_reference = pSQL($supplier_reference);
|
||||||
|
$product_supplier->product_supplier_price_te = (float)$price;
|
||||||
|
$product_supplier->id_currency = (int)$id_currency;
|
||||||
|
$product_supplier->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user