-
-
Save TITAN-UZ/5ac882f17c0790067500c8740d9d5772 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, 0); | |
| $depth = $modx->getOption('depth', $scriptProperties, 10); | |
| $limit = $modx->getOption('limit', $scriptProperties, 100); | |
| $tplOuter = $modx->getOption('tplOuter', $scriptProperties, '@INLINE <select name="[[+name]]" class="[[+class]]">[[+rows]]</select>'); | |
| $tplRow = $modx->getOption('tplRow', $scriptProperties, '@INLINE <option value="[[+id]]">[[+name]]</option>'); | |
| $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'); | |
| $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