trigger on shipping method update

This commit is contained in:
Frédéric FRANCE
2018-01-26 08:33:35 +01:00
parent d0e83b7902
commit 336c44dc88

View File

@@ -1790,29 +1790,57 @@ abstract class CommonObject
* Change the shipping method * Change the shipping method
* *
* @param int $shipping_method_id Id of shipping method * @param int $shipping_method_id Id of shipping method
* @param bool $notrigger false=launch triggers after, true=disable triggers
* @param User $userused Object user
*
* @return int 1 if OK, 0 if KO * @return int 1 if OK, 0 if KO
*/ */
function setShippingMethod($shipping_method_id) function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null)
{ {
global $user;
if (empty($userused)) $userused=$user;
$error = 0;
if (! $this->table_element) { if (! $this->table_element) {
dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
$this->db->begin();
if ($shipping_method_id<0) $shipping_method_id='NULL'; if ($shipping_method_id<0) $shipping_method_id='NULL';
dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
$sql.= " SET fk_shipping_method = ".$shipping_method_id; $sql.= " SET fk_shipping_method = ".$shipping_method_id;
$sql.= " WHERE rowid=".$this->id; $sql.= " WHERE rowid=".$this->id;
$resql = $this->db->query($sql);
if ($this->db->query($sql)) { if (! $resql) {
$this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id;
return 1;
} else {
dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG);
$this->error=$this->db->error(); $this->error = $this->db->lasterror();
return 0; $error++;
} } else {
if (!$notrigger)
{
// Call trigger
$this->context=array('shippingmethodupdate'=>1);
$result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused);
if ($result < 0) $error++;
// End call trigger
}
}
if ($error)
{
$this->db->rollback();
return -1;
} else {
$this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id;
$this->db->commit();
return 1;
}
} }
@@ -1904,6 +1932,8 @@ abstract class CommonObject
dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR);
return -1; return -1;
} }
$this->db->begin();
if ($fk_account<0) $fk_account='NULL'; if ($fk_account<0) $fk_account='NULL';
dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');