Last active
December 12, 2015 01:28
-
-
Save denysbutenko/4691562 to your computer and use it in GitHub Desktop.
getGoods with pdoFetch
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 | |
$pdoFetch = $modx->getService('pdofetch','pdoFetch',$modx->getOption('pdotools.core_path',null,$modx->getOption('core_path').'components/pdotools/').'model/pdotools/',$scriptProperties); | |
if (!($pdoFetch instanceof pdoFetch)) return ''; | |
$miniShop = $modx->getService('minishop','miniShop',$modx->getOption('core_path').'components/minishop/model/minishop/',array()); | |
if (!($miniShop instanceof miniShop)) return ''; | |
$where = array(); | |
if (empty($templates) && $templates != '0') {$where['template'] = $modx->resource->template;} | |
else if (!empty($templates)){ | |
$tids = explode(',', $templates); | |
$where['template:IN'] = $tids; | |
} | |
if (empty($parents) && $parents != '0') {$where['parent'] = $modx->resource->id;} | |
else if (!empty($parents)){ | |
$pids = explode(',', $parents); | |
$where['parent:IN'] = $pids; | |
} | |
$default = array( | |
'where' => json_encode($where) | |
,'leftJoin' => '{ | |
"ModGoods":{"alias":"Goods","on":"Goods.gid=modResource.id"} | |
,"ModGallery":{"alias":"Gallery","on":"Gallery.gid=Goods.gid AND Gallery.fileorder=0"} | |
}' | |
,'select' => '{ | |
"modResource":"modResource.id as id,modResource.pagetitle as pagetitle,modResource.longtitle as longtitle, modResource.uri as uri" | |
,"Goods":"Goods.price as price" | |
,"Gallery":"Gallery.file as file" | |
}' | |
,'sortby' => 'createdon' | |
,'sortdir' => 'desc' | |
,'groupby' => 'modResource.id' | |
,'limit' => $limit | |
,'fastMode' => false | |
,'return' => 'data' | |
); | |
$pdoFetch->config = array_merge($pdoFetch->config, $default, $scriptProperties); | |
$pdoFetch->config['tplOuter'] = $tplOuter; | |
$output = null; | |
$rows = $pdoFetch->run(); | |
foreach ($rows as $k => $v) { | |
foreach ($v as $field => $value) { | |
$v[$field] = $value; | |
} | |
if (empty($pdoFetch->config['tpl'])) { | |
echo '<pre>'; | |
$output[] = print_r($v, true); | |
echo '</pre>'; | |
} | |
else { | |
$output[] = $pdoFetch->getChunk($pdoFetch->config['tpl'], $v, $pdoFetch->config['fastMode']); | |
} | |
} | |
$pdoFetch->addTime('Returning processed chunks'); | |
if (!empty($output)) { | |
$output = implode($pdoFetch->config['outputSeparator'], $output); | |
if (!empty($pdoFetch->config['tplOuter'])){ | |
$output = $pdoFetch->getChunk($pdoFetch->config['tplOuter'], array('rows' => $output), $pdoFetch->config['fastMode']); | |
} | |
} | |
if ($modx->user->hasSessionContext('mgr')) { | |
$output .= '<pre>' . print_r($pdoFetch->getTime(), 1) . '</pre>'; | |
} | |
$pdoFetch->timings = array(); | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment