Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getCoverId example
return
;
}
$this
->
sortItemsByPosition
(
$sliderItems
)
;
if
(
$sliderItemsConfig
->
getStringValue
(
)
=== 'product.media'
)
{
/** @var ProductEntity $productEntity */
$productEntity
=
$resolverContext
->
getEntity
(
)
;
if
(
$productEntity
->
getCover
(
)
)
{
/** @var ProductMediaCollection $sliderItems */
$sliderItems
=
new
ProductMediaCollection
(
array_merge
(
[
$productEntity
->
getCoverId
(
)
=>
$productEntity
->
getCover
(
)
]
,
$sliderItems
->
getElements
(
)
)
)
;
}
}
foreach
(
$sliderItems
->
getMedia
(
)
as
$media
)
{
$imageSliderItem
=
new
ImageSliderItemStruct
(
)
;
$imageSliderItem
->
setMedia
(
$media
)
;
$imageSlider
->
addSliderItem
(
$imageSliderItem
)
;
}
}
}
$product
=
(
new
ProductBuilder
(
$ids
, 'p1'
)
)
->
price
(
100
)
->
media
(
'm1'
)
->
cover
(
'm1'
)
;
$productRepository
->
create
(
[
$product
->
build
(
)
]
, Context::
createDefaultContext
(
)
)
;
$productMediaRepository
=
$this
->
getContainer
(
)
->
get
(
'product_media.repository'
)
;
$productMediaRepository
->
delete
(
[
[
'id' =>
$ids
->
get
(
'm1'
)
]
]
, Context::
createDefaultContext
(
)
)
;
$product
=
$productRepository
->
search
(
new
Criteria
(
[
$ids
->
get
(
'p1'
)
]
)
, Context::
createDefaultContext
(
)
)
->
first
(
)
;
static
::
assertNull
(
$product
->
getCoverId
(
)
)
;
}
}
$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
(
)
]
)
)
{
$product
->
getManufacturer
(
)
->
setCoverMedia
(
$manufacturerCovers
[
$product
->
getManufacturer
(
)
->
getCoverId
(
)
]
)
;
}
$product
->
addAttribute
(
'marketing',
$this
->marketingService->
getProductAttribute
(
$product
)
)
;
$this
->priceCalculationService->
calculateProduct
(
$product
,
$context
)
;
if
(
!
$this
->
isProductValid
(
$product
,
$context
)
)
{
continue
;
}