-
-
Save webinmd/5f4d021621259c142656e0025898b8a5 to your computer and use it in GitHub Desktop.
Snippet for MiniShop2. Get vendors from category. - Вывод брендов для категории товаров
This file contains hidden or 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 | |
$pdo = $modx->getService('pdoTools'); | |
$fieldName = $modx->getOption('fieldName', $scriptProperties, 'vendor'); | |
$fieldClass = $modx->getOption('fieldClass', $scriptProperties, ''); | |
$firstOption = $modx->getOption('firstOption', $scriptProperties, ''); | |
$parent = $modx->getOption('parent', $scriptProperties, $modx->resource->get('id')); | |
$depth = $modx->getOption('depth', $scriptProperties, 10); | |
$limit = $modx->getOption('limit', $scriptProperties, 100); | |
$tplOuter = $modx->getOption('tplOuter', $scriptProperties, '@INLINE <ul class="brands">[[+rows]]</ul>'); | |
$tplRow = $modx->getOption('tplRow', $scriptProperties, '@INLINE <li><a href="[[~[[+resource]]]]">[[+name]]</a></li>'); | |
$q = $modx->newQuery('msProduct'); | |
$q->innerJoin('msProductData', 'Data', 'msProduct.id = Data.id'); | |
$q->innerJoin('msVendor', 'Vendor', 'Data.vendor = Vendor.id'); | |
$q->leftJoin('msCategoryMember', 'Member', 'Member.product_id = msProduct.id'); | |
$q->select('Vendor.id, Vendor.name, Vendor.resource, Vendor.logo'); | |
$q->groupby('Vendor.id'); | |
$q->sortby('Vendor.name'); | |
$q->limit($limit); | |
$parents = $modx->getChildIds($parent, $depth); | |
$parents[] = $parent; | |
$q->where(array('msProduct.parent:IN' => $parents)); | |
$q->orCondition(array('Member.category_id:IN' => $parents)); | |
$options = ''; | |
if (!empty($firstOption)) { | |
$options .= $pdo->getChunk($tplRow, array( | |
'id' => '', | |
'name' => $firstOption | |
)); | |
} | |
if ($q->prepare() && $q->stmt->execute()) { | |
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) { | |
$options .= $pdo->getChunk($tplRow, $row); | |
} | |
} | |
$output = $pdo->getChunk($tplOuter, array( | |
'name' => $fieldName, | |
'class' => $fieldClass, | |
'rows' => $options, | |
)); | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment