Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
BeforeLineItemAddedEvent example
foreach
(
$items
as
$item
)
{
if
(
$request
->
getClientIp
(
)
!== null
)
{
$cacheKey
=
(
$item
->
getReferencedId
(
)
??
$item
->
getId
(
)
)
. '-' .
$request
->
getClientIp
(
)
;
$this
->rateLimiter->
ensureAccepted
(
RateLimiter::CART_ADD_LINE_ITEM,
$cacheKey
)
;
}
$alreadyExists
=
$cart
->
has
(
$item
->
getId
(
)
)
;
$cart
->
add
(
$item
)
;
$this
->eventDispatcher->
dispatch
(
new
BeforeLineItemAddedEvent
(
$item
,
$cart
,
$context
,
$alreadyExists
)
)
;
}
$cart
->
markModified
(
)
;
$cart
=
$this
->cartCalculator->
calculate
(
$cart
,
$context
)
;
$this
->cartPersister->
save
(
$cart
,
$context
)
;
$this
->eventDispatcher->
dispatch
(
new
AfterLineItemAddedEvent
(
$items
,
$cart
,
$context
)
)
;
$this
->eventDispatcher->
dispatch
(
new
CartChangedEvent
(
$cart
,
$context
)
)
;
return
new
CartResponse
(
$cart
)
;
}