Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getChangeSets example
->
addListener
(
PreWriteValidationEvent::
class
,
function
DPreWriteValidationEvent
$event
)
: void
{
foreach
(
$event
->
getCommands
(
)
as
$command
)
{
if
(
!
$command
instanceof ChangeSetAware
)
{
continue
;
}
$command
->
requestChangeSet
(
)
;
}
}
)
;
$result
=
$this
->productRepository->
update
(
$updates
, Context::
createDefaultContext
(
)
)
;
$changeSets
=
$this
->
getChangeSets
(
ProductDefinition::ENTITY_NAME,
$result
, 2
)
;
$changeSetForProduct1
=
array_values
(
array_filter
(
$changeSets
,
function
DChangeSet
$changeSet
)
use
(
&
$productId1
)
{
return
$changeSet
->
getBefore
(
'id'
)
===
hex2bin
(
$productId1
)
;
}
)
)
[
0
]
;
$changeSetForProduct2
=
array_values
(
array_filter
(
$changeSets
,
function
DChangeSet
$changeSet
)
use
(
&
$productId2
)
{
return
$changeSet
->
getBefore
(
'id'
)
===
hex2bin
(
$productId2
)
;
}
)
)
[
0
]
;
static
::
assertNotNull
(
$changeSetForProduct1
)
;
static
::
assertTrue
(
$changeSetForProduct1
->
hasChanged
(
'stock'
)
)
;
static
::
assertEquals
(
1,
$changeSetForProduct1
->
getBefore
(
'stock'
)
)
;
static
::
assertEquals
(
100,
$changeSetForProduct1
->
getAfter
(
'stock'
)
)
;