Merge pull request #12135 from c3do/patch-1
NEW Can update product type with update method
This commit is contained in:
commit
c69e934f9c
@ -247,7 +247,12 @@ class Products extends DolibarrApi
|
|||||||
$this->product->$field = $value;
|
$this->product->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->product->update($id, DolibarrApiAccess::$user, 1, 'update');
|
$updatetype = false;
|
||||||
|
if ($this->product->type != $oldproduct->type && ($this->product->isProduct() || $this->product->isService())) {
|
||||||
|
$updatetype = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->product->update($id, DolibarrApiAccess::$user, 1, 'update', $updatetype);
|
||||||
|
|
||||||
// If price mode is 1 price per product
|
// If price mode is 1 price per product
|
||||||
if ($result > 0 && ! empty($conf->global->PRODUCT_PRICE_UNIQ)) {
|
if ($result > 0 && ! empty($conf->global->PRODUCT_PRICE_UNIQ)) {
|
||||||
|
|||||||
@ -787,13 +787,14 @@ class Product extends CommonObject
|
|||||||
* Update a record into database.
|
* Update a record into database.
|
||||||
* If batch flag is set to on, we create records into llx_product_batch
|
* If batch flag is set to on, we create records into llx_product_batch
|
||||||
*
|
*
|
||||||
* @param int $id Id of product
|
* @param int $id Id of product
|
||||||
* @param User $user Object user making update
|
* @param User $user Object user making update
|
||||||
* @param int $notrigger Disable triggers
|
* @param int $notrigger Disable triggers
|
||||||
* @param string $action Current action for hookmanager ('add' or 'update')
|
* @param string $action Current action for hookmanager ('add' or 'update')
|
||||||
* @return int 1 if OK, -1 if ref already exists, -2 if other error
|
* @param boolean $updatetype Update product type
|
||||||
|
* @return int 1 if OK, -1 if ref already exists, -2 if other error
|
||||||
*/
|
*/
|
||||||
public function update($id, $user, $notrigger = false, $action = 'update')
|
public function update($id, $user, $notrigger = false, $action = 'update', $updatetype = false)
|
||||||
{
|
{
|
||||||
global $langs, $conf, $hookmanager;
|
global $langs, $conf, $hookmanager;
|
||||||
|
|
||||||
@ -939,6 +940,11 @@ class Product extends CommonObject
|
|||||||
|
|
||||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
|
$sql = "UPDATE ".MAIN_DB_PREFIX."product";
|
||||||
$sql.= " SET label = '" . $this->db->escape($this->label) ."'";
|
$sql.= " SET label = '" . $this->db->escape($this->label) ."'";
|
||||||
|
|
||||||
|
if ($updatetype && ($this->isProduct() || $this->isService())) {
|
||||||
|
$sql.= ", fk_product_type = " . $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
$sql.= ", ref = '" . $this->db->escape($this->ref) ."'";
|
$sql.= ", ref = '" . $this->db->escape($this->ref) ."'";
|
||||||
$sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
|
$sql.= ", ref_ext = ".(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext)."'":"null");
|
||||||
$sql.= ", default_vat_code = ".($this->default_vat_code ? "'".$this->db->escape($this->default_vat_code)."'" : "null");
|
$sql.= ", default_vat_code = ".($this->default_vat_code ? "'".$this->db->escape($this->default_vat_code)."'" : "null");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user