Created
January 17, 2017 22:23
-
-
Save but1head/301b479e9f25c9a6674d90eab53a18f0 to your computer and use it in GitHub Desktop.
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 | |
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