Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
fetchListing example
$this
->
getContainer
(
)
->
get
(
'event_dispatcher'
)
->
addListener
(
ProductListingResolvePreviewEvent::
class
,
$listener
)
;
$context
=
$this
->
getContainer
(
)
->
get
(
SalesChannelContextFactory::
class
)
->
create
(
Uuid::
randomHex
(
)
, TestDefaults::SALES_CHANNEL
)
;
$criteria
=
new
Criteria
(
$ids
->
getList
(
[
'p1'
]
)
)
;
$this
->productListingLoader->
load
(
$criteria
,
$context
)
;
}
public
function
testMainVariant
(
)
: void
{
$this
->
createProduct
(
[
]
, true
)
;
$listing
=
$this
->
fetchListing
(
)
;
static
::
assertEquals
(
1,
$listing
->
getTotal
(
)
)
;
$mainVariant
=
$listing
->
getEntities
(
)
->
first
(
)
;
static
::
assertNotNull
(
$mainVariant
)
;
static
::
assertEquals
(
$this
->mainVariantId,
$mainVariant
->
getId
(
)
)
;
static
::
assertContains
(
$this
->optionIds
[
'red'
]
,
$mainVariant
->
getOptionIds
(
)
?:
[
]
)
;
static
::
assertContains
(
$this
->optionIds
[
'l'
]
,
$mainVariant
->
getOptionIds
(
)
?:
[
]
)
;
static
::
assertTrue
(
$mainVariant
->
hasExtension
(
'search'
)
)
;
$this
->repository =
$this
->
getContainer
(
)
->
get
(
'product.repository'
)
;
$this
->connection =
$this
->
getContainer
(
)
->
get
(
Connection::
class
)
;
parent::
setUp
(
)
;
}
public
function
testSingleGroup
(
)
: void
{
$this
->
createProduct
(
[
'color'
]
)
;
$listing
=
$this
->
fetchListing
(
)
;
static
::
assertCount
(
2,
$listing
->ids
)
;
static
::
assertContains
(
$this
->optionIds
[
'green'
]
,
$listing
->optionIds
)
;
static
::
assertContains
(
$this
->optionIds
[
'red'
]
,
$listing
->optionIds
)
;
}
public
function
testTwoGroups
(
)
: void
{
$this
->
createProduct
(
[
'color', 'size'
]
)
;