Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
createQuantityPriceCalculator example
parent::
setUp
(
)
;
$this
->context =
$this
->
getMockBuilder
(
SalesChannelContext::
class
)
->
disableOriginalConstructor
(
)
->
getMock
(
)
;
$this
->context->
method
(
'getItemRounding'
)
->
willReturn
(
new
CashRoundingConfig
(
2, 0.01, true
)
)
;
$this
->fakeSequenceSupervisor =
new
FakeSequenceSupervisor
(
)
;
$this
->fakeTakeAllPackager =
new
FakeLineItemGroupTakeAllPackager
(
'FAKE-PACKAGER',
$this
->fakeSequenceSupervisor
)
;
$this
->fakeSorter =
new
FakeLineItemGroupSorter
(
'FAKE-SORTER',
$this
->fakeSequenceSupervisor
)
;
$this
->fakeTakeAllRuleMatcher =
new
FakeTakeAllRuleMatcher
(
$this
->fakeSequenceSupervisor
)
;
$quantityPriceCalculator
=
$this
->
createQuantityPriceCalculator
(
)
;
$this
->integrationTestBuilder =
new
LineItemGroupBuilder
(
new
LineItemGroupServiceRegistry
(
[
$this
->fakeTakeAllPackager,
]
,
[
$this
->fakeSorter,
]
)
,
$this
->fakeTakeAllRuleMatcher,
public
static
function
grossPriceDataProvider
(
)
: \Generator
{
yield
[
self::
getDifferentTaxesCalculation
(
)
]
;
yield
[
self::
getOneHundredPercentageCalculation
(
)
]
;
yield
[
self::
getFiftyPercentageCalculation
(
)
]
;
yield
[
self::
regression_next_12270
(
)
]
;
}
private
static
function
regression_next_12270
(
)
: PercentageCalculation
{
$calculator
= self::
createQuantityPriceCalculator
(
)
;
$priceDefinition
=
new
QuantityPriceDefinition
(
10.40,
new
TaxRuleCollection
(
[
new
TaxRule
(
21, 100
)
]
)
, 1
)
;
$price
=
$calculator
->
calculate
(
$priceDefinition
, Generator::
createSalesChannelContext
(
)
)
;
static
::
assertSame
(
10.40,
$price
->
getTotalPrice
(
)
)
;
static
::
assertSame
(
1.80,
$price
->
getCalculatedTaxes
(
)
->
getAmount
(
)
)
;
$priceDefinition
=
new
QuantityPriceDefinition
(
104.00,
new
TaxRuleCollection
(
[
new
TaxRule
(
21, 100
)
]
)
, 1
)
;
$price
=
$calculator
->
calculate
(
$priceDefinition
, Generator::
createSalesChannelContext
(
)
)
;
static
::
assertSame
(
104.00,
$price
->
getTotalPrice
(
)
)
;
static
::
assertSame
(
18.05,
$price
->
getCalculatedTaxes
(
)
->
getAmount
(
)
)
;
public
static
function
provider
(
)
: array
{
return
[
'small-discounts' =>
[
self::
getSmallDiscountCase
(
)
]
,
'100%' =>
[
self::
getOneHundredPercentageDiscountCase
(
)
]
,
]
;
}
private
static
function
getSmallDiscountCase
(
)
: AbsoluteCalculation
{
$calculator
= self::
createQuantityPriceCalculator
(
)
;
$definition
=
new
QuantityPriceDefinition
(
30,
new
TaxRuleCollection
(
[
new
TaxRule
(
19
)
]
)
)
;
$price1
=
$calculator
->
calculate
(
$definition
, Generator::
createSalesChannelContext
(
)
)
;
$definition
=
new
QuantityPriceDefinition
(
30,
new
TaxRuleCollection
(
[
new
TaxRule
(
7
)
]
)
)
;
$price2
=
$calculator
->
calculate
(
$definition
, Generator::
createSalesChannelContext
(
)
)
;
return
new
AbsoluteCalculation
(
-6,
new
CalculatedPrice
(
-6,
-