Forked from antk25/Вывод количества товаров в категории.php
Created
October 20, 2016 07:31
-
-
Save Ibochkarev/59c276c6589c9bdff4d445f53febad73 to your computer and use it in GitHub Desktop.
Вывод количества товаров в категории minishop2
Сниппет получает сумму всех товаров в категории, с учетом мультикатегорий MS2. Можно указать нужную категорию параметром $parent.
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 | |
| if (empty($parent)) {$parent = $modx->resource->id;} | |
| $pids = array_merge(array($parent), $modx->getChildIds($parent)); | |
| $ids = array(); | |
| $q = $modx->newQuery('msProduct'); | |
| $q->where(array('class_key' => 'msProduct','parent:IN' => $pids,'published' => 1,'deleted' => 0)); | |
| $q->select('`msProduct`.`id`'); | |
| if ($q->prepare() && $q->stmt->execute()) { | |
| $ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN); | |
| } | |
| $q = $modx->newQuery('msProduct'); | |
| $q->leftJoin('msCategoryMember', 'Member', '`Member`.`product_id` = `msProduct`.`id`'); | |
| $q->where(array('class_key' => 'msProduct','Member.category_id:IN' => $pids,'published' => 1,'deleted' => 0)); | |
| $q->select('`msProduct`.`id`'); | |
| if ($q->prepare() && $q->stmt->execute()) { | |
| $ids2 = $q->stmt->fetchAll(PDO::FETCH_COLUMN); | |
| if (!empty($ids2)) { | |
| $ids = array_unique(array_merge($ids, $ids2)); | |
| } | |
| } | |
| return count($ids); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment