diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 7a177ee4e1b..708e79f1453 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -141,17 +141,18 @@ if ($id > 0 || !empty($ref)) { if ($result < 0) { dol_print_error($db, $object->error, $object->errors); } + $entity = (!empty($object->entity) ? $object->entity : $conf->entity); if (isModEnabled("product")) { - $upload_dir = $conf->product->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + $upload_dir = $conf->product->multidir_output[$entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); } elseif (isModEnabled("service")) { - $upload_dir = $conf->service->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); + $upload_dir = $conf->service->multidir_output[$entity].'/'.get_exdir(0, 0, 0, 0, $object, 'product').dol_sanitizeFileName($object->ref); } if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { // For backward compatiblity, we scan also old dirs if (isModEnabled("product")) { - $upload_dirold = $conf->product->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; + $upload_dirold = $conf->product->multidir_output[$entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; } else { - $upload_dirold = $conf->service->multidir_output[$object->entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; + $upload_dirold = $conf->service->multidir_output[$entity].'/'.substr(substr("000".$object->id, -2), 1, 1).'/'.substr(substr("000".$object->id, -2), 0, 1).'/'.$object->id."/photos"; } } } @@ -497,10 +498,11 @@ if (empty($reshook)) { if (!$error) { $units = GETPOST('units', 'int'); - $object->ref = $ref; - $object->label = GETPOST('label', $label_security_check); - $object->price_base_type = GETPOST('price_base_type', 'aZ09'); - $object->mandatory_period = !empty(GETPOST("mandatoryperiod", 'alpha')) ? 1 : 0; + $object->entity = $conf->entity; + $object->ref = $ref; + $object->label = GETPOST('label', $label_security_check); + $object->price_base_type = GETPOST('price_base_type', 'aZ09'); + $object->mandatory_period = !empty(GETPOST("mandatoryperiod", 'alpha')) ? 1 : 0; if ($object->price_base_type == 'TTC') { $object->price_ttc = GETPOST('price'); } else { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index ce0d05fd048..1dde1364e33 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -770,7 +770,7 @@ class Product extends CommonObject $sql .= ", mandatory_period"; $sql .= ") VALUES ("; $sql .= "'".$this->db->idate($now)."'"; - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".(!empty($this->entity) ? (int) $this->entity : (int) $conf->entity); $sql .= ", '".$this->db->escape($this->ref)."'"; $sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null"); $sql .= ", ".price2num($price_min_ht);