CodeExplorer getProductCategories example
Criteria
$criteria,
Search
$search,
ShopContextInterface
$context ) { $this->
handleFilter($criteriaPart,
$criteria,
$search,
$context);
} private function addQuery(SimilarProductCondition
$criteriaPart, Search
$search): void
{ $productId =
$criteriaPart->
getProductId();
$productName =
$criteriaPart->
getProductName();
$categories =
$this->
getProductCategories($productId);
$query =
new BoolQuery();
$nameQuery =
new MultiMatchQuery(['name', 'keywords'
],
$productName,
['boost' => 5
]);
$categoriesQuery =
new TermsQuery('categoryIds',
$categories,
['boost' => 0.2
]);
$query->
add($nameQuery, BoolQuery::SHOULD
);
$query->
add($categoriesQuery, BoolQuery::MUST
);
$not =
new BoolQuery();
$not->
add(new TermQuery('id',
$productId), BoolQuery::MUST_NOT
);
$result =
[];
foreach ($products as $product) { $id =
$product->
getId();
if (!
isset($mapping[$id])) { continue;
} $ids =
explode(',',
$mapping[$id]);
$ids =
array_map('\intval',
$ids);
$productCategories =
$this->
getProductCategories( $ids,
$categories );
$result[$product->
getNumber()] =
$productCategories;
} return $result;
} /**
* {@inheritdoc}
*/