Created
September 4, 2015 17:45
-
-
Save Ibochkarev/ecfbcb716a26a1dba4ac to your computer and use it in GitHub Desktop.
msop2OptionsAll
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 | |
$msop2 = $modx->getService('msop2', 'msop2', $modx->getOption('msop2_core_path', null, $modx->getOption('core_path') . 'components/msop2/') . 'model/msop2/', $scriptProperties); | |
if (!($msop2 instanceof msop2)) return ''; | |
/* @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;} | |
// | |
$countId = $msop2->getRemainsOption(); | |
if(!$_option = $modx->getObject('msop2Option', $countId)) {return;} | |
$_key = $_option->get('key'); | |
// | |
$output = ''; | |
$product = !empty($product) ? $modx->getObject('msProduct', $product) : $product = $modx->resource; | |
$product_id = $product->get('id'); | |
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(); | |
foreach ($options as $value) { | |
if($name == $_key) { | |
$_count = $msop2->getRemainsCount(array( | |
'product_id' => $product_id, | |
'option' => $countId, | |
'value' => $value, | |
)); | |
if(empty($_count)) {continue;} | |
} | |
$pls = array( | |
'value' => $value, | |
'count' => $_count, | |
'name' => $name, | |
'selected' => $value == $selected ? 'selected' : '' | |
); | |
$rows[] = empty($tplRow) ? $value : $pdoFetch->getChunk($tplRow, $pls); | |
} | |
$modx->setPlaceholder('msop2_count_var',count($rows)); | |
$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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment