Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setTaxCalculationType example
CustomerEntity
$customer
= null,
?string
$token
= null,
?string
$domainId
= null,
)
: SalesChannelContext
{
if
(
!
$baseContext
)
{
$baseContext
= Context::
createDefaultContext
(
)
;
}
if
(
$salesChannel
=== null
)
{
$salesChannel
=
new
SalesChannelEntity
(
)
;
$salesChannel
->
setId
(
'ffa32a50e2d04cf38389a53f8d6cd594'
)
;
$salesChannel
->
setNavigationCategoryId
(
Uuid::
randomHex
(
)
)
;
$salesChannel
->
setTaxCalculationType
(
SalesChannelDefinition::CALCULATION_TYPE_HORIZONTAL
)
;
}
$currency
=
$currency
?:
(
new
CurrencyEntity
(
)
)
->
assign
(
[
'id' => '4c8eba11bd3546d786afbed481a6e665',
'factor' => 1,
]
)
;
$currency
->
setFactor
(
1
)
;
if
(
!
$currentCustomerGroup
)
{
$currentCustomerGroup
=
new
CustomerGroupEntity
(
)
;
void
{
$context
=
$this
->
getContainer
(
)
->
get
(
SalesChannelContextFactory::
class
)
->
create
(
Uuid::
randomHex
(
)
, TestDefaults::SALES_CHANNEL
)
;
$taxState
=
$useNet
? CartPrice::TAX_STATE_NET : CartPrice::TAX_STATE_GROSS;
$context
->
setTaxState
(
$taxState
)
;
$calculator
=
$this
->
getContainer
(
)
->
get
(
AmountCalculator::
class
)
;
$cart
=
$this
->
createCart
(
$items
,
$context
)
;
$context
->
getSalesChannel
(
)
->
setTaxCalculationType
(
SalesChannelDefinition::CALCULATION_TYPE_HORIZONTAL
)
;
$amount
=
$calculator
->
calculate
(
$cart
->
getLineItems
(
)
->
getPrices
(
)
,
$cart
->
getDeliveries
(
)
->
getShippingCosts
(
)
,
$context
)
;
static
::
assertEquals
(
$horizontal
,
$amount
->
getCalculatedTaxes
(
)
)
;
$context
->
getSalesChannel
(
)
->
setTaxCalculationType
(
SalesChannelDefinition::CALCULATION_TYPE_VERTICAL
)
;
$amount
=
$calculator
->
calculate
(
$cart
->
getLineItems
(
)
->
getPrices
(
)
,
$cart
->
getDeliveries
(
)
->
getShippingCosts
(
)
,