Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CartVerifyPersistEvent example
$this
->eventDispatcher->
dispatch
(
new
CartLoadedEvent
(
$cart
,
$context
)
)
;
return
$cart
;
}
public
function
save
(
Cart
$cart
, SalesChannelContext
$context
)
: void
{
$shouldPersist
=
$this
->
shouldPersist
(
$cart
)
;
$this
->eventDispatcher->
dispatch
(
new
CartSavedEvent
(
$context
,
$cart
)
)
;
$event
=
new
CartVerifyPersistEvent
(
$context
,
$cart
,
$shouldPersist
)
;
$this
->eventDispatcher->
dispatch
(
$event
)
;
if
(
!
$event
->
shouldBePersisted
(
)
)
{
$this
->
delete
(
$cart
->
getToken
(
)
,
$context
)
;
return
;
}
$content
=
$this
->
serializeCart
(
$cart
,
$context
)
;
$this
->redis->
set
(
self::PREFIX .
$cart
->
getToken
(
)
,
$content
,
[
'EX' =>
$this
->expireDays * 86400
]
)
;
}
/** * @throws InvalidUuidException */
public
function
save
(
Cart
$cart
, SalesChannelContext
$context
)
: void
{
if
(
$cart
->
getBehavior
(
)
?->
isRecalculation
(
)
)
{
return
;
}
$shouldPersist
=
$this
->
shouldPersist
(
$cart
)
;
$event
=
new
CartVerifyPersistEvent
(
$context
,
$cart
,
$shouldPersist
)
;
$this
->eventDispatcher->
dispatch
(
$event
)
;
if
(
!
$event
->
shouldBePersisted
(
)
)
{
$this
->
delete
(
$cart
->
getToken
(
)
,
$context
)
;
return
;
}
$payloadExists
=
$this
->
payloadExists
(
)
;
$sql
= <<<'SQL'