Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CountSorting example
}
public
function
testFilterIdsWithAggregatedSorting
(
)
: void
{
$this
->
prepareTestData
(
)
;
$criteria
=
new
Criteria
(
)
;
$criteria
->
addFilter
(
new
NotFilter
(
NotFilter::CONNECTION_AND,
[
new
EqualsFilter
(
'categories.id', null
)
,
]
)
)
;
$criteria
->
addSorting
(
new
CountSorting
(
'categories.id', FieldSorting::DESCENDING
)
)
;
$filteredTagIdsStruct
=
$this
->filterTagIdsService->
filterIds
(
new
Request
(
)
,
$criteria
,
Context::
createDefaultContext
(
)
)
;
static
::
assertEquals
(
5,
$filteredTagIdsStruct
->
getTotal
(
)
)
;
static
::
assertEquals
(
[
$this
->ids->
get
(
'e'
)
,
/** * @depends testIndexing */
public
function
testSortByPropertiesCount
(
IdsCollection
$ids
)
: void
{
$context
=
$this
->context;
try
{
$criteria
=
new
Criteria
(
)
;
$criteria
->
addState
(
Criteria::STATE_ELASTICSEARCH_AWARE
)
;
$criteria
->
addSorting
(
new
CountSorting
(
'properties.id', CountSorting::DESCENDING
)
)
;
$criteria
->
addSorting
(
new
FieldSorting
(
'productNumber', FieldSorting::ASCENDING
)
)
;
$searcher
=
$this
->
createEntitySearcher
(
)
;
$result
=
$searcher
->
search
(
$this
->productDefinition,
$criteria
,
$context
)
->
getIds
(
)
;
static
::
assertSame
(
$ids
->
get
(
'dal-1'
)
,
$result
[
0
]
)
;
static
::
assertSame
(
$ids
->
get
(
'dal-2.1'
)
,
$result
[
1
]
)
;
static
::
assertSame
(
$ids
->
get
(
'dal-2.2'
)
,
$result
[
2
]
)
;
static
::
assertSame
(
$ids
->
get
(
'product-1'
)
,
$result
[
3
]
)
;
static
::
assertSame
(
$ids
->
get
(
'product-2'
)
,
$result
[
4
]
)
;
static
::
assertTrue
(
$criteria
->
hasAssociation
(
'prices'
)
)
;
$nested
=
$criteria
->
getAssociation
(
'prices'
)
;
static
::
assertCount
(
1,
$nested
->
getFilters
(
)
)
;
static
::
assertCount
(
1,
$nested
->
getSorting
(
)
)
;
}
public
function
testCriteriaToArray
(
)
: void
{
$criteria
=
(
new
Criteria
(
)
)
->
addSorting
(
new
FieldSorting
(
'order.createdAt', FieldSorting::DESCENDING
)
)
->
addSorting
(
new
CountSorting
(
'transactions.id', CountSorting::ASCENDING
)
)
->
addAssociation
(
'transactions.paymentMethod'
)
->
addAssociation
(
'deliveries.shippingMethod'
)
->
setLimit
(
1
)
->
setOffset
(
(
1 - 1
)
* 1
)
->
setTotalCountMode
(
100
)
;
$criteria
->
getAssociation
(
'transaction'
)
->
addSorting
(
new
FieldSorting
(
'createdAt', FieldSorting::DESCENDING
)
)
;
$criteriaArray
=
$this
->requestCriteriaBuilder->
toArray
(
$criteria
)
;
$testArray
=
[