Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
EmptyCartException example
public
function
persist
(
Cart
$cart
, SalesChannelContext
$context
)
: string
{
if
(
$cart
->
getErrors
(
)
->
blockOrder
(
)
)
{
throw
CartException::
invalidCart
(
$cart
->
getErrors
(
)
)
;
}
if
(
!
$context
->
getCustomer
(
)
)
{
throw
CartException::
customerNotLoggedIn
(
)
;
}
if
(
$cart
->
getLineItems
(
)
->
count
(
)
<= 0
)
{
throw
new
EmptyCartException
(
)
;
}
$order
=
$this
->converter->
convertToOrder
(
$cart
,
$context
,
new
OrderConversionContext
(
)
)
;
$context
->
getContext
(
)
->
scope
(
Context::SYSTEM_SCOPE,
function
DContext
$context
)
use
(
$order
)
: void
{
$this
->orderRepository->
create
(
[
$order
]
,
$context
)
;
}
)
;
return
$order
[
'id'
]
;
}
}