Created
September 5, 2016 14:14
-
-
Save antk25/7049f5efb18797c340eff1174d22d67c to your computer and use it in GitHub Desktop.
Вывод производителей товаров MS2
Сниппет получает всех производителей, у которых есть хоть один активный товар и выводит в виде селектбокса.
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 | |
$q = $modx->newQuery('msVendor'); | |
$q->innerJoin('msProductData', 'msProductData', '`msProductData`.`vendor` = `msVendor`.`id`'); | |
$q->innerJoin('msProduct', 'msProduct', array( | |
'`msProductData`.`id` = `msProduct`.`id`', | |
'msProduct.deleted' => 0, | |
'msProduct.published' => 1 | |
)); | |
$q->groupby('msVendor.id'); | |
$q->sortby('name','ASC'); | |
$q->select(array('msVendor.id', 'name')); | |
$options = '<option value="0">Нет</option>'; | |
if ($q->prepare() && $q->stmt->execute()) { | |
while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) { | |
$options .= '<option value="'.$row['id'].'">'.$row['name'].'</option>'; | |
} | |
} | |
return '<select name="vendors">'.$options.'</select>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment