Skip to content

Instantly share code, notes, and snippets.

@qwertik17
Created June 17, 2020 07:00
Show Gist options
  • Save qwertik17/35772e193d7cf359d7beff6e568fff0b to your computer and use it in GitHub Desktop.
Save qwertik17/35772e193d7cf359d7beff6e568fff0b to your computer and use it in GitHub Desktop.
Поиск всех производителей в подкаталоге
<?php
$parent = 12791;
$parents = array_merge([$parent], $modx->getChildIds($parent, 10, ['context' => 'web']));
$template = [28];
$pdo = $modx->getService('pdoFetch');
$results = $pdo->getCollection('msProduct', [], [
'leftJoin' => [
'msProductData' => [
'class' => 'msProductData',
'on' => 'msProduct.id = msProductData.id'
],
'msVendor' => [
'class' => 'msVendor',
'on' => 'msProductData.vendor = msVendor.id'
]
],
'where' => [
'msProduct.parent:IN' => $parents,
'msProduct.template:IN' => $template
],
'groupby' => 'msVendor.name',
'select' => [
'msProduct' => 'id',
'msProductData' => 'vendor',
'msVendor' => 'msVendor.name AS vendor_name',
],
]
);
echo count($results);
foreach ($results as $result)
{
print_r($result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment