Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setCheapestPriceRule example
$cheapestPriceRule
=
$product
->
getPriceRules
(
)
[
0
]
;
$displayFromPrice
=
$product
->
displayFromPrice
(
)
;
}
else
{
$cheapestPriceRule
=
$cheapestPriceData
[
$number
]
[
'price'
]
;
$displayFromPrice
=
$cheapestPriceData
[
$number
]
[
'different_price_count'
]
> 1;
}
if
(
$product
->
isPriceGroupActive
(
)
)
{
$cheapestPriceRule
=
$this
->
calculatePriceGroupDiscounts
(
$product
,
$cheapestPriceRule
,
$context
)
;
}
$product
->
setCheapestPriceRule
(
$cheapestPriceRule
)
;
$this
->priceCalculationService->
calculateProduct
(
$product
,
$context
)
;
$product
->
setListingPrice
(
$product
->
getCheapestUnitPrice
(
)
)
;
if
(
$this
->config->
get
(
'calculateCheapestPriceWithMinPurchase'
)
&&
$product
->
getCheapestPrice
(
)
instanceof Price
)
{
$product
->
setListingPrice
(
$product
->
getCheapestPrice
(
)
)
;
}
$product
->
setDisplayFromPrice
(
$displayFromPrice
)
;
}
}
$product
->
setMinStock
(
$listProduct
->
getMinStock
(
)
)
;
$product
->
setReleaseDate
(
$listProduct
->
getReleaseDate
(
)
)
;
$product
->
setShippingTime
(
$listProduct
->
getShippingTime
(
)
)
;
$product
->
setShortDescription
(
$listProduct
->
getShortDescription
(
)
)
;
$product
->
setStock
(
$listProduct
->
getStock
(
)
)
;
$product
->
setWeight
(
$listProduct
->
getWeight
(
)
)
;
$product
->
setWidth
(
$listProduct
->
getWidth
(
)
)
;
$product
->
setPriceGroup
(
$listProduct
->
getPriceGroup
(
)
)
;
$product
->
setCreatedAt
(
$listProduct
->
getCreatedAt
(
)
)
;
$product
->
setUpdatedAt
(
$listProduct
->
getUpdatedAt
(
)
)
;
$product
->
setPriceRules
(
$listProduct
->
getPriceRules
(
)
)
;
$product
->
setCheapestPriceRule
(
$listProduct
->
getCheapestPriceRule
(
)
)
;
$product
->
setManufacturerNumber
(
$listProduct
->
getManufacturerNumber
(
)
)
;
$product
->
setMetaTitle
(
$listProduct
->
getMetaTitle
(
)
)
;
$product
->
setTemplate
(
$listProduct
->
getTemplate
(
)
)
;
$product
->
setHasConfigurator
(
$listProduct
->
hasConfigurator
(
)
)
;
$product
->
setSales
(
$listProduct
->
getSales
(
)
)
;
$product
->
setHasEsd
(
$listProduct
->
hasEsd
(
)
)
;
$product
->
setEsd
(
$listProduct
->
getEsd
(
)
)
;
$product
->
setIsPriceGroupActive
(
$listProduct
->
isPriceGroupActive
(
)
)
;
$product
->
setBlockedCustomerGroupIds
(
$listProduct
->
getBlockedCustomerGroupIds
(
)
)
;
$product
->
setVoteAverage
(
$listProduct
->
getVoteAverage
(
)
)
;
$product
->
setHasAvailableVariant
(
$listProduct
->
hasAvailableVariant
(
)
)
;
$product
=
$products
[
$number
]
;
if
(
isset
(
$covers
[
$number
]
)
)
{
$product
->
setCover
(
$covers
[
$number
]
)
;
}
if
(
isset
(
$graduatedPrices
[
$number
]
)
)
{
$product
->
setPriceRules
(
$graduatedPrices
[
$number
]
)
;
}
if
(
isset
(
$cheapestPrices
[
$number
]
)
)
{
$product
->
setCheapestPriceRule
(
$cheapestPrices
[
$number
]
)
;
}
if
(
isset
(
$voteAverages
[
$number
]
)
)
{
$product
->
setVoteAverage
(
$voteAverages
[
$number
]
)
;
}
if
(
isset
(
$categories
[
$number
]
)
)
{
$product
->
setCategories
(
$categories
[
$number
]
)
;
}
if
(
$product
->
getManufacturer
(
)
&&
isset
(
$manufacturerCovers
[
$product
->
getManufacturer
(
)
->
getCoverId
(
)
]
)
)
{
$rules
=
$product
->
getPriceRules
(
)
;
$prices
=
[
]
;
foreach
(
$rules
as
$rule
)
{
$prices
[
]
=
$this
->
calculatePriceStruct
(
$rule
,
$tax
,
$context
)
;
}
$product
->
setPrices
(
$prices
)
;
$rules
=
$product
->
getPriceRules
(
)
;
if
(
!
$product
->
getCheapestPriceRule
(
)
&& !
empty
(
$rules
)
)
{
$product
->
setCheapestPriceRule
(
clone
$rules
[
0
]
)
;
}
if
(
$product
->
getCheapestPriceRule
(
)
)
{
/** * Calculation with considering min purchase */
$rule
=
clone
$product
->
getCheapestPriceRule
(
)
;
$product
->
setCheapestPrice
(
$this
->
calculateCheapestAvailablePrice
(
$product
,
$rule
,
$context
)
)
;
$product
->
addAttributes
(
$this
->
parseAttributes
(
$product
->
getAttributes
(
)
)
)
;
$product
->
setCreatedAt
(
null
)
;
$product
->
setUpdatedAt
(
null
)
;
$product
->
setReleaseDate
(
null
)
;
$product
->
setPrices
(
null
)
;
$product
->
setPriceRules
(
null
)
;
$product
->
setCheapestPriceRule
(
null
)
;
$product
->
setCheapestPrice
(
null
)
;
$product
->
setCheapestUnitPrice
(
null
)
;
$product
->
setAvailableCombinations
(
null
)
;
$product
->
setFullConfiguration
(
null
)
;
$product
->
resetStates
(
)
;
if
(
!
$this
->
isValid
(
$shop
,
$product
)
)
{
continue
;
}
$result
[
$number
]
=
$product
;
}