Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setAvailabilityRuleId example
static
::
assertCount
(
0,
$errors
)
;
}
public
function
testValidateWithoutRules
(
)
: void
{
$deliveryTime
=
$this
->
generateDeliveryTimeDummy
(
)
;
$cart
=
new
Cart
(
'test'
)
;
$context
=
$this
->
createMock
(
SalesChannelContext::
class
)
;
$shippingMethod
=
new
ShippingMethodEntity
(
)
;
$shippingMethod
->
setId
(
'1'
)
;
$shippingMethod
->
setAvailabilityRuleId
(
'1'
)
;
$shippingMethod
->
setDeliveryTime
(
$deliveryTime
)
;
$shippingMethod
->
setActive
(
true
)
;
$deliveryDate
=
new
DeliveryDate
(
new
\
DateTime
(
)
,
new
\
DateTime
(
)
)
;
$delivery
=
new
Delivery
(
new
DeliveryPositionCollection
(
)
,
$deliveryDate
,
$shippingMethod
,
new
ShippingLocation
(
new
CountryEntity
(
)
, null, null
)
,
new
CalculatedPrice
(
5, 5,
new
CalculatedTaxCollection
(
)
,
new
TaxRuleCollection
(
)
)
)
;
$cart
->
setDeliveries
(
new
DeliveryCollection
(
[
$delivery
]
)
)
;
static
::
assertCount
(
1,
$errors
)
;
$error
=
$errors
->
get
(
'payment-method-blocked-'
)
;
static
::
assertNotNull
(
$error
)
;
}
public
function
getSalesChannelContext
(
)
: SalesChannelContext
{
$paymentMethod
=
new
PaymentMethodEntity
(
)
;
$paymentMethod
->
setId
(
'payment-method-id'
)
;
$paymentMethod
->
setActive
(
true
)
;
$paymentMethod
->
setAvailabilityRuleId
(
'payment-method-availability-rule-id'
)
;
$salesChannel
=
new
SalesChannelEntity
(
)
;
$salesChannel
->
setPaymentMethodIds
(
[
'payment-method-id'
]
)
;
$base
= Context::
createDefaultContext
(
)
;
$base
->
setRuleIds
(
[
'payment-method-availability-rule-id'
]
)
;
return
new
SalesChannelContext
(
$base
,
'token',
null,
$this
->salesChannelContext->
getShippingMethod
(
)
)
;
$originalCart
=
new
Cart
(
'original'
)
;
$deliveryTime
=
$this
->
generateDeliveryTimeDummy
(
)
;
$shippingMethod
=
new
ShippingMethodEntity
(
)
;
$shippingMethod
->
setId
(
'1'
)
;
$shippingMethod
->
setName
(
'Express'
)
;
$shippingMethod
->
addTranslated
(
'name', 'Express'
)
;
$shippingMethod
->
setDeliveryTime
(
$deliveryTime
)
;
$shippingMethod
->
setAvailabilityRuleId
(
Uuid::
randomHex
(
)
)
;
$shippingMethod
->
setTaxType
(
ShippingMethodEntity::TAX_TYPE_AUTO
)
;
$deliveryDate
=
new
DeliveryDate
(
new
\
DateTime
(
)
,
new
\
DateTime
(
)
)
;
$delivery
=
new
Delivery
(
new
DeliveryPositionCollection
(
)
,
$deliveryDate
,
$shippingMethod
,
new
ShippingLocation
(
new
CountryEntity
(
)
, null, null
)
,
new
CalculatedPrice
(
10, 10,
new
CalculatedTaxCollection
(
)
,
new
TaxRuleCollection
(
)
)
)
;