Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
ShippingAddressBlockedError example
}
public
function
validate
(
Cart
$cart
, ErrorCollection
$errors
, SalesChannelContext
$context
)
: void
{
$country
=
$context
->
getShippingLocation
(
)
->
getCountry
(
)
;
$customer
=
$context
->
getCustomer
(
)
;
$validateShipping
=
$cart
->
getLineItems
(
)
->
count
(
)
=== 0
||
$cart
->
getLineItems
(
)
->
hasLineItemWithState
(
State::IS_PHYSICAL
)
;
if
(
!
$country
->
getActive
(
)
&&
$validateShipping
)
{
$errors
->
add
(
new
ShippingAddressBlockedError
(
(string)
$country
->
getTranslation
(
'name'
)
)
)
;
return
;
}
if
(
!
$country
->
getShippingAvailable
(
)
&&
$validateShipping
)
{
$errors
->
add
(
new
ShippingAddressBlockedError
(
(string)
$country
->
getTranslation
(
'name'
)
)
)
;
return
;
}
if
(
!
$this
->
isSalesChannelCountry
(
$country
->
getId
(
)
,
$context
)
&&
$validateShipping
)
{