Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getFreeDelivery example
return
false;
}
private
function
isFreeDeliveryItem
(
LineItem
$lineItem
)
: bool
{
$deliveryInformation
=
$lineItem
->
getDeliveryInformation
(
)
;
if
(
$deliveryInformation
=== null
)
{
return
false;
}
return
$deliveryInformation
->
getFreeDelivery
(
)
;
}
}
return
(
$length
*
$width
*
$height
)
*
$deliverable
->
getQuantity
(
)
;
}
)
;
return
array_sum
(
$volumes
)
;
}
public
function
getWithoutDeliveryFree
(
)
: DeliveryPositionCollection
{
return
$this
->
filter
(
function
DDeliveryPosition
$position
)
{
if
(
$position
->
getLineItem
(
)
->
getDeliveryInformation
(
)
!== null && !
$position
->
getLineItem
(
)
->
getDeliveryInformation
(
)
->
getFreeDelivery
(
)
)
{
return
$position
;
}
return
null;
}
)
;
}
public
function
getApiAlias
(
)
: string
{
return
'cart_delivery_position_collection';
}
return
;
}
$delivery
->
setShippingCosts
(
$costs
)
;
}
private
function
hasDeliveryWithOnlyShippingFreeItems
(
Delivery
$delivery
)
: bool
{
foreach
(
$delivery
->
getPositions
(
)
->
getLineItems
(
)
->
getIterator
(
)
as
$lineItem
)
{
if
(
$lineItem
->
getDeliveryInformation
(
)
&& !
$lineItem
->
getDeliveryInformation
(
)
->
getFreeDelivery
(
)
)
{
return
false;
}
}
return
true;
}
private
function
matches
(
Delivery
$delivery
, ShippingMethodPriceEntity
$shippingMethodPrice
, SalesChannelContext
$context
)
: bool
{
if
(
$shippingMethodPrice
->
getCalculationRuleId
(
)
)
{
return
\
in_array
(
$shippingMethodPrice
->
getCalculationRuleId
(
)
,
$context
->
getRuleIds
(
)
, true
)
;
}
$product
=
$this
->
getContainer
(
)
->
get
(
ProductLineItemFactory::
class
)
->
create
(
[
'id' =>
$this
->ids->
get
(
'product'
)
, 'referencedId' =>
$this
->ids->
get
(
'product'
)
]
,
$context
)
;
$product
->
setLabel
(
'My test product'
)
;
$cart
=
$this
->cartService->
getCart
(
$token
,
$context
)
;
$this
->cartService->
add
(
$cart
,
$product
,
$context
)
;
$actualProduct
=
$cart
->
get
(
$product
->
getId
(
)
)
;
static
::
assertInstanceOf
(
LineItem::
class
,
$actualProduct
)
;
static
::
assertInstanceOf
(
DeliveryInformation::
class
,
$actualProduct
->
getDeliveryInformation
(
)
)
;
static
::
assertFalse
(
$actualProduct
->
getDeliveryInformation
(
)
->
getFreeDelivery
(
)
)
;
}
public
function
testInactiveProductCartRemoval
(
)
: void
{
$context
=
$this
->
getContext
(
)
;
$this
->
createProduct
(
)
;
$this
->
getProductCart
(
)
;
$update
=
[
'id' =>
$this
->ids->
get
(
'product'
)
, 'active' => false
]
;
$this
->
getContainer
(
)
->
get
(
'product.repository'
)
->
upsert
(
[
$update
]
,
$context
->
getContext
(
)
)
;