Last active
February 7, 2017 14:34
-
-
Save vgrish/213c931d96c28e09861eaa17e5c642aa to your computer and use it in GitHub Desktop.
This file contains 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 | |
/** @var modX $modx */ | |
/** @var array $scriptProperties */ | |
$tpl = $modx->getOption('tpl', $scriptProperties, 'tpl.msOptions'); | |
if (!empty($input) && empty($product)) { | |
$product = $input; | |
} | |
if (!empty($name) && empty($options)) { | |
$options = $name; | |
} | |
$product = !empty($product) && $product != $modx->resource->id | |
? $modx->getObject('msProduct', $product) | |
: $modx->resource; | |
if (!($product instanceof msProduct)) { | |
return "[msOptions] The resource with id = {$product->id} is not instance of msProduct."; | |
} | |
$names = array_map('trim', explode(',', $options)); | |
$options = array(); | |
foreach ($names as $name) { | |
if (!empty($name) && $option = $product->get($name)) { | |
if (!is_array($option)) { | |
$option = array($option); | |
} | |
$options[$name] = $option; | |
} | |
} | |
/** @var pdoTools $pdoTools */ | |
$pdoTools = $modx->getService('pdoTools'); | |
return $pdoTools->getChunk($tpl, array( | |
'id' => $product->id, | |
'options' => $options, | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment