Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setMinPurchase example
public
function
testSkipStockValidation
(
)
: void
{
$cart
=
new
Cart
(
Uuid::
randomHex
(
)
)
;
$builder
=
new
ProductLineItemFactory
(
new
PriceDefinitionFactory
(
)
)
;
$salesChannelContext
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$cart
->
add
(
$builder
->
create
(
[
'id' => 'product-1', 'referencedId' => 'product-1'
]
,
$salesChannelContext
)
->
setQuantityInformation
(
(
new
QuantityInformation
(
)
)
->
setMinPurchase
(
1
)
->
setMaxPurchase
(
1
)
->
setPurchaseSteps
(
1
)
)
)
;
$cart
->
add
(
$builder
->
create
(
[
'id' => 'product-2', 'referencedId' => 'product-2'
]
,
$salesChannelContext
)
->
setReferencedId
(
'product-1'
)
->
setQuantityInformation
(
(
new
QuantityInformation
(
)
)
->
setMinPurchase
(
1
)
if
(
isset
(
$data
[
'__unit_referenceunit'
]
)
)
{
$unit
->
setReferenceUnit
(
(float)
$data
[
'__unit_referenceunit'
]
)
;
}
if
(
isset
(
$data
[
'__unit_purchasesteps'
]
)
)
{
$unit
->
setPurchaseStep
(
(int)
$data
[
'__unit_purchasesteps'
]
)
;
}
if
(
isset
(
$data
[
'__unit_minpurchase'
]
)
)
{
$unit
->
setMinPurchase
(
(int)
$data
[
'__unit_minpurchase'
]
)
;
}
if
(
isset
(
$data
[
'__unit_maxpurchase'
]
)
)
{
$unit
->
setMaxPurchase
(
(int)
$data
[
'__unit_maxpurchase'
]
)
;
}
}
}
// Check if the price has to be updated
if
(
$this
->
shouldPriceBeRecalculated
(
$lineItem
,
$behavior
)
)
{
$lineItem
->
setPriceDefinition
(
$this
->
getPriceDefinition
(
$product
,
$context
,
$lineItem
->
getQuantity
(
)
)
)
;
}
$quantityInformation
=
new
QuantityInformation
(
)
;
$quantityInformation
->
setMinPurchase
(
$product
->
getMinPurchase
(
)
?? 1
)
;
$quantityInformation
->
setMaxPurchase
(
$product
->
getCalculatedMaxPurchase
(
)
)
;
$quantityInformation
->
setPurchaseSteps
(
$product
->
getPurchaseSteps
(
)
?? 1
)
;