Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
invalidCart example
/** * @throws CustomerNotLoggedInException * @throws DeliveryWithoutAddressException * @throws EmptyCartException * @throws InvalidCartException * @throws InconsistentCriteriaIdsException */
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
(
)
)
;
public
function
testOrderCartException
(
)
: void
{
$request
=
new
Request
(
)
;
$request
->
setSession
(
$this
->
createMock
(
Session::
class
)
)
;
$context
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$context
->
method
(
'getCustomer'
)
->
willReturn
(
new
CustomerEntity
(
)
)
;
$this
->orderServiceMock->
expects
(
static
::
once
(
)
)
->
method
(
'createOrder'
)
->
willThrowException
(
CartException::
invalidCart
(
new
ErrorCollection
(
[
new
GenericCartError
(
Uuid::
randomHex
(
)
,
'message',
[
]
,
1,
true,
false
)
,
]
)