Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
PromotionDiscountPriceEntity example
$currencyDiscountValue
= 10;
$discount
=
new
PromotionDiscountEntity
(
)
;
$discount
->
setId
(
'D5'
)
;
$discount
->
setType
(
PromotionDiscountEntity::TYPE_ABSOLUTE
)
;
$discount
->
setValue
(
$standardDiscountValue
)
;
$discount
->
setScope
(
PromotionDiscountEntity::SCOPE_CART
)
;
$currency
=
new
CurrencyEntity
(
)
;
$currency
->
setId
(
'C1'
)
;
$advancedPrice
=
new
PromotionDiscountPriceEntity
(
)
;
$advancedPrice
->
setUniqueIdentifier
(
Uuid::
randomHex
(
)
)
;
$advancedPrice
->
setCurrency
(
$currency
)
;
$advancedPrice
->
setCurrencyId
(
$currency
->
getId
(
)
)
;
$advancedPrice
->
setPrice
(
$currencyDiscountValue
)
;
$advancedPricesCollection
=
new
PromotionDiscountPriceCollection
(
[
]
)
;
$advancedPricesCollection
->
add
(
$advancedPrice
)
;
$discount
->
setPromotionDiscountPrices
(
$advancedPricesCollection
)
;
$this
->salesChannelContext->
method
(
'getCurrency'
)
->
willReturn
(
$currency
)
;
$discount
=
new
PromotionDiscountEntity
(
)
;
$discount
->
setId
(
'D5'
)
;
$discount
->
setType
(
PromotionDiscountEntity::TYPE_PERCENTAGE
)
;
$discount
->
setValue
(
40
)
;
$discount
->
setMaxValue
(
30.0
)
;
$discount
->
setScope
(
PromotionDiscountEntity::SCOPE_CART
)
;
$currency
=
new
CurrencyEntity
(
)
;
$currency
->
setId
(
'currency'
)
;
$this
->salesChannelContext->
method
(
'getCurrency'
)
->
willReturn
(
$currency
)
;
$advancedPrice
=
new
PromotionDiscountPriceEntity
(
)
;
$advancedPrice
->
setUniqueIdentifier
(
Uuid::
randomHex
(
)
)
;
$advancedPrice
->
setCurrency
(
$currency
)
;
$advancedPrice
->
setCurrencyId
(
$currency
->
getId
(
)
)
;
$advancedPrice
->
setPrice
(
20
)
;
$discount
->
setPromotionDiscountPrices
(
new
PromotionDiscountPriceCollection
(
[
$advancedPrice
]
)
)
;
$builder
=
new
PromotionItemBuilder
(
)
;
$item
=
$builder
->
buildDiscountLineItem
(
'',
$this
->promotion,
$discount
,
$currency
->
getId
(
)
,
$currencyFactor
)
;
static
::
assertEquals
(
20,
$item
->
getPayload
(
)
[
'maxValue'
]
)
;
}