因此,首先,要在 Akeneo 中查询产品,您应该使用Product Query Builder (PQB)。如果您使用的是 1.6,这里是使用它的文档的链接,它非常简单:https ://docs.akeneo.com/1.6/cookbook/catalog/product/query.html
要获得可与 PQB 一起使用的属性和字段过滤器的详尽列表,您可以php app/console pim:product:query-help
在 PIM 上使用该命令。
正如您所注意到的,族不是属性而是字段,您可以在上面命令的字段过滤器中找到它:
php app/console pim:product:query-help
Useable field filters...
+-----------------+--------------------------------+-----------------------------------------------------------+
| field | operators | filter_class |
+-----------------+--------------------------------+-----------------------------------------------------------+
| family | IN, NOT IN, EMPTY, NOT EMPTY | Pim\Bundle\CatalogBundle\Doctrine\ORM\Filter\FamilyFilter |
| family.id | IN, NOT IN, EMPTY, NOT EMPTY | Pim\Bundle\CatalogBundle\Doctrine\ORM\Filter\FamilyFilter |
| family.code | IN, NOT IN, EMPTY, NOT EMPTY | Pim\Bundle\CatalogBundle\Doctrine\ORM\Filter\FamilyFilter |
+-----------------+--------------------------------+-----------------------------------------------------------+
您现在可以看到您可以在该family.code
字段上进行搜索。
对于你的例子,你最终会得到这样的东西:
<?php
// Get a new instance of the PQB
$pqbFactory = $this->getContainer()->get('pim_catalog.query.product_query_builder_factory');
$pqb = $pqbFactory->create([
'default_locale' => 'en_US',
'default_scope' => 'ecommerce'
]);
// Now you can search for products with your family codes
$pqb->addFilter(
'family.code',
'IN',
['projector', 'projector_child', 'projector_parent']
);
// Retrieve your products
$productsCursor = $pqb->execute();
foreach ($productsCursor as $product) {
// your custom logic
}