diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index dc102a2248f..95a3b1fa9ad 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -17,6 +17,7 @@ * Copyright (C) 2019 Thibault Foucart * Copyright (C) 2020 Open-Dsi * Copyright (C) 2021 Gauthier VERDOL + * Copyright (C) 2022 Ferran Marcet * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -7204,6 +7205,9 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $substitutionarray['__PROJECT_REF__'] = (is_object($object->projet) ? $object->projet->ref : ''); $substitutionarray['__PROJECT_NAME__'] = (is_object($object->projet) ? $object->projet->title : ''); } + if (is_object($object) && $object->element == 'project') { + $substitutionarray['__PROJECT_NAME__'] = $object->title; + } if (is_object($object) && $object->element == 'shipping') { $substitutionarray['__SHIPPINGTRACKNUM__'] = $object->tracking_number; diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index daef20542a5..4295f3fc232 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -766,7 +766,7 @@ if (!empty($usemargins) && $user->rights->margins->creer) { global->PRODUCT_LOAD_EXTRAFIELD_INTO_OBJECTLINES)) { ?> jQuery.each(data.array_options, function( key, value ) { - jQuery('div[class$="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value); + jQuery('div[class*="det'+key.replace('options_','_extras_')+'"] > #'+key).val(value); }); diff --git a/htdocs/variants/ajax/get_attribute_values.php b/htdocs/variants/ajax/get_attribute_values.php index 1d4eab49773..c9abbd9e9bf 100644 --- a/htdocs/variants/ajax/get_attribute_values.php +++ b/htdocs/variants/ajax/get_attribute_values.php @@ -75,7 +75,7 @@ if ($prodattr->fetch($id) < 0) { $prodattrval = new ProductAttributeValue($db); -$res = $prodattrval->fetchAllByProductAttribute($id); +$res = $prodattrval->fetchAllByProductAttribute($id, false, 1); if ($res == -1) { print json_encode(array( diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php index 1e7f44bb936..4f218b79807 100644 --- a/htdocs/variants/class/ProductAttribute.class.php +++ b/htdocs/variants/class/ProductAttribute.class.php @@ -107,9 +107,10 @@ class ProductAttribute extends CommonObject /** * Returns an array of all product variants * - * @return ProductAttribute[] + * @param int $returnonlydata 0: return object, 1: return only data + * @return ProductAttribute[] */ - public function fetchAll() + public function fetchAll($returnonlydata = 0) { $return = array(); @@ -118,7 +119,12 @@ class ProductAttribute extends CommonObject $query = $this->db->query($sql); if ($query) { while ($result = $this->db->fetch_object($query)) { - $tmp = new ProductAttribute($this->db); + if (empty($returnonlydata)) { + $tmp = new ProductAttribute($this->db); + } else { + $tmp = new stdClass(); + } + $tmp->id = $result->rowid; $tmp->ref = $result->ref; $tmp->ref_ext = $result->ref_ext; diff --git a/htdocs/variants/class/ProductAttributeValue.class.php b/htdocs/variants/class/ProductAttributeValue.class.php index 5ee341526bb..ff9f233ce3d 100644 --- a/htdocs/variants/class/ProductAttributeValue.class.php +++ b/htdocs/variants/class/ProductAttributeValue.class.php @@ -99,11 +99,12 @@ class ProductAttributeValue extends CommonObject /** * Returns all product attribute values of a product attribute * - * @param int $prodattr_id Product attribute id - * @param bool $only_used Fetch only used attribute values - * @return ProductAttributeValue[] + * @param int $prodattr_id Product attribute id + * @param bool $only_used Fetch only used attribute values + * @param int $returnonlydata 0: return object, 1: return only data + * @return ProductAttributeValue[] */ - public function fetchAllByProductAttribute($prodattr_id, $only_used = false) + public function fetchAllByProductAttribute($prodattr_id, $only_used = false, $returnonlydata = 0) { $return = array(); @@ -130,7 +131,12 @@ class ProductAttributeValue extends CommonObject $query = $this->db->query($sql); while ($result = $this->db->fetch_object($query)) { - $tmp = new ProductAttributeValue($this->db); + if (empty($returnonlydata)) { + $tmp = new ProductAttributeValue($this->db); + } else { + $tmp = new stdClass(); + } + $tmp->fk_product_attribute = $result->fk_product_attribute; $tmp->id = $result->rowid; $tmp->ref = $result->ref; diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 64fa6b08b93..da71ee91a42 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -481,7 +481,7 @@ if (!empty($id) || !empty($ref)) { } if ($action == 'add') { - $prodattr_all = $prodattr->fetchAll(); + $prodattr_all = $prodattr->fetchAll(1); if (!$selected) { $selected = $prodattr_all[key($prodattr_all)]->id; @@ -492,7 +492,6 @@ if (!empty($id) || !empty($ref)) { foreach ($prodattr_all as $each) { $prodattr_alljson[$each->id] = $each; } - ?>