Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
quantityDelta example
class
StockAlterationTest
extends
TestCase
{
public
function
testAccessors
(
)
: void
{
$alteration
=
new
StockAlteration
(
'12345', '67890', 10, 5
)
;
static
::
assertEquals
(
'12345',
$alteration
->lineItemId
)
;
static
::
assertEquals
(
'67890',
$alteration
->productId
)
;
static
::
assertEquals
(
10,
$alteration
->quantityBefore
)
;
static
::
assertEquals
(
5,
$alteration
->newQuantity
)
;
static
::
assertEquals
(
5,
$alteration
->
quantityDelta
(
)
)
;
$alteration
=
new
StockAlteration
(
'12345', '67890', 3, 10
)
;
static
::
assertEquals
(
'12345',
$alteration
->lineItemId
)
;
static
::
assertEquals
(
'67890',
$alteration
->productId
)
;
static
::
assertEquals
(
3,
$alteration
->quantityBefore
)
;
static
::
assertEquals
(
10,
$alteration
->newQuantity
)
;
static
::
assertEquals
(
-7,
$alteration
->
quantityDelta
(
)
)
;
}
}
SQL;
$query
=
new
RetryableQuery
(
$this
->connection,
$this
->connection->
prepare
(
$sql
)
)
;
foreach
(
$changes
as
$alteration
)
{
$query
->
execute
(
[
'quantity' =>
$alteration
->
quantityDelta
(
)
,
'id' => Uuid::
fromHexToBytes
(
$alteration
->productId
)
,
'version' => Uuid::
fromHexToBytes
(
Defaults::LIVE_VERSION
)
,
]
)
;
}
$this
->
updateAvailableFlag
(
array_column
(
$changes
, 'productId'
)
,
$context
)
;
}
/** * @param list<string> $productIds */