Skip to content

Instantly share code, notes, and snippets.

@maxout
Last active March 1, 2022 08:08
Show Gist options
  • Save maxout/97ea094c5be78b259944f2dd18cfe778 to your computer and use it in GitHub Desktop.
Save maxout/97ea094c5be78b259944f2dd18cfe778 to your computer and use it in GitHub Desktop.
Shopware: The following example selects a list of products assigned to the category with id 3 and sorts the result set by the cheapest price.
$criteria = new Criteria();
$criteria->limit(10);
$criteria->addCondition(new CategoryCondition([3]));
$criteria->addSorting(new PriceSorting());
$context = $this->get('shopware_storefront.context_service')->getShopContext();
$service = $this->get('shopware_search.product_number_search');
/**@var $result ProductNumberSearchResult*/
$result = $service->search($criteria, $context);
$numbers = [];
foreach($result->getProducts() as $product) {
$numbers[] = $product->getNumber();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment