65 $langs->load(
"errors");
99 if (empty($this->error_parser)) {
100 return $langs->trans(
"ErrorPriceExpressionUnknown", 0);
102 list($code, $info) = $this->error_parser;
103 if (in_array($code, array(9, 14, 19, 20))) {
104 return $langs->trans(
"ErrorPriceExpression".$code);
105 } elseif (in_array($code, array(1, 2, 3, 4, 5, 8, 10, 11, 17, 21, 22))) {
106 return $langs->trans(
"ErrorPriceExpression".$code, $info);
107 } elseif (in_array($code, array(6, 23))) {
108 return $langs->trans(
"ErrorPriceExpression".$code, $info[0], $info[1]);
109 } elseif (in_array($code, array(7, 12, 13, 15, 16, 18))) {
110 return $langs->trans(
"ErrorPriceExpressionInternal", $code);
112 return $langs->trans(
"ErrorPriceExpressionUnknown", $code);
126 global $user, $hookmanager, $extrafields;
128 $action =
'PARSEEXPRESSION';
129 if ($reshook = $hookmanager->executeHooks(
'doDynamiPrice', array(
130 'expression' => &$expression,
131 'product' => &$product,
133 ), $this, $action)) {
134 return $hookmanager->resArray[
'return'];
137 $expression = trim($expression);
138 if (empty($expression)) {
139 $this->error_parser = array(20,
null);
144 $values = array_merge($values, array(
145 "tva_tx" => $product->tva_tx,
146 "localtax1_tx" => $product->localtax1_tx,
147 "localtax2_tx" => $product->localtax2_tx,
148 "weight" => $product->weight,
149 "length" => $product->length,
150 "surface" => $product->surface,
151 "price_min" => $product->price_min,
152 "cost_price" => $product->cost_price,
153 "pmp" => $product->pmp,
157 if (! is_object($extrafields)) {
159 $extrafields->fetch_name_optionals_label($product->table_element);
162 $product->fetch_optionals();
163 if (is_array($extrafields->attributes[$product->table_element][
'label'])) {
164 foreach ($extrafields->attributes[$product->table_element][
'label'] as $key => $label) {
165 $values[
"extrafield_".$key] = $product->array_options[
'options_'.$key];
171 foreach ($price_updaters->listPendingUpdaters() as $entry) {
173 $entry->update_next_update(
dol_now() + ($entry->update_interval * 60), $user);
175 $res = $entry->process();
177 $entry->update_status($res < 1 ? $entry->error :
'', $user);
182 foreach ($price_globals->listGlobalVariables() as $entry) {
183 $values[
"global_".$entry->code] = $entry->value;
187 unset($values[
"supplier_id"]);
191 $em->suppress_errors =
true;
192 $this->error_expr =
null;
196 $expression = str_replace(
"\n", $this->separator_chr, $expression);
197 foreach ($values as $key => $value) {
198 if ($value ===
null && strpos($expression, $key) !==
false) {
199 $this->error_parser = array(24, $key);
202 $expression = str_replace($this->special_chr.$key.$this->special_chr, strval($value), $expression);
206 if (strpos($expression, $this->special_chr) !==
false) {
207 $data = explode($this->special_chr, $expression);
208 $variable = $this->special_chr.$data[1];
209 if (isset($data[2])) {
210 $variable .= $this->special_chr;
212 $this->error_parser = array(23, array($variable, $expression));
217 $expressions = explode($this->separator_chr, $expression);
218 $expressions = array_slice($expressions, 0, $this->limit);
219 foreach ($expressions as $expr) {
222 $last_result = $em->evaluate($expr);
223 $this->error_parser = $em->last_error_code;
224 if ($this->error_parser !==
null) {
225 $this->error_expr = $expr;
231 if (empty($vars[
"price"])) {
232 $vars[
"price"] = $last_result;
234 if (!isset($vars[
"price"])) {
235 $this->error_parser = array(21, $expression);
238 if ($vars[
"price"] < 0) {
239 $this->error_parser = array(22, $expression);
242 return $vars[
"price"];
256 $res = $price_expression->fetch($product->fk_price_expression);
258 $this->error_parser = array(19,
null);
264 $res = $productFournisseur->find_min_price_product_fournisseur($product->id, 0, 0);
266 $this->error_parser = array(25,
null);
268 } elseif ($res == 0) {
269 $supplier_min_price = 0;
270 $supplier_min_price_with_discount = 0;
272 $supplier_min_price = $productFournisseur->fourn_unitprice;
273 $supplier_min_price_with_discount = $productFournisseur->fourn_unitprice_with_discount;
277 $extra_values = array_merge($extra_values, array(
278 "supplier_min_price" => $supplier_min_price,
279 "supplier_min_price_with_discount" => $supplier_min_price_with_discount,
283 $result = $this->
parseExpression($product, $price_expression->expression, $extra_values);
284 if (empty($this->error_parser)) {
285 if ($result < $product->price_min) {
286 $result = $product->price_min;
303 $res = $price_expression->fetch($product_supplier->fk_supplier_price_expression);
305 $this->error_parser = array(19,
null);
310 $product_supplier->fetch($product_supplier->id,
'',
'',
'', 1);
313 $extra_values = array_merge($extra_values, array(
314 "supplier_quantity" => $product_supplier->fourn_qty,
315 "supplier_tva_tx" => $product_supplier->fourn_tva_tx,
319 return $this->
parseExpression($product_supplier, $price_expression->expression, $extra_values);
330 public function testExpression($product_id, $expression, $extra_values = array())
333 $product =
new Product($this->db);
334 $product->fetch($product_id,
'',
'', 1);
337 $extra_values = array_merge($extra_values, array(
338 "supplier_min_price" => 1,
339 "supplier_min_price_with_discount" => 2,
343 $extra_values = array_merge($extra_values, array(
344 "supplier_quantity" => 3,
345 "supplier_tva_tx" => 4,