Skip to content

Instantly share code, notes, and snippets.

@vgrish
Created July 22, 2015 12:02
Show Gist options
  • Save vgrish/f48a7ab2ead1899f8aa8 to your computer and use it in GitHub Desktop.
Save vgrish/f48a7ab2ead1899f8aa8 to your computer and use it in GitHub Desktop.
msOptionsPrice
// скопировать сниппет msOptions
// вставить код ниже
<?php
/* @var array $scriptProperties */
/* @var pdoFetch $pdoFetch */
if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) {return false;}
$pdoFetch = new pdoFetch($modx, $scriptProperties);
if (empty($product) && !empty($input)) {$product = $input;}
if (empty($selected)) {$selected = '';}
if (empty($outputSeparator)) {$outputSeparator = "\n";}
if ((empty($name) || $name == 'id') && !empty($options)) {$name = $options;}
$output = '';
$product = !empty($product) ? $modx->getObject('msProduct', $product) : $product = $modx->resource;
if (!($product instanceof msProduct)) {
$output = 'This resource is not instance of msProduct class.';
}
elseif (!empty($name) && $options = $product->get($name)) {
if (!is_array($options) || $options[0] == '') {
$output = !empty($tplEmpty)
? $pdoFetch->getChunk($tplEmpty, $scriptProperties)
: '';
}
else {
$rows = array();
$pls = $product->toArray();
foreach ($options as $value) {
$pls['value'] = $value;
$pls['selected'] = $value == $selected ? 'selected' : '';
$rows[] = empty($tplRow) ? $value : $pdoFetch->getChunk($tplRow, $pls);
}
$rows = implode($outputSeparator, $rows);
$output = empty($tplOuter)
? $pdoFetch->getChunk('', array('name' => $name, 'rows' => $rows))
: $pdoFetch->getChunk($tplOuter, array_merge($scriptProperties, array('name' => $name, 'rows' => $rows)));
}
}
return $output;
// чанк _msOptions.row
<option value="[[+value]]" [[+selected]]>[[+value]] - [[+properties.msoptionsprice.[[+value]]]]</option>
// вызов
[[!_msOptions?name=`size`&tplRow=`_msOptions.row`]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment