msGallery перебивает msProducts - почему?

Задача: вывести в каталоге товары с 2-мя полными галереями (одна с превьюшками 15x15 в одном месте, а другая с крупными превьюшками в другом месте того же чанка товара).

Проблема: при добавлении вызова msGallery в чанк товара с указанием id этого товара сама выборка всех товаров стопорится и выводит только 1 товар.

Подробнее:

Выборка товаров:
{'!msProducts'|snippet:[
    'tpl' => 'tpl.msProducts.row.card',                                    
    'limit' => 20,
    'sortby' => 'menuindex',
    'showLog' => 1,
]}
вызов галереи в чанке
{'!msGallery'|snippet:[
    'product' => $id,
]}
showLog без подключения галереи:
0.0007920: pdoTools loaded.
0.0000911: Conditions prepared
0.0000272: xPDO query object created
0.0000930: leftJoined msProductData as Data
0.0000629: leftJoined msVendor as Vendor
0.0000010: Grouped by msProduct.id
0.0000181: Added selection of msProduct: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`
0.0000091: Added selection of msProductData: `article`, `price`, `old_price`, `weight`, `image`, `thumb`, `vendor`, `made_in`, `new`, `popular`, `favorite`, `tags`, `color`, `size`, `source`
0.0000069: Added selection of msVendor: `name` AS `vendor.name`, `resource` AS `vendor.resource`, `country` AS `vendor.country`, `logo` AS `vendor.logo`, `address` AS `vendor.address`, `phone` AS `vendor.phone`, `fax` AS `vendor.fax`, `email` AS `vendor.email`, `description` AS `vendor.description`, `properties` AS `vendor.properties`
0.0003569: Processed additional conditions
0.0004601: Added where condition: class_key=msProduct, msProduct.parent:IN(1,3,4,5,2,6,7), msProduct.published=1, msProduct.deleted=0
0.0000300: Sorted by msProduct.menuindex, ASC
0.0000010: Limited to 20, offset 0
0.0001862: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `msProduct`.`id`, `msProduct`.`type`, `msProduct`.`contentType`, `msProduct`.`pagetitle`, `msProduct`.`longtitle`, `msProduct`.`description`, `msProduct`.`alias`, `msProduct`.`link_attributes`, `msProduct`.`published`, `msProduct`.`pub_date`, `msProduct`.`unpub_date`, `msProduct`.`parent`, `msProduct`.`isfolder`, `msProduct`.`introtext`, `msProduct`.`richtext`, `msProduct`.`template`, `msProduct`.`menuindex`, `msProduct`.`searchable`, `msProduct`.`cacheable`, `msProduct`.`createdby`, `msProduct`.`createdon`, `msProduct`.`editedby`, `msProduct`.`editedon`, `msProduct`.`deleted`, `msProduct`.`deletedon`, `msProduct`.`deletedby`, `msProduct`.`publishedon`, `msProduct`.`publishedby`, `msProduct`.`menutitle`, `msProduct`.`donthit`, `msProduct`.`privateweb`, `msProduct`.`privatemgr`, `msProduct`.`content_dispo`, `msProduct`.`hidemenu`, `msProduct`.`class_key`, `msProduct`.`context_key`, `msProduct`.`content_type`, `msProduct`.`uri`, `msProduct`.`uri_override`, `msProduct`.`hide_children_in_tree`, `msProduct`.`show_in_tree`, `msProduct`.`properties`, `Data`.`article`, `Data`.`price`, `Data`.`old_price`, `Data`.`weight`, `Data`.`image`, `Data`.`thumb`, `Data`.`vendor`, `Data`.`made_in`, `Data`.`new`, `Data`.`popular`, `Data`.`favorite`, `Data`.`tags`, `Data`.`color`, `Data`.`size`, `Data`.`source`, `Vendor`.`name` AS `vendor.name`, `Vendor`.`resource` AS `vendor.resource`, `Vendor`.`country` AS `vendor.country`, `Vendor`.`logo` AS `vendor.logo`, `Vendor`.`address` AS `vendor.address`, `Vendor`.`phone` AS `vendor.phone`, `Vendor`.`fax` AS `vendor.fax`, `Vendor`.`email` AS `vendor.email`, `Vendor`.`description` AS `vendor.description`, `Vendor`.`properties` AS `vendor.properties` FROM `1z6fJ8nTV9NY_site_content` AS `msProduct` LEFT JOIN `1z6fJ8nTV9NY_ms2_products` `Data` ON `msProduct`.`id` =  `Data`.`id` LEFT JOIN `1z6fJ8nTV9NY_ms2_vendors` `Vendor` ON Data.vendor=Vendor.id WHERE  ( `msProduct`.`class_key` = 'msProduct' AND `msProduct`.`parent` IN (1,3,4,5,2,6,7) AND `msProduct`.`published` = 1 AND `msProduct`.`deleted` = 0 )  GROUP BY msProduct.id ORDER BY msProduct.menuindex ASC LIMIT 20 "
0.0005751: SQL executed
0.0000861: Total rows: 6
0.0000260: Rows fetched
0.0000632: Returning raw data
0.0002558: Checked the active modifiers
0.0008931: Loaded "modChunk" with name "tpl.msProducts.row.card"
0.0009580: Compiled Fenom chunk with name "modchunk/22"
0.0019603: Time to load products options
0.0735221: Total time
6 291 456: Memory usage
showLog с галереей:
0.0004411: pdoTools loaded.
0.0004699: Conditions prepared
0.0000119: xPDO query object created
0.0000250: Added selection of msProductFile: SQL_CALC_FOUND_ROWS `id`, `product_id`, `source`, `parent`, `name`, `description`, `path`, `file`, `type`, `createdon`, `createdby`, `rank`, `url`, `properties`, `hash`
0.0000381: Added where condition: product_id=3, parent=0
0.0000210: Sorted by msProductFile.rank, ASC
0.0000730: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `msProductFile`.`id`, `msProductFile`.`product_id`, `msProductFile`.`source`, `msProductFile`.`parent`, `msProductFile`.`name`, `msProductFile`.`description`, `msProductFile`.`path`, `msProductFile`.`file`, `msProductFile`.`type`, `msProductFile`.`createdon`, `msProductFile`.`createdby`, `msProductFile`.`rank`, `msProductFile`.`url`, `msProductFile`.`properties`, `msProductFile`.`hash` FROM `1z6fJ8nTV9NY_ms2_product_files` AS `msProductFile` WHERE  ( `msProductFile`.`product_id` = 3 AND `msProductFile`.`parent` = 0 )  ORDER BY msProductFile.rank ASC "
0.0000260: SQL executed
0.0000372: Total rows: 3
0.0000069: Rows fetched
0.0000150: Returning raw data
0.0000010: Fetching thumbnails
0.0011487: Time to load products options
0.0603931: Total time
6 291 456: Memory usage

Почему так происходит?
Судя по логам, при подключении галереи в чанке, вызов msProducts превращается в вызов msGallery????
Василий Столейков
15 декабря 2016, 08:59
modx.pro
1
3 063
0
Поблагодарить автора Отправить деньги

Комментарии: 12

Василий Столейков
15 декабря 2016, 18:43
1
0
Что можно сделать в таком случае? Уже кажется перепробовал все варианты…
    Василий Столейков
    15 декабря 2016, 19:43
    1
    0
    Короче на феноме не завелось…
    Пришлось вызовы галерей переписать на modx-теги
    [[!msGallery?
        &tpl=`tpl.gallery.card`
        &product=`[[+id]]`
    ]]
      nekto
      09 марта 2017, 13:07
      0
      На modx-тегах у меня тоже не заводится…
      Подскажите решение, если есть, пожалуйста.
        Василий Столейков
        09 марта 2017, 13:09
        1
        +1
        У меня там был весь сайт на феноме, а только этот вызов msGallery на modx-синтаксисе. Возможно сработало именно благодаря такому гибриду.
      Илья Уткин
      09 марта 2017, 13:52
      1
      +1
      Хм… Подтверждаю, проблема действительно воспроизводится…

      Если нужно быстрое решение, придётся просто написать свой сниппет для выборки нужных картинок — типа такого:
      <?php
      $product = empty($product) ? $modx->resource->id : $product;
      $miniShop2 = $modx->getService('minishop2');
      $q = $modx->newQuery('msProductFile', array('parent' => 0, 'product_id' => $product));
      $q->sortby('rank','ASC');
      $q->prepare();
      $q->stmt->execute();
      $res = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
      $output = array();
      foreach($res as $r) {
          $output[] = $modx->getChunk('tpl.gal');
      }
      return implode(PHP_EOL, $output);
        Василий Наумкин
        09 марта 2017, 13:59
        +1
        Думаю, проблема в том, что msGallery получает текущий экземпляр pdoFetch и меняет его параметры
        $pdoFetch = $modx->getService('pdoFetch');
        $pdoFetch->setConfig($scriptProperties);

        В то время как ms2Gallery делает умнее:
        if (!$modx->loadClass('pdofetch', MODX_CORE_PATH . 'components/pdotools/model/pdotools/', false, true)) {
            return false;
        }
        $pdoFetch = new pdoFetch($modx, $scriptProperties);
        То есть, создаёт свой экземпляр и никому не мешает.

        Кому не лень — проверьте, пожалуйста, и пришлите PR в репозиторий ms2.
      Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
      12