Вывести товары с определённым значением TV их категорий

Здравствуйте.
Необходимо вывести все товары, категории которых имеют определённое значение TV (TV называется 'categoryYandexProductsAndPricesEnabled' и должно иметь значение 1).

Пробую так:
{'msProducts' | snippet : [
	'templates' => 3,
	'limit' => 0,
	'parents' => 0,
	'tpl' => 'yandexProductsAndPricesOffer',
	'leftJoin' => [
		'parentCategory' => [
			'class' => 'msCategory',
			'on' => 'msProduct.parent = parentCategory.id'
		]
	],
	'select' => [
		'msProduct' => '*',
		'parentCategory' => '*'
	],
	'where' => [
		'parentCategory.categoryYandexProductsAndPricesEnabled:=' => 1
	],
	'showLog' => 1
]}
Log:
0.0000839: pdoTools loaded.
0.0005710: Conditions prepared
0.0000300: xPDO query object created
0.0001609: leftJoined msProductData as Data
0.0001080: leftJoined msVendor as Vendor
0.0001070: leftJoined msCategory as parentCategory
0.0000031: Grouped by msProduct.id
0.0002050: Added selection of msProduct: `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `content`, `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.0000720: Added selection of msProductData: `article`, `price`, `old_price`, `weight`, `image`, `thumb`, `vendor`, `made_in`, `new`, `popular`, `favorite`, `tags`, `color`, `size`, `source`, `purchasingPriceCustom`, `capacityCustom`, `materialCustom`, `formCustom`, `pictureCustom`, `smallDescriptionCustom`, `viewsCountCustom`, `soldCountCustom`
0.0000601: 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.0001431: Added selection of msCategory: `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `content`, `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.0000269: Processed additional conditions
0.0001919: Added where condition: class_key=msProduct, parentCategory.categoryYandexProductsAndPricesEnabled:==1, msProduct.template:IN(3), msProduct.published=1, msProduct.deleted=0
0.0000610: Sorted by msProduct.id, ASC
0.0005100: SQL prepared "SELECT `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`.`content`, `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`.`purchasingPriceCustom`, `Data`.`capacityCustom`, `Data`.`materialCustom`, `Data`.`formCustom`, `Data`.`pictureCustom`, `Data`.`smallDescriptionCustom`, `Data`.`viewsCountCustom`, `Data`.`soldCountCustom`, `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`, `parentCategory`.`id`, `parentCategory`.`type`, `parentCategory`.`contentType`, `parentCategory`.`pagetitle`, `parentCategory`.`longtitle`, `parentCategory`.`description`, `parentCategory`.`alias`, `parentCategory`.`link_attributes`, `parentCategory`.`published`, `parentCategory`.`pub_date`, `parentCategory`.`unpub_date`, `parentCategory`.`parent`, `parentCategory`.`isfolder`, `parentCategory`.`introtext`, `parentCategory`.`content`, `parentCategory`.`richtext`, `parentCategory`.`template`, `parentCategory`.`menuindex`, `parentCategory`.`searchable`, `parentCategory`.`cacheable`, `parentCategory`.`createdby`, `parentCategory`.`createdon`, `parentCategory`.`editedby`, `parentCategory`.`editedon`, `parentCategory`.`deleted`, `parentCategory`.`deletedon`, `parentCategory`.`deletedby`, `parentCategory`.`publishedon`, `parentCategory`.`publishedby`, `parentCategory`.`menutitle`, `parentCategory`.`donthit`, `parentCategory`.`privateweb`, `parentCategory`.`privatemgr`, `parentCategory`.`content_dispo`, `parentCategory`.`hidemenu`, `parentCategory`.`class_key`, `parentCategory`.`context_key`, `parentCategory`.`content_type`, `parentCategory`.`uri`, `parentCategory`.`uri_override`, `parentCategory`.`hide_children_in_tree`, `parentCategory`.`show_in_tree`, `parentCategory`.`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 LEFT JOIN `modx_site_content` `parentCategory` ON msProduct.parent = parentCategory.id WHERE  ( `msProduct`.`class_key` = 'msProduct' AND `parentCategory`.`categoryYandexProductsAndPricesEnabled` = '1' AND `msProduct`.`template` IN (3) AND `msProduct`.`published` = 1 AND `msProduct`.`deleted` = 0 )  GROUP BY msProduct.id ORDER BY msProduct.id ASC "
0.0007620: Could not process query, error #1054: Unknown column 'parentCategory.categoryYandexProductsAndPricesEnabled' in 'where clause'
0.0032358: Total time
6 291 456: Memory usage
Вижу, что поля categoryYandexProductsAndPricesEnabled нет в выборке msCategory (у категорий есть и другие TV, их тоже нет в выборке).
Как подключить TV categoryYandexProductsAndPricesEnabled?
Александр
18 мая 2018, 16:28
modx.pro
1 235
0

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

Александр
23 мая 2018, 09:40
0
Здравствуйте.
Может быть у кого-нибудь была похожая ситуация? Подскажите, пожалуйста, в чём может быть дело.
    Александр
    23 мая 2018, 14:26
    +2
    Здравствуйте. Не проверял, но нужно дополнительно присоединить таблицу с TV для родителя. Что-то такое:
    {'msProducts' | snippet : [
    	'templates' => 3,
    	'limit' => 0,
    	'parents' => 0,
    	'tpl' => 'yandexProductsAndPricesOffer',
    	'leftJoin' => [
    		'parentCategory' => [
    			'class' => 'msCategory',
    			'on' => 'msProduct.parent = parentCategory.id'
    		],
    		'parentCategoryTV' => [
    			'class' => 'modTemplateVar',
    			'on' => 'parentCategoryTV.id=parentCategoryTVvalue.tmplvarid'
    		],
    		'parentCategoryTVvalue' => [
    			'class' => 'modTemplateVarResource',
    			'on' => 'parentCategoryTV.contentid=parentCategory.id'
    		]
    	],
    	'select' => [
    		'msProduct' => '*',
    		'parentCategory' => '*',
    		'parentCategoryTVvalue' => '*'
    	],
    	'where' => [
    		'parentCategoryTVvalue.categoryYandexProductsAndPricesEnabled:=' => 1
    	],
    	'showLog' => 1
    ]}
      Александр
      23 мая 2018, 18:36
      +1
      Вы правы, спасибо большое!
      Вот, что получилось:
      {'msProducts' | snippet : [
      	'templates' => 3,
      	'limit' => 0,
      	'parents' => 0,
      	'tpl' => 'yandexProductsAndPricesOffer',
      	'leftJoin' => [
      		'parentCategory' => [
      			'class' => 'msCategory',
      			'on' => 'msProduct.parent = parentCategory.id'
      		],
      		'parentCategoryTVValue' => [
      			'class' => 'modTemplateVarResource',
      			'on' => 'parentCategory.id = parentCategoryTVValue.contentid'
      		],
      		'parentCategoryTV' => [
      			'class' => 'modTemplateVar',
      			'on' => 'parentCategoryTVValue.tmplvarid = parentCategoryTV.id'
      		]
      	],
      	'select' => [
      		'msProduct' => '*',
      		'parentCategoryTV' => 'name',
      		'parentCategoryTVValue' => 'value'
      	],
      	'where' => [
      		'parentCategoryTV.name:=' => 'categoryYandexProductsAndPricesEnabled',
      		'parentCategoryTVValue.value:=' => 1
      	]
      ]}
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    3