Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
isNetDelivery example
$countryTaxFree
=
$shippingLocationCountry
->
getCustomerTax
(
)
->
getEnabled
(
)
;
if
(
$countryTaxFree
)
{
return
true;
}
return
$this
->
isCompanyTaxFree
(
$context
,
$shippingLocationCountry
)
;
}
public
function
getTaxState
(
SalesChannelContext
$context
)
: string
{
if
(
$this
->
isNetDelivery
(
$context
)
)
{
return
CartPrice::TAX_STATE_FREE;
}
if
(
$this
->
useGross
(
$context
)
)
{
return
CartPrice::TAX_STATE_GROSS;
}
return
CartPrice::TAX_STATE_NET;
}
public
function
isCompanyTaxFree
(
SalesChannelContext
$context
, CountryEntity
$shippingLocationCountry
)
: bool
{
$country
=
new
CountryEntity
(
)
;
$country
->
setCustomerTax
(
new
TaxFreeConfig
(
true, Defaults::CURRENCY, 0
)
)
;
$country
->
setCompanyTax
(
new
TaxFreeConfig
(
true, Defaults::CURRENCY, 0
)
)
;
$context
->
expects
(
static
::
once
(
)
)
->
method
(
'getShippingLocation'
)
->
willReturn
(
ShippingLocation::
createFromCountry
(
$country
)
)
;
$detector
=
$this
->
getContainer
(
)
->
get
(
TaxDetector::
class
)
;
static
::
assertTrue
(
$detector
->
isNetDelivery
(
$context
)
)
;
}
public
function
testIsNetDeliveryWithCompanyFreeTax
(
)
: void
{
$context
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
/** @var EntityRepository<CountryCollection> $countryRepository */
$countryRepository
=
$this
->
getContainer
(
)
->
get
(
'country.repository'
)
;
$criteria
=
new
Criteria
(
)
;
$criteria
->
addFilter
(
new
EqualsFilter
(
'iso', 'DE'
)
)
;
$criteria
->
setLimit
(
1
)
;