Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
orderProduct example
SalesChannelContextService::CUSTOMER_ID =>
$this
->
createCustomer
(
)
,
]
)
;
}
public
function
testOrderProduct
(
)
: void
{
$id
=
$this
->
createProduct
(
)
;
$context
= Context::
createDefaultContext
(
)
;
$orderId
=
$this
->
orderProduct
(
$id
, 5,
$this
->context
)
;
static
::
assertNotNull
(
$orderId
)
;
$criteria
=
new
Criteria
(
)
;
$criteria
->
addFilter
(
new
EqualsFilter
(
'orderId',
$orderId
)
)
;
$lineItems
=
$this
->lineItemRepository->
search
(
$criteria
,
$context
)
;
static
::
assertCount
(
1,
$lineItems
)
;
/** @var OrderLineItemEntity $first */
$first
=
$lineItems
->
first
(
)
;
$id
=
$this
->
createProduct
(
)
;
$context
= Context::
createDefaultContext
(
)
;
$product
=
$this
->productRepository->
search
(
new
Criteria
(
[
$id
]
)
,
$context
)
->
get
(
$id
)
;
static
::
assertInstanceOf
(
ProductEntity::
class
,
$product
)
;
static
::
assertTrue
(
$product
->
getAvailable
(
)
)
;
static
::
assertSame
(
5,
$product
->
getAvailableStock
(
)
)
;
$this
->
orderProduct
(
$id
, 1
)
;
$product
=
$this
->productRepository->
search
(
new
Criteria
(
[
$id
]
)
,
$context
)
->
get
(
$id
)
;
static
::
assertInstanceOf
(
ProductEntity::
class
,
$product
)
;
static
::
assertTrue
(
$product
->
getAvailable
(
)
)
;
static
::
assertSame
(
4,
$product
->
getAvailableStock
(
)
)
;
static
::
assertSame
(
5,
$product
->
getStock
(
)
)
;
}
public
function
testAvailableAfterCancel
(
)
: void
{
$id
=
$this
->
createProduct
(
)
;
$context
= Context::
createDefaultContext
(
)
;
$product
=
$this
->productRepository->
search
(
new
Criteria
(
[
$id
]
)
,
$context
)
->
get
(
$id
)
;
static
::
assertInstanceOf
(
ProductEntity::
class
,
$product
)
;
static
::
assertTrue
(
$product
->
getAvailable
(
)
)
;
$this
->
assertStock
(
5,
$product
)
;
$this
->
orderProduct
(
$id
, 1
)
;
$product
=
$this
->productRepository->
search
(
new
Criteria
(
[
$id
]
)
,
$context
)
->
get
(
$id
)
;
static
::
assertInstanceOf
(
ProductEntity::
class
,
$product
)
;
static
::
assertTrue
(
$product
->
getAvailable
(
)
)
;
$this
->
assertStock
(
4,
$product
)
;
}
public
function
testStockAfterCancel
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;