-
-
Save TITAN-UZ/5d291f84dd4fb9c6d8213778f8942370 to your computer and use it in GitHub Desktop.
Выводим сгруппированные характеристики товара msProductOptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {foreach $cats as $cat} | |
| <div class="section-option"> | |
| <h5 class="mb-3">{$cat.name}</h5> | |
| <ul class="list-group list-group-flush mb-3"> | |
| {foreach $cat.items as $option} | |
| <li class="list-group-item d-flex justify-content-between border-0 px-0 py-2"> | |
| <span> | |
| {$option.caption} | |
| </span> | |
| <span> | |
| {if $option_type == "combo-options"?} | |
| {var $values = $value | split} | |
| {foreach $values as $val} | |
| <span class="label label-default">{$val}</span> | |
| {/foreach} | |
| {$option_measure_unit} | |
| {else} | |
| {if $option.value is array} | |
| {$option.value | join : ', '} | |
| {else} | |
| {$option.value} | |
| {/if} | |
| {if $option.measure_unit?} | |
| {$option.measure_unit} | |
| {/if} | |
| {/if} | |
| </span> | |
| </li> | |
| {/foreach} | |
| </ul> | |
| </div> | |
| {/foreach} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $product = !empty($product) && $product != $modx->resource->id | |
| ? $modx->getObject('msProduct', array('id' => $product)) | |
| : $modx->resource; | |
| if (!($product instanceof msProduct)) { | |
| return "[msProductOptions] The resource with id = {$product->id} is not instance of msProduct."; | |
| } | |
| $ignoreOptions = array_map('trim', explode(',', $modx->getOption('ignoreOptions', $scriptProperties, ''))); | |
| $onlyOptions = array_map('trim', explode(',', $modx->getOption('onlyOptions', $scriptProperties, ''))); | |
| $groups = !empty($groups) | |
| ? array_map('trim', explode(',', $groups)) | |
| : array(); | |
| if ($data = $product->getOne('Data')) { | |
| $optionKeys = $data->getOptionKeys(); | |
| } | |
| if (empty($optionKeys)) { | |
| return ''; | |
| } | |
| $productData = $product->loadOptions(); | |
| $options = array(); | |
| $catoptions = array(); | |
| foreach ($optionKeys as $key) { | |
| // Filter by key | |
| if (!empty($onlyOptions) && $onlyOptions[0] != '' && !in_array($key, $onlyOptions)) { | |
| continue; | |
| } elseif (in_array($key, $ignoreOptions)) { | |
| continue; | |
| } | |
| $option = array(); | |
| foreach ($productData as $dataKey => $dataValue) { | |
| $dataKey = explode('.', $dataKey); | |
| if ($dataKey[0] == $key && (count($dataKey) > 1)) { | |
| $option[$dataKey[1]] = $dataValue; | |
| } | |
| } | |
| $option['value'] = $product->get($key); | |
| // Filter by groups | |
| $skip = !empty($groups) && !in_array($option['category'], $groups) && !in_array($option['category_name'], $groups); | |
| if ($skip || empty($option['value'])) { | |
| continue; | |
| } | |
| $options[$key] = $option; | |
| if($option["type"] == 'combo-boolean'){ | |
| if($option['value'][0] == 1 || $option['value'][0] == "Да"){ | |
| $option['value'][0] = "Да"; | |
| }else{ | |
| $option['value'][0] = "Нет"; | |
| } | |
| } | |
| if(strlen($option['value'][0])){ | |
| $catoptions[$option['category']]['name'] = $option['category_name']; | |
| $catoptions[$option['category']]['items'][] = $option; | |
| } | |
| } | |
| if($tpl){ | |
| $pdoTools = $modx->getService('pdoTools'); | |
| return $pdoTools->getChunk($tpl, array( | |
| 'cats' => $catoptions, | |
| )); | |
| }else{ | |
| echo "<pre>"; | |
| print_r($catoptions); | |
| echo "</pre>"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment