Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
hasDifferentPrices example
public
function
convertConfiguratorPrice
(
ListProduct
$product
, ConfiguratorSet
$set
)
{
if
(
$set
->
isSelectionSpecified
(
)
)
{
return
[
]
;
}
$data
=
[
]
;
$variantPrice
=
$product
->
getVariantPrice
(
)
;
$cheapestPrice
=
$product
->
getListingPrice
(
)
;
if
(
\
count
(
$product
->
getPrices
(
)
)
> 1 ||
$product
->
hasDifferentPrices
(
)
)
{
$data
[
'priceStartingFrom'
]
=
$this
->
formatPrice
(
$cheapestPrice
->
getCalculatedPrice
(
)
)
;
}
$data
=
array_merge
(
$data
,
$this
->
convertProductPriceStruct
(
$cheapestPrice
)
)
;
$data
[
'price'
]
=
$data
[
'priceStartingFrom'
]
?:
$this
->
formatPrice
(
$variantPrice
->
getCalculatedPrice
(
)
)
;
$data
[
'sBlockPrices'
]
=
[
]
;
return
$this
->eventManager->
filter
(
'Legacy_Struct_Converter_Convert_Configurator_Price',
$data
,
[
'configurator_set' =>
$set
,
'product' =>
$product
,
]
)
;
}
$product
->
addAttribute
(
'marketing',
$this
->marketingService->
getProductAttribute
(
$product
)
)
;
$this
->priceCalculationService->
calculateProduct
(
$product
,
$context
)
;
if
(
!
$this
->
isProductValid
(
$product
,
$context
)
)
{
continue
;
}
$product
->
setListingPrice
(
$product
->
getCheapestUnitPrice
(
)
)
;
$product
->
setDisplayFromPrice
(
\
count
(
$product
->
getPrices
(
)
)
> 1 ||
$product
->
hasDifferentPrices
(
)
)
;
$product
->
setAllowBuyInListing
(
$this
->
allowBuyInListing
(
$product
)
)
;
if
(
$this
->config->
get
(
'calculateCheapestPriceWithMinPurchase'
)
&&
$product
->
getCheapestPrice
(
)
instanceof Price
)
{
$product
->
setListingPrice
(
$product
->
getCheapestPrice
(
)
)
;
}
$result
[
$number
]
=
$product
;
}
return
$result
;
}
/** * Checks if the provided product is allowed to display in the store front for * the provided context. */