Skip to content

Instantly share code, notes, and snippets.

@vgrish
Last active February 7, 2017 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrish/213c931d96c28e09861eaa17e5c642aa to your computer and use it in GitHub Desktop.
Save vgrish/213c931d96c28e09861eaa17e5c642aa to your computer and use it in GitHub Desktop.
<?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