Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getPersistent example
$cart
->
setRuleIds
(
$context
->
getRuleIds
(
)
)
;
return
$cart
;
}
, 'cart'
)
;
}
private
function
runProcessors
(
Cart
$original
, Cart
$cart
, SalesChannelContext
$context
, CartBehavior
$behavior
)
: void
{
if
(
$original
->
getLineItems
(
)
->
count
(
)
<= 0
)
{
$cart
->
addErrors
(
...
array_values
(
$original
->
getErrors
(
)
->
getPersistent
(
)
->
getElements
(
)
)
)
;
$cart
->
setExtensions
(
$original
->
getExtensions
(
)
)
;
return
;
}
// enrich cart with all required data
foreach
(
$this
->collectors
as
$collector
)
{
$collector
->
collect
(
$cart
->
getData
(
)
,
$original
,
$context
,
$behavior
)
;
}
$guestCart
=
$this
->cartService->
getCart
(
$token
,
$currentContext
)
;
$customerCart
=
$this
->cartService->
getCart
(
$customerContext
->
getToken
(
)
,
$customerContext
)
;
if
(
$guestCart
->
getLineItems
(
)
->
count
(
)
> 0
)
{
$restoredCart
=
$this
->
mergeCart
(
$customerCart
,
$guestCart
,
$customerContext
)
;
}
else
{
$restoredCart
=
$this
->cartService->
recalculate
(
$customerCart
,
$customerContext
)
;
}
$restoredCart
->
addErrors
(
...
array_values
(
$guestCart
->
getErrors
(
)
->
getPersistent
(
)
->
getElements
(
)
)
)
;
$this
->
deleteGuestContext
(
$currentContext
,
$customerId
)
;
$errors
=
$restoredCart
->
getErrors
(
)
;
$result
=
$this
->cartRuleLoader->
loadByToken
(
$customerContext
,
$restoredCart
->
getToken
(
)
)
;
$cartWithErrors
=
$result
->
getCart
(
)
;
$cartWithErrors
->
setErrors
(
$errors
)
;
$this
->cartService->
setCart
(
$cartWithErrors
)
;
$this
->eventDispatcher->
dispatch
(
new
SalesChannelContextRestoredEvent
(
$customerContext
,
$currentContext
)
)
;