Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setGross example
if
(
$type
!== AbsolutePriceDefinition::TYPE
)
{
throw
CartException::
discountTypeNotSupported
(
$key
,
$type
)
;
}
if
(
!
$value
instanceof PriceCollection
)
{
throw
CartException::
absoluteDiscountMissingPriceCollection
(
$key
)
;
}
if
(
!
$value
->
has
(
Defaults::CURRENCY
)
)
{
throw
CartException::
missingDefaultPriceCollectionForDiscount
(
$key
)
;
}
foreach
(
$value
as
$price
)
{
$price
->
setGross
(
\
abs
(
$price
->
getGross
(
)
)
* -1
)
;
$price
->
setNet
(
\
abs
(
$price
->
getNet
(
)
)
* -1
)
;
if
(
!
$price
->
getListPrice
(
)
)
{
continue
;
}
$price
->
getListPrice
(
)
->
setGross
(
\
abs
(
$price
->
getListPrice
(
)
->
getGross
(
)
)
* -1
)
;
$price
->
getListPrice
(
)
->
setNet
(
\
abs
(
$price
->
getListPrice
(
)
->
getNet
(
)
)
* -1
)
;
}
return
new
CurrencyPriceDefinition
(
$value
)
;
}
}
$object
->
setPurchase
(
$cheapest
[
'purchase_unit'
]
?
(float)
$cheapest
[
'purchase_unit'
]
: null
)
;
$object
->
setReference
(
$cheapest
[
'reference_unit'
]
?
(float)
$cheapest
[
'reference_unit'
]
: null
)
;
$object
->
setUnitId
(
$cheapest
[
'unit_id'
]
?? null
)
;
$prices
=
[
]
;
$blueprint
=
new
Price
(
'', 1, 1, true
)
;
foreach
(
$cheapest
[
'price'
]
as
$row
)
{
$price
=
clone
$blueprint
;
$price
->
setCurrencyId
(
$row
[
'currencyId'
]
)
;
$price
->
setGross
(
(float)
$row
[
'gross'
]
)
;
$price
->
setNet
(
(float)
$row
[
'net'
]
)
;
$price
->
setLinked
(
(bool)
$row
[
'linked'
]
)
;
if
(
isset
(
$row
[
'listPrice'
]
)
)
{
$list
=
clone
$blueprint
;
$list
->
setCurrencyId
(
$row
[
'currencyId'
]
)
;
$list
->
setGross
(
(float)
$row
[
'listPrice'
]
[
'gross'
]
)
;
$list
->
setNet
(
(float)
$row
[
'listPrice'
]
[
'net'
]
)
;
$list
->
setLinked
(
(bool)
$row
[
'listPrice'
]
[
'linked'
]
)
;
if
(
$type
!== AbsolutePriceDefinition::TYPE
)
{
throw
CartException::
surchargeTypeNotSupported
(
$key
,
$type
)
;
}
if
(
!
$value
instanceof PriceCollection
)
{
throw
CartException::
absoluteSurchargeMissingPriceCollection
(
$key
)
;
}
if
(
!
$value
->
has
(
Defaults::CURRENCY
)
)
{
throw
CartException::
missingDefaultPriceCollectionForSurcharge
(
$key
)
;
}
foreach
(
$value
as
$price
)
{
$price
->
setGross
(
\
abs
(
$price
->
getGross
(
)
)
)
;
$price
->
setNet
(
\
abs
(
$price
->
getNet
(
)
)
)
;
if
(
!
$price
->
getListPrice
(
)
)
{
continue
;
}
$price
->
getListPrice
(
)
->
setGross
(
\
abs
(
$price
->
getListPrice
(
)
->
getGross
(
)
)
)
;
$price
->
getListPrice
(
)
->
setNet
(
\
abs
(
$price
->
getListPrice
(
)
->
getNet
(
)
)
)
;
}
return
new
CurrencyPriceDefinition
(
$value
)
;
}
}