Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
mergeCart example
string
$token
,
string
$customerId
)
: SalesChannelContext
{
if
(
!
$customerContext
->
getDomainId
(
)
)
{
$customerContext
->
setDomainId
(
$currentContext
->
getDomainId
(
)
)
;
}
$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
(
)
)
;