Integrations > APIs. * The API key defines the tenant context. */ $apiBase='https://app.fenzon.com/api.php'; $apiKey=getenv('FENZON_API_KEY')?:'YOUR_API_KEY'; $productId=(int)(getenv('FENZON_PRODUCT_ID')?:0); $configLanguage='de'; $configProps=[ 'configLanguage'=>$configLanguage, 'configCurrency'=>'EUR', 'configVatType'=>'excl', // 'configVatRate'=>19, // Optional. If omitted, the tenant default VAT rate is used. 'discount'=>0, 'showFieldNumbers'=>true, 'showDimensions'=>true, 'showOpeningTypes'=>true, 'showBackground'=>true ]; $configView='both'; // inside | outside | both if($apiKey==='YOUR_API_KEY'||$productId<=0){ header('Content-Type: text/plain; charset=utf-8'); echo "Fenzon Configurator Quickstart\n\n"; echo "Set FENZON_API_KEY or replace YOUR_API_KEY and set FENZON_PRODUCT_ID before running this file.\n"; exit; } // 1. Authenticate once and return an authenticated API request function. function fenzonApi(string $apiKey,string $apiBase):Closure{ $request=function(string $method,string $url,array $headers=[],?array $body=null):array{ $ch=curl_init($url); $requestHeaders=array_merge(['Accept: application/json'],$headers); $options=[ CURLOPT_RETURNTRANSFER=>true, CURLOPT_CUSTOMREQUEST=>$method, CURLOPT_HTTPHEADER=>$requestHeaders, CURLOPT_CONNECTTIMEOUT=>5, CURLOPT_TIMEOUT=>20 ]; if($body!==null){ $json=json_encode($body,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $requestHeaders[]='Content-Type: application/json'; $options[CURLOPT_HTTPHEADER]=$requestHeaders; $options[CURLOPT_POSTFIELDS]=$json; } curl_setopt_array($ch,$options); $raw=curl_exec($ch); if($raw===false){$error=curl_error($ch);curl_close($ch);throw new RuntimeException('API connection failed: '.$error);} $status=(int)curl_getinfo($ch,CURLINFO_RESPONSE_CODE); curl_close($ch); $data=json_decode($raw,true,512,JSON_THROW_ON_ERROR); if($status<200||$status>=300||isset($data['error'])){$message=$data['error']['message']??('HTTP '.$status);throw new RuntimeException('Fenzon API: '.$message);} return$data; }; $session=$request('POST',$apiBase.'/auth/session',['X-Fenzon-Api-Key: '.$apiKey]); $token=(string)($session['data']['session_token']??$session['data']['token']??''); if($token==='')throw new RuntimeException('The API did not return a session token.'); $auth=['Authorization: Bearer '.$token]; return static fn(string $method,string $endpoint,?array $body=null):array=>$request($method,$apiBase.'/'.ltrim($endpoint,'/'),$auth,$body); } // 2. Start, change, evaluate, confirm or skip rules and validate through one function. function fenzonConfigurator(Closure $api,int $productId,array $config=[],array $action=[],array $configProps=[]):array{ if(!$config)$config=['product'=>[0=>$productId]]; $confirmRules=array_values(array_unique(array_map('intval',(array)($action['confirmRules']??[])))); $skipRules=array_values(array_unique(array_map('intval',(array)($action['skipRules']??[])))); $confirm=(int)($action['confirm']??0); $skip=(int)($action['skip']??0); if($confirm>0){$confirmRules[]=$confirm;$confirmRules=array_values(array_unique($confirmRules));$skipRules=array_values(array_diff($skipRules,[$confirm]));} if($skip>0){$skipRules[]=$skip;$skipRules=array_values(array_unique($skipRules));$confirmRules=array_values(array_diff($confirmRules,[$skip]));} $update=trim((string)($action['field']??'')); if($update!==''){ preg_match_all('/[^\.\[\]]+/',$update,$matches); $keys=$matches[0]??[]; if(!$keys)throw new InvalidArgumentException('Invalid field path: '.$update); $value=$action['value']??''; $isCombinationRelation=($keys[0]??'')==='combination'&&end($keys)==='relation'; $previousRelation=null; if($isCombinationRelation){ $scope=(string)($keys[1]??'');$section=$scope==='section'?(string)($keys[2]??'0'):'0';$class=(string)($keys[$scope==='section'?3:2]??''); $entry=$scope==='section'?($config['combination']['section'][$section][$class]??null):($config['combination']['element'][$class]??null); $previousRelation=is_array($entry)?($entry['relation']??null):$entry; } $ref=&$config; foreach($keys as$i=>$key){ $key=ctype_digit((string)$key)?(int)$key:$key; if($i===array_key_last($keys)){$ref[$key]=$value;break;} if(!isset($ref[$key]))$ref[$key]=[]; elseif(!is_array($ref[$key]))$ref[$key]=['id'=>$ref[$key]]; $ref=&$ref[$key]; } unset($ref); if($isCombinationRelation){ if((string)$value===''){ if($scope==='section')unset($config['combination']['section'][$section][$class]);else unset($config['combination']['element'][$class]); }elseif((string)$previousRelation!==(string)$value){ if($scope==='section')unset($config['combination']['section'][$section][$class]['config']);else unset($config['combination']['element'][$class]['config']); } } } $props=array_replace([ 'configLanguage'=>'de', 'configCurrency'=>'EUR', 'configVatType'=>'excl', 'discount'=>0, 'showFieldNumbers'=>true, 'showDimensions'=>true, 'showOpeningTypes'=>true, 'showBackground'=>true ],$configProps,[ 'confirmRules'=>$confirmRules, 'skipRules'=>$skipRules ]); if($update!=='')$props['update']=$update; elseif(!empty($action['update']))$props['update']=(string)$action['update']; if(!empty($action['validate']))$props['save']=true; $requestBody=['config'=>$config,'props'=>$props]; $requestPayload=json_decode(json_encode($requestBody,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR),true,512,JSON_THROW_ON_ERROR); $response=$api('POST','configurations/render',$requestBody); $data=(array)($response['data']??[]); $data['props']=is_array($data['props']??null)?$data['props']:[]; $data['props']['confirmRules']=$confirmRules; $data['props']['skipRules']=$skipRules; if(isset($props['update']))$data['props']['update']=$props['update']; $data['_request']=['method'=>'POST','endpoint'=>'configurations/render','body'=>$requestPayload]; return$data; } // 3. Optionally add the finished configuration to an existing or a new document. function saveConfiguration(Closure $api,array $configuration,int $documentId=0,int $accountId=0):array{ if(empty($configuration['rules']['can_save']))throw new RuntimeException('The configuration is not ready to be saved.'); $product=$configuration['config']['product'][0]??0; if(is_array($product))$product=$product['id']??reset($product); $productId=(int)$product; if($productId<=0)throw new RuntimeException('The configuration does not contain a valid product ID.'); $createdDocument=null; if($documentId<=0){ if($accountId<=0)throw new RuntimeException('Set an account ID when creating a new document.'); $response=$api('POST','documents',['account_id'=>$accountId,'type'=>'quote']); $createdDocument=(array)($response['data']??[]); $documentId=(int)($createdDocument['id']??0); if($documentId<=0)throw new RuntimeException('The API did not return a document ID.'); } $response=$api('POST','document_items',[ 'document_id'=>$documentId, 'product_id'=>$productId, 'type'=>'product', 'config'=>$configuration['config'], 'quantity'=>1 ]); return[ 'document_id'=>$documentId, 'document_created'=>$createdDocument!==null, 'document'=>$createdDocument, 'item'=>$response['data']??[] ]; } // 4. Optionally render fields, visualization, prices and rule decisions as simple HTML. function renderConfigurator(array $configuration,string $configView='both'):void{ $h=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES|ENT_SUBSTITUTE,'UTF-8'); $configLanguage=strtolower(trim((string)($configuration['props']['configLanguage']??'de')))?:'de'; $languageKeys=array_values(array_unique([$configLanguage,str_replace('_','-',$configLanguage),strtolower(explode('-',str_replace('_','-',$configLanguage))[0]??$configLanguage),'de-DE','de','en-US','en'])); $text=static function($value)use($languageKeys):string{ if(is_string($value)||is_numeric($value))return trim((string)$value); if(!is_array($value))return''; foreach($languageKeys as$locale){ if(isset($value[$locale])&&(is_string($value[$locale])||is_numeric($value[$locale]))&&trim((string)$value[$locale])!=='')return trim((string)$value[$locale]); } foreach($value as$item)if((is_string($item)||is_numeric($item))&&trim((string)$item)!=='')return trim((string)$item); return''; }; $scalar=static function($value){ if(is_array($value)){ if(array_key_exists('id',$value))return$value['id']; if(count($value)===1)return reset($value); } return$value; }; $pathName=static function(array $path):string{ if(!$path)return''; $name=(string)array_shift($path); foreach($path as$key)$name.='['.(string)$key.']'; return$name; }; $humanize=static function(string $value):string{ $value=(string)preg_replace('/(?'; $combinationChildren=[]; foreach((array)($configuration['combinationFlow']['configurable']??[])as$child){ if(!is_array($child)||trim((string)($child['key']??''))==='')continue; $combinationChildren[(string)$child['key']]=$child; } $fields=[]; $nodeVisible=static function(array $node)use($scalar):bool{ $display=$node['data']['display']??null; if(!is_array($display)){ $selected=$scalar($node['value']??$node['default']??''); $display=is_array($node['options'][$selected]['data']['display']??null)?$node['options'][$selected]['data']['display']:null; } return!is_array($display)||!array_key_exists('configuration',$display)||$display['configuration']!==false; }; $collectAttributes=function(array $path,array $node,int $level=0)use(&$collectAttributes,&$fields,$scalar,$nodeVisible):void{ if(count($path)<2)return; $selected=$scalar($node['value']??$node['default']??''); $attributes=$node['options'][$selected]['attributes']??null; if(!is_array($attributes))return; foreach($attributes as$attribute=>$layers){ $layerMap=isset($layers['type'])?[0=>$layers]:(array)$layers; foreach($layerMap as$layerIndex=>$layer){ $hasSubIndex=!isset($layer['type']); $valueMap=$hasSubIndex?(array)$layer:[0=>$layer]; foreach($valueMap as$subIndex=>$attributeNode){ if(!is_array($attributeNode)||empty($attributeNode['type'])||!$nodeVisible($attributeNode))continue; $attributePath=[$path[0],$path[1],$attribute,(string)$layerIndex]; if($hasSubIndex)$attributePath[]=(string)$subIndex; $fields[]=['path'=>$attributePath,'node'=>$attributeNode,'level'=>$level+1]; $collectAttributes($attributePath,$attributeNode,$level+1); } } } }; $walk=function($node,array $path=[])use(&$walk,&$fields,$collectAttributes,$nodeVisible):void{ if(!is_array($node))return; $isNode=array_key_exists('value',$node)||array_key_exists('default',$node)||isset($node['options'])||isset($node['type']); if($isNode){ if(empty($node['hidden'])&&($node['type']??'')!=='hidden'&&$nodeVisible($node)){ $fields[]=['path'=>$path,'node'=>$node,'level'=>0]; $collectAttributes($path,$node); } return; } foreach($node as$key=>$value){ if(!is_array($value)||in_array((string)$key,['options','attributes','data','display','label','constraints'],true))continue; $walk($value,[...$path,$key]); } }; $walk((array)($configuration['ctree']??[])); $svgViews=[]; foreach((array)($configuration['svg']??[])as$view=>$viewSvg){ if(!is_string($viewSvg)||stripos($viewSvg,'(string)$view,'key'=>$viewKey,'label'=>$viewLabel,'svg'=>$viewSvg]; } $configView=in_array($configView,['inside','outside','both'],true)?$configView:'both'; if($configView!=='both'){ $filtered=array_values(array_filter($svgViews,static fn(array $view):bool=>$view['key']===$configView)); if($filtered)$svgViews=$filtered; } $ruleItems=[]; $collectRule=function($rule,$index=0)use(&$ruleItems):void{ if(!is_array($rule))return; $id=(int)($rule['ruleId']??$rule['rule_id']??$rule['id']??(is_numeric($index)?$index:0)); if($id>0&&!isset($ruleItems[$id]))$ruleItems[$id]=$rule; }; $collectRule($configuration['rules']['message']??null); foreach(['modal_queue','pending','blocking']as$key)foreach((array)($configuration['rules'][$key]??[])as$index=>$rule)$collectRule($rule,$index); $configJson=json_encode($configuration['config']??[],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $confirmJson=json_encode($configuration['props']['confirmRules']??[],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $skipJson=json_encode($configuration['props']['skipRules']??[],JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $update=(string)($configuration['rules']['update']??$configuration['props']['update']??''); $notice=(string)($configuration['_notice']??''); $descriptionRows=array_values((array)($configuration['description']??[])); $productPricing=(array)($configuration['pricing']['product'][0]??[]); $totalPrice=$productPricing['salePrice']??$productPricing['price']??null; $currency=(string)($configuration['props']['configCurrency']??'EUR'); $vatType=(string)($configuration['props']['configVatType']??'excl'); $vatRate=(float)($configuration['props']['configVatRate']??0); if(is_numeric($totalPrice)&&$vatType==='incl')$totalPrice=round((float)$totalPrice*(1+$vatRate/100),2); echo'Fenzon Configurator Quickstart'; echo''; echo'

Fenzon Configurator Quickstart

'; echo'

Runtime response language: '.$h($configLanguage).'. The UI labels in this example stay in English.

'; if($notice!=='')echo'
'.$h($notice).'
'; if($mode==='combination'){ echo'
'.$stateHtml.'
'.$stateHtml.'
'.$stateHtml.'
'; } echo'

'.($mode==='combination'?'Combination configuration'.(!empty($combinationMeta['name'])?' · '.$h($combinationMeta['name']):''):'Configuration').'

'; echo''; echo''.$stateHtml; $combinationHeading=false; foreach($fields as$field){ $node=$field['node']; $name=$pathName($field['path']); if($name==='')continue; $root=(string)($field['path'][0]??''); if($mode==='combination'&&$root==='product')continue; if($mode==='combination'&&$root==='dimension'){ $dimension=(string)end($field['path']); if(($combinationMeta['class']??'')!=='windowSill'||$dimension!=='depth')continue; } $isCombination=$root==='combination'; if($isCombination)$name=$pathName([...$field['path'],'relation']); if($isCombination&&!$combinationHeading){ echo'

Product combinations

Select a linked product to activate the combination, or choose None to remove it.

'; $combinationHeading=true; } $label=$text($node['label']??null)?:$text($node['name']??null)?:$text($node['title']??null)?:$name; if($isCombination&&$label===$name){ $class=(string)end($field['path']); $scope=(string)($field['path'][1]??''); $label='Combination · '.$humanize($class).($scope==='section'?' · Section '.(string)($field['path'][2]??''):''); } if($isCombination){ [$hasExplicitValue,$explicitValue]=$configPathValue((array)($configuration['config']??[]),[...$field['path'],'relation']); $value=$hasExplicitValue?$explicitValue:$scalar($node['value']??$node['default']??''); }else$value=$scalar($node['value']??$node['default']??''); $type=strtolower((string)($node['type']??'')); $options=(array)($node['options']??[]); $fieldLevel=max(0,(int)($field['level']??0)); echo'
'; if($options){ echo''; if($isCombination&&(string)$value!==''){ $scope=(string)($field['path'][1]??''); $section=$scope==='section'?(string)($field['path'][2]??'0'):'0'; $childKey=$scope.':'.$section.':'.(string)$value; if(isset($combinationChildren[$childKey])){ $child=$combinationChildren[$childKey]; $combinationAction=!empty($child['configured'])?'Edit ':'Configure '; echo'
'; } } }elseif(in_array($type,['checkbox','bool','boolean'],true)){ echo''; }else{ $inputType=in_array($type,['number','int','integer','float','decimal','range'],true)?'number':'text'; echo''; } echo'
'; } echo'
'; echo'

Visualization

'; if($svgViews){ echo'
'; foreach($svgViews as$view)echo'

'.$h($view['label']).'

'.$view['svg'].'
'; echo'
'; }else echo'

No SVG returned.

'; echo'
'; echo'

Product description

'; $descriptionCount=0; if($descriptionRows){ echo'
'; foreach($descriptionRows as$row){ if(!is_array($row)||($row['type']??'')==='combinationBreak')continue; $label=$text($row['label']??null); $name=$text($row['name']??null); if($label===''&&$name==='')continue; $descriptionLevel=max(0,min(8,(int)($row['level']??0))); if($label==='')echo'
'.$h($name).'
'; else echo'
'.$h($label).''.$h($name).'
'; $descriptionCount++; } echo'
'; } if($descriptionCount===0)echo'

No product description returned.

'; if(is_numeric($totalPrice))echo'
Total price ('.$h($vatType==='incl'?'incl. VAT':'excl. VAT').')'.$h(number_format((float)$totalPrice,2,'.',',').' '.$currency).'
'; echo'
'; echo'

Rules

'; if($ruleItems){ foreach($ruleItems as$ruleId=>$rule){ $title=$text($rule['title']??null); $intro=$text($rule['intro']??null); $messages=[]; $messageValue=$rule['message']??[]; if(is_string($messageValue)||is_numeric($messageValue))$messages[]=(string)$messageValue; elseif(is_array($messageValue))foreach($messageValue as$part){ $message=is_array($part)?$text($part['text']??null):$text($part); if($message!=='')$messages[]=$message; } echo'
Rule #'.$h($ruleId).' requires a decision.'; if($title!=='')echo'

'.$h($title).'

'; if($intro!=='')echo'

'.$h($intro).'

'; foreach($messages as$message)echo'

'.$h($message).'

'; foreach(['confirm'=>'Confirm','skip'=>'Skip']as$action=>$buttonLabel){ echo'
'.$stateHtml.'
'; } echo'
'; } }elseif(empty($configuration['rules']['blocking']))echo'

No rule decision is currently required.

'; if(!empty($configuration['rules']['blocking'])&&!$ruleItems)echo'
'.$h(json_encode($configuration['rules']['blocking'],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'
'.$stateHtml.'
'; echo'

Ready to save: '.(!empty($configuration['rules']['can_save'])?'yes':'no').'

'; if($mode!=='combination'){ echo'

Optional document assignment

'; echo'
Existing document'.$stateHtml.'
'; echo'
New quote'.$stateHtml.'
'; } echo'
'; echo'

Configuration Endpoints

configurations/render is the aggregate endpoint used by this quickstart. It returns props, the normalized configuration, C-Tree, construction data, combination flow, SVG/views, pricing, description and rules. The same configuration payload can be sent to configurations/ctree, configurations/svg, configurations/pricing, configurations/description or configurations/rules when only one response slice is required. In the current backend implementation, these endpoints use the same configuration pipeline and then return only the requested slice.

'; $request=(array)($configuration['_request']??[]); echo'

Latest API Request

The exact JSON payload sent with the most recent configurator request. It shows the configuration state and all properties submitted to the API before the response is processed.

'.$h(strtoupper((string)($request['method']??'POST')).' /api.php/'.ltrim((string)($request['endpoint']??'configurations/render'),'/')).'

'.$h(json_encode($request['body']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'

Configuration Data Response

The normalized configuration state returned by the API. It contains the selected product, construction, dimensions, openings, component values and the configuration state of selected product combinations. Reuse this object as config in the next configurator request.

'.$h(json_encode($configuration['config']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'

Configuration Tree Response

The complete configurable input structure for the current state. It describes available fields, options, constraints, attributes and display metadata and can be used to build a dynamic input form.

'.$h(json_encode($configuration['ctree']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'

Pricing Response

The commercial calculation for the configuration, including price and delivery-time information on product and component level. product[0] contains the aggregated result for the complete configured product, including the total price and overall delivery time.

'.$h(json_encode($configuration['pricing']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'

Description Response

The generated product description for the current configuration. The rows can be used directly for summaries or document positions and may already include calculated price information and nested description levels.

'.$h(json_encode($configuration['description']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo'

Rules Response

The current rule evaluation for the configuration. It contains informational and blocking messages, pending confirmations, applied rules and the final can_save state. Some rules only transform or validate the configuration in the background, while others require an explicit decision.

'.$h(json_encode($configuration['rules']??[],JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)).'
'; echo''; } try{ $api=fenzonApi($apiKey,$apiBase); $config=[]; $action=[]; $mode='parent'; $parentConfig=[]; $parentConfirmRules=[]; $parentSkipRules=[]; $parentUpdate=''; $combinationKey=''; $combinationMeta=[]; $type=''; if(($_SERVER['REQUEST_METHOD']??'GET')==='POST'){ $config=json_decode((string)($_POST['config']??''),true)?:[]; $parentConfig=json_decode((string)($_POST['parentConfig']??''),true)?:[]; $parentConfirmRules=json_decode((string)($_POST['parentConfirmRules']??''),true)?:[]; $parentSkipRules=json_decode((string)($_POST['parentSkipRules']??''),true)?:[]; $parentUpdate=(string)($_POST['parentUpdate']??''); $combinationMeta=json_decode((string)($_POST['combinationMeta']??''),true)?:[]; $confirmRules=json_decode((string)($_POST['confirmRules']??''),true)?:[]; $skipRules=json_decode((string)($_POST['skipRules']??''),true)?:[]; $type=(string)($_POST['action']??''); $mode=(string)($_POST['mode']??'parent'); $combinationKey=(string)($_POST['combinationKey']??''); $action=['confirmRules'=>$confirmRules,'skipRules'=>$skipRules,'update'=>(string)($_POST['update']??'')]; if($type==='change'){$action['field']=(string)($_POST['field']??'');$action['value']=$_POST['value']??'';} elseif($type==='confirm')$action['confirm']=(int)($_POST['rule']??0); elseif($type==='skip')$action['skip']=(int)($_POST['rule']??0); elseif(in_array($type,['validate','saveExisting','saveNew','applyCombination'],true))$action['validate']=true; } if($type==='openCombination'){ $parentConfiguration=fenzonConfigurator($api,$productId,$config,$action,$configProps); $combinationKey=(string)($_POST['combinationKey']??''); $child=null; foreach((array)($parentConfiguration['combinationFlow']['configurable']??[])as$item)if((string)($item['key']??'')===$combinationKey){$child=$item;break;} if(!is_array($child))throw new RuntimeException('The selected combination configuration is not available.'); $childConfig=(array)($child['config']??[]); $childProduct=$childConfig['product'][0]??($child['product']??0); if(is_array($childProduct))$childProduct=$childProduct['id']??reset($childProduct); if(is_string($childProduct)&&str_starts_with($childProduct,'connect:'))$childProduct=(int)substr(strrchr($childProduct,':')?:':0',1); $childProps=array_replace($configProps,['combinationChild'=>true,'ctreeContext'=>['combination'=>(array)($child['compatibility']??[])]]); $configuration=fenzonConfigurator($api,max(1,(int)$childProduct),$childConfig,[],$childProps); $configuration['_quickstart']=['mode'=>'combination','parentConfig'=>$parentConfiguration['config']??$config,'parentConfirmRules'=>$parentConfiguration['props']['confirmRules']??[],'parentSkipRules'=>$parentConfiguration['props']['skipRules']??[],'parentUpdate'=>$parentConfiguration['props']['update']??'','combinationKey'=>$combinationKey,'combinationMeta'=>['key'=>$combinationKey,'name'=>$child['name']??'','class'=>$child['class']??'','relation_id'=>$child['relation_id']??0,'scope'=>$child['scope']??'element','section'=>$child['section']??null,'compatibility'=>$child['compatibility']??[]]]; }elseif($mode==='combination'&&$combinationKey!==''){ $parentAction=['confirmRules'=>$parentConfirmRules,'skipRules'=>$parentSkipRules,'update'=>$parentUpdate]; if($type==='backCombination'){ $configuration=fenzonConfigurator($api,$productId,$parentConfig,$parentAction,$configProps); }elseif($type==='removeCombination'){ $scope=(string)($combinationMeta['scope']??'element');$section=(string)($combinationMeta['section']??'0');$class=(string)($combinationMeta['class']??''); if($scope==='section')unset($parentConfig['combination']['section'][$section][$class]);else unset($parentConfig['combination']['element'][$class]); $configuration=fenzonConfigurator($api,$productId,$parentConfig,$parentAction,$configProps); }elseif($type==='applyCombination'){ $childProps=array_replace($configProps,['combinationChild'=>true,'ctreeContext'=>['combination'=>(array)($combinationMeta['compatibility']??[])]]); $childProduct=$config['product'][0]??0;if(is_array($childProduct))$childProduct=$childProduct['id']??reset($childProduct);if(is_string($childProduct)&&str_starts_with($childProduct,'connect:'))$childProduct=(int)substr(strrchr($childProduct,':')?:':0',1); $childConfiguration=fenzonConfigurator($api,max(1,(int)$childProduct),$config,$action,$childProps); if(empty($childConfiguration['rules']['can_save']))throw new RuntimeException('Resolve the combination rules before applying the child configuration.'); $scope=(string)($combinationMeta['scope']??'element');$section=(string)($combinationMeta['section']??'0');$class=(string)($combinationMeta['class']??'');$relation=(int)($combinationMeta['relation_id']??0); $entry=['relation'=>$relation,'config'=>(array)($childConfiguration['config']??$config)]; if($scope==='section')$parentConfig['combination']['section'][$section][$class]=$entry;else$parentConfig['combination']['element'][$class]=$entry; $configuration=fenzonConfigurator($api,$productId,$parentConfig,$parentAction,$configProps); }else{ $childProps=array_replace($configProps,['combinationChild'=>true,'ctreeContext'=>['combination'=>(array)($combinationMeta['compatibility']??[])]]); $childProduct=$config['product'][0]??0;if(is_array($childProduct))$childProduct=$childProduct['id']??reset($childProduct);if(is_string($childProduct)&&str_starts_with($childProduct,'connect:'))$childProduct=(int)substr(strrchr($childProduct,':')?:':0',1); $configuration=fenzonConfigurator($api,max(1,(int)$childProduct),$config,$action,$childProps); $configuration['_quickstart']=['mode'=>'combination','parentConfig'=>$parentConfig,'parentConfirmRules'=>$parentConfirmRules,'parentSkipRules'=>$parentSkipRules,'parentUpdate'=>$parentUpdate,'combinationKey'=>$combinationKey,'combinationMeta'=>$combinationMeta]; } }else{ $configuration=fenzonConfigurator($api,$productId,$config,$action,$configProps); } if(($_SERVER['REQUEST_METHOD']??'GET')==='POST'&&in_array($type,['saveExisting','saveNew'],true)){ $saved=saveConfiguration( $api, $configuration, $type==='saveExisting'?(int)($_POST['documentId']??0):0, $type==='saveNew'?(int)($_POST['accountId']??0):0 ); $configuration['_notice']=$saved['document_created'] ?'A new quote was created and the configuration was added as a document item.' :'The configuration was added to the existing document.'; } renderConfigurator($configuration,$configView); }catch(Throwable$e){ http_response_code(500); header('Content-Type: text/plain; charset=utf-8'); echo "Fenzon Configurator Quickstart\n\n".$e->getMessage()."\n"; }