Подключение msOptionsColor

Добрый день,

Подключаем msOptionsColor.

Выполнили все по инструкции.

На странице Категории где функционирует фильтр отображается перечень товаров, нами из всех только двум тестовым товарам назначены шаблоны, работающие с опцией цвет, и соответственно присвоены тестовые цвета.

Опции цвета есть в фильтре на странице Категории и выбор опции работает, однако в результат фильтрации попадают ВСЕ позиции товаров, независимо от наличия/отсутствия опции цвета и товары со ВСЕМИ цветами из двух тестовых. Т.е. фильтр по цвету не учитывается в результате.

Также при сброшенном фильтре для всех вариантов опции цвет указаны одинаково по количеству ВСЕ товары на странице: белый 26 (шт,) красный 26, фиолетовый 26. А при назначенном фильтре количества на всех вариантах цветов 0, хотя все товары показываются на странице без фильтрации по цвету.

Подскажите, в какой стороне можно искать решение проблемы.

Ниже приведен код подключения и логи.

Спасибо за помощь, с Уважением.


— Вызов фильтра в шаблоне категории, феном

{$_modx->runSnippet('!mFilter2', [
				'element' => 'msProducts',
				'class' => 'msProduct',
				'showEmptyFilters' => 1,
				'parents' => 9,
				'sort'=> 'resource|pagetitle:asc',
				'limit' => 48,
				'pageLimit'=> 10,
				'showLog'=> 1,
				'tplOuter' => '@FILE chunks/mfilter_outer_staff.tpl',
				'tplPageWrapper' => '@INLINE <ul class="pagination">{$prev}{$pages}{$next}</ul>',
				'tplPageActive' => '@INLINE <li class="page-item"><span class="page-link page-link-active" >{$pageNo}</span></li>',
				'tplPage' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">{$pageNo}</a></li>',
				'tplPagePrev' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">«</a></li>',
				'tplPageNext' => '@INLINE <li class="page-item"><a class="page-link" href="{$href}">»</a></li>',
				'tplPagePrevEmpty' => '@INLINE <li class="page-item"><span class="page-link page-link-empty">«</span></li>',
				'tplPageNextEmpty' => '@INLINE <li class="page-item"><a href="" class="page-link page-link-empty">»</a></li>',
				'filters' => 'ms|vendor:vendors,
							ms|gender,
							ms|wear_type,
							ms|material,
							ms|frame_form,
							ms|construct,
							ms|size_front,
							ms|size_bridge,
							ms|size_temple,
							ms|price:number,
                    		msoc|color~value~color',
				'aliases' => 'ms|price==price' ,
				'ajaxMode' => 'default',
				'filterOptions' => '{
						"more_tpl": "<div class=\"text-center\"><button class=\"btn btn-blue btn-rounded btn_more\">Загрузить еще</button></div>"
						}',
				'tpls' => '@FILE chunks/product_tpl.tpl',
				'tplFilter.outer.default' => '@FILE chunks/filter_outer.tpl',
				'tplFilter.row.default' => '@FILE chunks/filter_row.tpl',
				'tplFilter.outer.price' => '@FILE chunks/filter_outer_price.tpl',
				'tplFilter.row.price' => '@FILE chunks/filter_row_price.tpl',
	            'tplFilter.row.msoc|color' => '@FILE chunks/tpl.mfilter2.filter.checkbox.color.tpl'
			])}

— кастомный класс на всякий случай

<?php

class msocFilters extends mse2FiltersHandler
{

    public function getMsocValues(array $tmp, array $ids)
    {
        $filters = $fields = $keys = array();
        foreach ($tmp as $v) {
            $v = explode('~', $v);
            $fields[array_shift($v)] = implode('~', $v);
            $keys = array_merge($keys, $v);
        }
        $keys = array_keys(array_flip($keys));
        $keys = array_merge(array('rid', 'key', 'value'), $keys);

        $classColor = 'msocColor';
        $classProductOption = 'msProductOption';
        $q = $this->modx->newQuery($classColor);
        $q->innerJoin($classProductOption, $classProductOption,
            "{$classProductOption}.key = {$classColor}.key AND {$classProductOption}.value = {$classColor}.value AND {$classProductOption}.product_id = {$classColor}.rid AND {$classColor}.active = 1");
        $q->where(array(
            "{$classColor}.rid:IN"         => $ids,
            "{$classProductOption}.key:IN" => array_keys($fields),
        ));

        $q->select($this->modx->getSelectColumns($classColor, $classColor, '', $keys, false));
        $tstart = microtime(true);
        if ($q->prepare() && $q->stmt->execute()) {
            $this->modx->queryTime += microtime(true) - $tstart;
            $this->modx->executedQueries++;
            while ($row = $q->stmt->fetch(PDO::FETCH_ASSOC)) {
                $key = strtolower($row['key']);

                //$value = str_replace(array_keys($row), array_values($row), $fields[$key]);

                $value = implode('~', array_intersect_key($row, array_flip(explode('~', $fields[$key]))));

                if (!is_array($filters[$key])) {
                    $filters[$key] = array();
                }
                if (isset($filters[$key][$value])) {
                    $filters[$key][$value][$row['rid']] = $row['rid'];
                } else {
                    $filters[$key][$value] = array($row['rid'] => $row['rid']);
                }
            }
        } else {
            $this->modx->log(modX::LOG_LEVEL_ERROR,
                "[mSearch2] Error on get filter params.\nQuery: " . $q->toSql() . "\nResponse: " . print_r($q->stmt->errorInfo(),
                    1));
        }

        return $filters;
    }
}

