Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
calculateQuantity example
$this
->prices->
clear
(
)
;
$rules
=
$this
->context->
buildTaxRules
(
$this
->product->
get
(
'taxId'
)
)
;
foreach
(
$mapped
as
$quantity
=>
$price
)
{
$value
=
$this
->
getPriceForTaxState
(
$price
,
$this
->context
)
;
$definition
=
new
QuantityPriceDefinition
(
$value
,
$rules
,
$quantity
)
;
$this
->prices->
add
(
$this
->priceStubs->
calculateQuantity
(
$definition
,
$this
->context
)
)
;
}
}
/** * @internal */
public
function
getIterator
(
)
: \Traversable
{
return
new
\
ArrayIterator
(
$this
->prices->
map
(
function
DCalculatedPrice
$price
)
{
if
(
$price
instanceof PriceCollection
)
{
$value
=
$this
->
getPriceForTaxState
(
$price
,
$this
->context
)
;
$definition
=
new
QuantityPriceDefinition
(
$value
,
$this
->price->
getTaxRules
(
)
,
$this
->
getQuantity
(
)
)
;
$price
=
$this
->priceStubs->
calculateQuantity
(
$definition
,
$this
->context
)
;
}
if
(
!
$price
instanceof CalculatedPrice
)
{
throw
ProductException::
invalidCheapestPriceFacade
(
$this
->item->
getUniqueIdentifier
(
)
)
;
}
$this
->price->
overwrite
(
$price
->
getUnitPrice
(
)
,
$price
->
getTotalPrice
(
)
,
$price
->
getCalculatedTaxes
(
)
,
)
;
public
function
discount
(
float
$value
)
: void
{
$definition
=
new
QuantityPriceDefinition
(
$this
->price->
getUnitPrice
(
)
,
$this
->price->
getTaxRules
(
)
)
;
$definition
->
setIsCalculated
(
true
)
;
$unit
=
$this
->priceStubs->
calculateQuantity
(
$definition
,
$this
->context
)
;
$discount
=
$this
->priceStubs->
calculatePercentage
(
\
abs
(
$value
)
,
new
CalculatedPriceCollection
(
[
$unit
]
)
,
$this
->context
)
;
$definition
=
new
QuantityPriceDefinition
(
$this
->price->
getUnitPrice
(
)
-
$discount
->
getUnitPrice
(
)
,
$this
->price->
getTaxRules
(
)
,
$this
->
getQuantity
(
)
)
;
$this
->
overwrite
(
$definition
)
;
}