79 $langs->load(
"errors");
113 if (empty($this->error_parser)) {
114 return $langs->trans(
"ErrorPriceExpressionUnknown", 0);
116 list($code, $info) = $this->error_parser;
117 if (in_array($code, array(9, 14, 19, 20))) {
118 return $langs->trans(
"ErrorPriceExpression".$code);
119 } elseif (in_array($code, array(1, 2, 3, 4, 5, 8, 10, 11, 17, 21, 22))) {
120 return $langs->trans(
"ErrorPriceExpression".$code, $info);
121 } elseif (in_array($code, array(6, 23))) {
122 return $langs->trans(
"ErrorPriceExpression".$code, $info[0], $info[1]);
123 } elseif (in_array($code, array(7, 12, 13, 15, 16, 18))) {
124 return $langs->trans(
"ErrorPriceExpressionInternal", $code);
126 return $langs->trans(
"ErrorPriceExpressionUnknown", $code);
140 global $user, $hookmanager, $extrafields;
142 $action =
'PARSEEXPRESSION';
143 if ($reshook = $hookmanager->executeHooks(
'doDynamiPrice', array(
144 'expression' => &$expression,
145 'product' => &$product,
147 ), $this, $action)) {
148 return $hookmanager->resArray[
'return'];
151 $expression = trim($expression);
152 if (empty($expression)) {
153 $this->error_parser = array(20,
null);
158 $values = array_merge($values, array(
159 "tva_tx" => $product->tva_tx,
160 "localtax1_tx" => $product->localtax1_tx,
161 "localtax2_tx" => $product->localtax2_tx,
162 "weight" => $product->weight,
163 "length" => $product->length,
164 "surface" => $product->surface,
165 "price_min" => $product->price_min,
166 "cost_price" => $product->cost_price,
167 "pmp" => $product->pmp,
171 if (! is_object($extrafields)) {
173 $extrafields->fetch_name_optionals_label($product->table_element);
176 $product->fetch_optionals();
177 if (is_array($extrafields->attributes[$product->table_element][
'label'])) {
178 foreach ($extrafields->attributes[$product->table_element][
'label'] as $key => $label) {
179 $values[
"extrafield_".$key] = $product->array_options[
'options_'.$key];
185 foreach ($price_updaters->listPendingUpdaters() as $entry) {
187 $entry->update_next_update(
dol_now() + ($entry->update_interval * 60), $user);
189 $res = $entry->process();
191 $entry->update_status($res < 1 ? $entry->error :
'', $user);
196 foreach ($price_globals->listGlobalVariables() as $entry) {
197 $values[
"global_".$entry->code] = $entry->value;
201 unset($values[
"supplier_id"]);
205 $em->suppress_errors =
true;
206 $this->error_expr =
null;
210 $expression = str_replace(
"\n", $this->separator_chr, $expression);
211 foreach ($values as $key => $value) {
212 if ($value ===
null && strpos($expression, $key) !==
false) {
213 $this->error_parser = array(24, $key);
216 $expression = str_replace($this->special_chr.$key.$this->special_chr, strval($value), $expression);
220 if (strpos($expression, $this->special_chr) !==
false) {
221 $data = explode($this->special_chr, $expression);
222 $variable = $this->special_chr.$data[1];
223 if (isset($data[2])) {
224 $variable .= $this->special_chr;
226 $this->error_parser = array(23, array($variable, $expression));
231 $expressions = explode($this->separator_chr, $expression);
232 $expressions = array_slice($expressions, 0, $this->limit);
233 foreach ($expressions as $expr) {
236 $last_result = $em->evaluate($expr);
237 $this->error_parser = $em->last_error_code;
238 if ($this->error_parser !==
null) {
239 $this->error_expr = $expr;
245 if (empty($vars[
"price"])) {
246 $vars[
"price"] = $last_result;
248 if (!isset($vars[
"price"])) {
249 $this->error_parser = array(21, $expression);
252 if ($vars[
"price"] < 0) {
253 $this->error_parser = array(22, $expression);
256 return $vars[
"price"];
270 $res = $price_expression->fetch($product->fk_price_expression);
272 $this->error_parser = array(19,
null);
278 $res = $productFournisseur->find_min_price_product_fournisseur($product->id, 0, 0);
280 $this->error_parser = array(25,
null);
282 } elseif ($res == 0) {
283 $supplier_min_price = 0;
284 $supplier_min_price_with_discount = 0;
286 $supplier_min_price = $productFournisseur->fourn_unitprice;
287 $supplier_min_price_with_discount = $productFournisseur->fourn_unitprice_with_discount;
291 $extra_values = array_merge($extra_values, array(
292 "supplier_min_price" => $supplier_min_price,
293 "supplier_min_price_with_discount" => $supplier_min_price_with_discount,
297 $result = $this->
parseExpression($product, $price_expression->expression, $extra_values);
298 if (empty($this->error_parser)) {
299 if ($result < $product->price_min) {
300 $result = $product->price_min;
317 $res = $price_expression->fetch($product_supplier->fk_supplier_price_expression);
319 $this->error_parser = array(19,
null);
324 $product_supplier->fetch($product_supplier->id,
'',
'',
'', 1);
327 $extra_values = array_merge($extra_values, array(
328 "supplier_quantity" => $product_supplier->fourn_qty,
329 "supplier_tva_tx" => $product_supplier->fourn_tva_tx,
333 return $this->
parseExpression($product_supplier, $price_expression->expression, $extra_values);
344 public function testExpression($product_id, $expression, $extra_values = array())
347 $product =
new Product($this->db);
348 $product->fetch($product_id,
'',
'', 1);
351 $extra_values = array_merge($extra_values, array(
352 "supplier_min_price" => 1,
353 "supplier_min_price_with_discount" => 2,
357 $extra_values = array_merge($extra_values, array(
358 "supplier_quantity" => 3,
359 "supplier_tva_tx" => 4,