— лог при сброшенном фильтре цвета

0.0001030: pdoTools loaded.
0.0001860: Conditions prepared
0.0000260: xPDO query object created
0.0001261: leftJoined msProductData as Data
0.0000939: leftJoined msVendor as Vendor
0.0000029: Grouped by msProduct.id
0.0000339: Added selection of msProduct: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `alias_visible`, `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.0000219: Added selection of msProductData: `article`, `price`, `old_price`, `weight`, `image`, `thumb`, `vendor`, `made_in`, `new`, `popular`, `favorite`, `tags`, `color`, `size`, `source`, `diopter`, `cyl`, `ax`, `add2`, `bc`, `available`, `gender`, `wear_type`, `size_front`, `size_bridge`, `size_temple`, `material`, `frame_form`, `construct`, `sun_class`, `model_class`
0.0000131: 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.0000381: Processed additional conditions
0.0001650: Added where condition: class_key=msProduct, msProduct.id:IN(2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724), msProduct.published=1, msProduct.deleted=0
0.0000591: Sorted by `msProduct`.`pagetitle` asc, 
0.0000031: Limited to 48, offset 0
0.0002759: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `msProduct`.`id`, `msProduct`.`type`, `msProduct`.`contentType`, `msProduct`.`pagetitle`, `msProduct`.`longtitle`, `msProduct`.`description`, `msProduct`.`alias`, `msProduct`.`alias_visible`, `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`, `Data`.`diopter`, `Data`.`cyl`, `Data`.`ax`, `Data`.`add2`, `Data`.`bc`, `Data`.`available`, `Data`.`gender`, `Data`.`wear_type`, `Data`.`size_front`, `Data`.`size_bridge`, `Data`.`size_temple`, `Data`.`material`, `Data`.`frame_form`, `Data`.`construct`, `Data`.`sun_class`, `Data`.`model_class`, `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 `modx_site_content` AS `msProduct` LEFT JOIN `modx_ms2_products` `Data` ON `msProduct`.`id` =  `Data`.`id` LEFT JOIN `modx_ms2_vendors` `Vendor` ON Data.vendor=Vendor.id WHERE  ( `msProduct`.`class_key` = 'msProduct' AND `msProduct`.`id` IN (2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724) AND `msProduct`.`published` = 1 AND `msProduct`.`deleted` = 0 )  GROUP BY msProduct.id ORDER BY `msProduct`.`pagetitle` asc LIMIT 48 "
0.0043530: SQL executed
0.0001290: Total rows: 26
0.0005920: Rows fetched
0.0006959: Returning raw data
0.0007820: Checked the active modifiers
0.0037820: Created "modChunk" from file "core/elements/chunks/product_tpl.tpl"
0.0210979: Compiled Fenom chunk with name "modchunk/0034c3c23ab55c49c1c37b61237eafdc"
0.0133302: Loaded "modSnippet" with name "msGallery"
0.0425570: Loaded "modSnippet" with name "msProductOptions"
0.0118799: Loaded "modSnippet" with name "msOneClick"
0.0201211: Time to load products options
0.6839559: Total time
15 204 352: Memory usage
0.0004110: pdoTools loaded
0.0035901: Loaded "modSnippet" with name "msProducts"
0.6949899: Created inline "modChunk" with name "5f2d77515184032c7fcd46c2968e80f7"
0.0022511: Compiled Fenom chunk with name "modchunk/5f2d77515184032c7fcd46c2968e80f7"
0.7013102: Total time
15 466 496: Memory usage
0.0240920: pdoTools loaded.
0.0144961: Getting filters for saved ids: (2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724)
0.0068710: Filters retrieved.
0.0012400: Suggestions retrieved.
0.5819521: Total filter operations: 0
0.7561021: Total time
15 466 496: Memory usage
— лог при назначенном фильтре цвета (фиолетовый)

