Skip to content

Instantly share code, notes, and snippets.

@but1head
Created January 17, 2017 22:23
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 but1head/301b479e9f25c9a6674d90eab53a18f0 to your computer and use it in GitHub Desktop.
Save but1head/301b479e9f25c9a6674d90eab53a18f0 to your computer and use it in GitHub Desktop.
<?php
class mstoFilters extends mse2FiltersHandler{
public function getMstoValues(array $fields, array $ids){
$this->modx->getService('msto', 'msto', $this->modx->getOption('msto_core_path', null, $this->modx->getOption('core_path') . 'components/msto/') . 'model/msto/');
$filters = array();
$q = $this->modx->newQuery('mstoOffer');
$q->where(array(
'product_id:IN' => $ids,
));
$q->select('product_id,' . implode(',', $fields));
$tstart = microtime(true);
if ($q->prepare() && $q->stmt->execute()) {
$this->modx->queryTime += microtime(true) - $tstart;
$this->modx->executedQueries++;
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
foreach ($row as $k => $v) {
$v = trim($v);
if ($v == '' || $k == 'product_id') {
continue;
} else if (isset($filters[$k][$v])) {
$filters[$k][$v][] = $row['product_id'];
} else {
$filters[$k][$v] = array($row['product_id']);
}
}
}
} else {
$this->modx->log(modX::LOG_LEVEL_ERROR, "[mSearch2] Error on get filter params.\nQuery: " . $q->toSql() . "\nResponse: " . print_r($q->stmt->errorInfo(), 1));
}
return $filters;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment