Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
CmsBlockEntity example
)
;
}
private
function
getCmsPage
(
SalesChannelProductEntity
$productEntity
)
: CmsPageEntity
{
$cmsPageEntity
=
new
CmsPageEntity
(
)
;
$cmsSectionEntity
=
new
CmsSectionEntity
(
)
;
$cmsSectionEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsBlockEntity
=
new
CmsBlockEntity
(
)
;
$cmsBlockEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsSlotEntity
=
new
CmsSlotEntity
(
)
;
$cmsSlotEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsSlotEntity
->
setSlot
(
json_encode
(
$productEntity
->
getTranslated
(
)
, \JSON_THROW_ON_ERROR
)
)
;
$cmsBlockEntity
->
setSlots
(
new
CmsSlotCollection
(
[
$cmsSlotEntity
]
)
)
;
$cmsSectionEntity
->
setBlocks
(
new
CmsBlockCollection
(
[
$cmsBlockEntity
]
)
)
;
$cmsPageEntity
->
setSections
(
new
CmsSectionCollection
(
[
$cmsSectionEntity
]
)
)
;
return
$cmsPageEntity
;
}
)
;
}
private
function
getCmsPage
(
SalesChannelProductEntity
$productEntity
)
: CmsPageEntity
{
$cmsPageEntity
=
new
CmsPageEntity
(
)
;
$cmsSectionEntity
=
new
CmsSectionEntity
(
)
;
$cmsSectionEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsBlockEntity
=
new
CmsBlockEntity
(
)
;
$cmsBlockEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsSlotEntity
=
new
CmsSlotEntity
(
)
;
$cmsSlotEntity
->
setId
(
Uuid::
randomHex
(
)
)
;
$cmsSlotEntity
->
setSlot
(
json_encode
(
$productEntity
->
getTranslated
(
)
, \JSON_THROW_ON_ERROR
)
)
;
$cmsBlockEntity
->
setSlots
(
new
CmsSlotCollection
(
[
$cmsSlotEntity
]
)
)
;
$cmsSectionEntity
->
setBlocks
(
new
CmsBlockCollection
(
[
$cmsBlockEntity
]
)
)
;
$cmsPageEntity
->
setSections
(
new
CmsSectionCollection
(
[
$cmsSectionEntity
]
)
)
;
return
$cmsPageEntity
;
}
$collection
->
setSlots
(
$slots
)
;
/** @var CmsSlotEntity $lastSlot */
$lastSlot
=
$collection
->
getSlots
(
)
->
last
(
)
;
static
::
assertEquals
(
[
'overwrite' => true
]
,
$lastSlot
->
getConfig
(
)
)
;
}
private
function
getBlock
(
)
: CmsBlockEntity
{
$block
=
new
CmsBlockEntity
(
)
;
$block
->
setUniqueIdentifier
(
Uuid::
randomHex
(
)
)
;
$block
->
setType
(
'block'
)
;
$block
->
setSlots
(
new
CmsSlotCollection
(
[
$this
->
getSlot
(
)
,
$this
->
getSlot
(
)
,
$this
->
getSlot
(
)
,
$this
->
getSlot
(
)
,
$this
->
getSlot
(
)
,
]
)
)
;
$fieldConfig
=
new
FieldConfigCollection
(
)
;
$fieldConfig
->
add
(
new
FieldConfig
(
'product', FieldConfig::SOURCE_STATIC,
$product
->
getId
(
)
)
)
;
$slot
=
new
CmsSlotEntity
(
)
;
$slot
->
setUniqueIdentifier
(
'id'
)
;
$slot
->
setSlot
(
'product-box'
)
;
$slot
->
setType
(
'product-box'
)
;
$slot
->
setFieldConfig
(
$fieldConfig
)
;
$slot
->
getFieldConfig
(
)
;
$cmsBlock
=
new
CmsBlockEntity
(
)
;
$cmsBlock
->
setUniqueIdentifier
(
'block1'
)
;
$cmsBlock
->
setSlots
(
new
CmsSlotCollection
(
[
$slot
]
)
)
;
$cmsSection
=
new
CmsSectionEntity
(
)
;
$cmsSection
->
setUniqueIdentifier
(
'section1'
)
;
$cmsSection
->
setBlocks
(
new
CmsBlockCollection
(
[
$cmsBlock
]
)
)
;
$cmsPage
=
new
CmsPageEntity
(
)
;
$cmsPage
->
setSections
(
new
CmsSectionCollection
(
[
$cmsSection
]
)
)
;
$product
->
setCmsPage
(
$cmsPage
)
;