0.0001619: pdoTools loaded.
0.0001950: Conditions prepared
0.0000401: xPDO query object created
0.0001371: leftJoined msProductData as Data
0.0000808: leftJoined msVendor as Vendor
0.0000021: Grouped by msProduct.id
0.0000401: Added selection of msProduct: SQL_CALC_FOUND_ROWS `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `alias_visible`, `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.0000231: Added selection of msProductData: `article`, `price`, `old_price`, `weight`, `image`, `thumb`, `vendor`, `made_in`, `new`, `popular`, `favorite`, `tags`, `color`, `size`, `source`, `diopter`, `cyl`, `ax`, `add2`, `bc`, `available`, `gender`, `wear_type`, `size_front`, `size_bridge`, `size_temple`, `material`, `frame_form`, `construct`, `sun_class`, `model_class`
0.0000141: 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.0000401: Processed additional conditions
0.0002301: Added where condition: class_key=msProduct, msProduct.id:IN(2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724), msProduct.published=1, msProduct.deleted=0
0.0000639: Sorted by `msProduct`.`pagetitle` asc, 
0.0000019: Limited to 48, offset 0
0.0003521: SQL prepared "SELECT SQL_CALC_FOUND_ROWS `msProduct`.`id`, `msProduct`.`type`, `msProduct`.`contentType`, `msProduct`.`pagetitle`, `msProduct`.`longtitle`, `msProduct`.`description`, `msProduct`.`alias`, `msProduct`.`alias_visible`, `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`, `Data`.`diopter`, `Data`.`cyl`, `Data`.`ax`, `Data`.`add2`, `Data`.`bc`, `Data`.`available`, `Data`.`gender`, `Data`.`wear_type`, `Data`.`size_front`, `Data`.`size_bridge`, `Data`.`size_temple`, `Data`.`material`, `Data`.`frame_form`, `Data`.`construct`, `Data`.`sun_class`, `Data`.`model_class`, `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 `modx_site_content` AS `msProduct` LEFT JOIN `modx_ms2_products` `Data` ON `msProduct`.`id` =  `Data`.`id` LEFT JOIN `modx_ms2_vendors` `Vendor` ON Data.vendor=Vendor.id WHERE  ( `msProduct`.`class_key` = 'msProduct' AND `msProduct`.`id` IN (2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724) AND `msProduct`.`published` = 1 AND `msProduct`.`deleted` = 0 )  GROUP BY msProduct.id ORDER BY `msProduct`.`pagetitle` asc LIMIT 48 "
0.0037680: SQL executed
0.0001252: Total rows: 26
0.0004849: Rows fetched
0.0006630: Returning raw data
0.0004730: Checked the active modifiers
0.0040870: Created "modChunk" from file "core/elements/chunks/product_tpl.tpl"
0.0206120: Compiled Fenom chunk with name "modchunk/0034c3c23ab55c49c1c37b61237eafdc"
0.0026510: Loaded "modSnippet" with name "msGallery"
0.0361550: Loaded "modSnippet" with name "msProductOptions"
0.0181241: Loaded "modSnippet" with name "msOneClick"
0.0253181: Time to load products options
0.7771220: Total time
15 204 352: Memory usage
0.0006950: pdoTools loaded
0.0043888: Loaded "modSnippet" with name "msProducts"
0.7872801: Created inline "modChunk" with name "5f2d77515184032c7fcd46c2968e80f7"
0.0024140: Compiled Fenom chunk with name "modchunk/5f2d77515184032c7fcd46c2968e80f7"
0.7948730: Total time
15 466 496: Memory usage
0.0203729: pdoTools loaded.
0.0156779: Getting filters for saved ids: (2417,2418,2419,2420,2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,2433,2434,2435,2436,3035,3036,3037,3038,3039,4857,4859,15724)
0.0079551: Filters retrieved.
0.0020421: Suggestions retrieved.
0.6864500: Total filter operations: 0
0.8484199: Total time
15 466 496: Memory usage
ВК
18 декабря 2024, 19:52
modx.pro
238
0

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

Артур Шевченко
19 декабря 2024, 21:35
0
Попробуйте поменять
'tplFilter.row.msoc|color' => '@FILE chunks/tpl.mfilter2.filter.checkbox.color.tpl'
на
'tplFilter.row.msoc|color~value~color' => '@FILE chunks/tpl.mfilter2.filter.checkbox.color.tpl'
    ВК
    23 декабря 2024, 16:08
    0
    Добрый день, спасибо за помощь, разобрались на сайте поддержки продукта, сразу просто не увидели там продление поддержки, с Уважением.
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    2