Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
deleteGuestContext example
$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
)
)
;
return
$customerContext
;
}