engine = $engine; $this->article = $article; $this->formelCalc = new Formel($engine, $article); } public function calc() { $gesamt = 0; /** @var Base $option */ foreach($this->article->getOptions() as $option) { if($option instanceof Select || $option instanceof Checkbox) { /** @var Select\Opt $opt */ foreach($option->getOptions() as $opt) { if($opt->isValid() && $opt->isSelected()) { $gesamt = $this->parseEdgeCollection($gesamt, $option, $opt->getEdgesCollectionContainer(), [$option->getId()]); } } } $gesamt = $this->parseEdgeCollection($gesamt, $option, $option->getEdgesCollectionContainer(), [$option->getId()]); } return $gesamt; } /** * @param $gesamt * @param Base $option * @param EdgeCollectionContainer $container * @return int */ private function parseEdgeCollection($gesamt, $option, EdgeCollectionContainer $container, $calcValueId = []) { $calcValue1 = 0; $calcValue2 = 0; $calcValueAccount1 = 0; $calcValueAccount2 = 0; /** @var EdgeCollection $collection */ foreach($container as $collection) { $var = 'XXXXXXXXXXXX'; if($collection->getName() == "opt") continue; if($collection->getFormel() != "") { $formel = $this->formelCalc->parse($collection->getFormel()); if(preg_match("/^[a-z](.*)/", $formel)) { eval('$var = "' . $formel . '";'); }else{ eval('$var = ' . $formel . ';'); } }else{ if(isset($this->engine->getVariables()[$collection->getName()])) { $var = $this->engine->getVariables()[$collection->getName()]; } } /** @var Edge $edge */ foreach($collection as $edge) { if($var !== "XXXXXXXXXXXX" && $edge->isValid($var)) { if($edge->getPauschale() != 0) { eval('$gesamt += ' . $edge->getPauschale() . ';'); $this->engine->addDebugFlatPrice($collection->getName(), $edge->getPauschale()); } if($edge->getPreis() != 0) { eval('$gesamt += ' . ($edge->getPreis()*$var) . ';'); $this->engine->addDebugPrice($collection->getName(), $edge->getPreis(), $var, $edge->getPreis()*$var); } if($edge->getCalcValue() != "") { $cv = $this->formelCalc->parse($edge->getCalcValue()); $orgCv = $cv; try { eval('@$cv = ' . $cv . ';'); $this->engine->addDebugCalcVariables($option->getId() . '_' . $collection->getName(), $edge->getCalcValue(), $orgCv . ' = ' . $cv); }catch (\Throwable $e) { $cv = 0; } $this->engine->addCalcVariable($option->getId() . '_' . $collection->getName(), $cv); $this->engine->setCalcVaribleStack($cv, $calcValueId); } if($edge->getFormel() != "") { $formel = $this->formelCalc->parse($edge->getFormel()); if ($formel != "" && !in_array($option->getId(), ['weight', 'weight_single']) && !$option->isAjaxExport() && !$option->isDisplayOnly() && $option->isAmount()) { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); try { eval('@$p = ' . $formel . ';'); $this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = ' . $p); }catch (\Throwable $e) { $this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = error'); $p = 0; } //echo $option->getId(). ' / '.$formel . ' / '.$p.' / '.PHP_EOL.PHP_EOL; if($p > 0 || $p < 0) { $gesamt += $p; } $this->engine->setVariable('price', $gesamt); } if ($formel != "" && !in_array($option->getId(), ['weight', 'weight_single']) && $option->isAjaxExport() && !$option->isDisplayOnly() && $option->isAmount()) { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); try { eval('@$p = ' . $formel . ';'); $this->engine->addAjaxVariable($option->getId(), $p); }catch (\Throwable $e) { $this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = error'); $p = 0; } } if ($formel != "" && !in_array($option->getId(), ['weight', 'weight_single']) && !$option->isAjaxExport() && $option->isDisplayOnly() && $option->isAmount()) { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); eval('@$p = ' . $formel . ';'); $this->engine->addDisplayVariable($option->getId(), $p); } if($formel != "" && $option->getId() == "weight_single") { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); eval('@$p = ' . $formel . ';'); $this->engine->setWeightSingle($p); } if($formel != "" && $option->getId() == "weight") { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); eval('@$p = ' . $formel . ';'); $this->engine->setWeight($p); } if(!$option->isAmount()) { $p = 0; $formel = str_replace("tonumber", '$this->toNumber', $formel); eval('@$p = ' . $formel . ';'); $this->engine->addCalcVariable($option->getId(), $p); } } if($edge->getEdgesCollectionContainer()->count() > 0) { $calcValueId[] = $collection->getName(); $gesamt = $this->parseEdgeCollection($gesamt, $option, $edge->getEdgesCollectionContainer(), $calcValueId); } } } } return $gesamt; } private function toNumber($value) { if(strpos($value,',') == (strlen($value)-1)) { return str_replace(',', '', $value); } return str_replace(',', '.', $value); } }