Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getAffectedIds example
public
static
function
getSubscribedEvents
(
)
: array
{
return
[
PreWriteValidationEvent::
class
=>
'preValidate',
PostWriteValidationEvent::
class
=>
'postValidate',
]
;
}
public
function
postValidate
(
PostWriteValidationEvent
$event
)
: void
{
$commands
=
$event
->
getCommands
(
)
;
$affectedIds
=
$this
->
getAffectedIds
(
$commands
)
;
if
(
\
count
(
$affectedIds
)
=== 0
)
{
return
;
}
$violations
=
new
ConstraintViolationList
(
)
;
$violations
->
addAll
(
$this
->
getInheritanceViolations
(
$affectedIds
)
)
;
$violations
->
addAll
(
$this
->
getMissingTranslationCodeViolations
(
$affectedIds
)
)
;
if
(
$violations
->
count
(
)
> 0
)
{
$event
->
getExceptions
(
)
->
add
(
new
WriteConstraintViolationException
(
$violations
)
)
;
}
}
if
(
$event
->
getContext
(
)
->
getVersionId
(
)
!== Defaults::LIVE_VERSION
)
{
return
;
}
$ids
=
$event
->
getIds
(
'order_line_item'
)
;
if
(
!
$ids
)
{
return
;
}
$ids
=
$this
->
getAffectedIds
(
$event
)
;
if
(
empty
(
$ids
)
)
{
return
;
}
$beforeLineItems
=
$this
->
fetchOrderLineItems
(
$ids
)
;
$context
=
$event
->
getContext
(
)
;
$event
->
addSuccess
(
function
D
)
use
(
$ids
,
$beforeLineItems
,
$context
)
: void
{
$afterLineItems
=
$this
->
fetchOrderLineItems
(
$ids
)
;