Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
PropertyGroupEntity example
function
DCriteria
$criteria
)
{
static
::
assertContains
(
'red',
$criteria
->
getIds
(
)
)
;
static
::
assertContains
(
'green',
$criteria
->
getIds
(
)
)
;
static
::
assertContains
(
'xl',
$criteria
->
getIds
(
)
)
;
static
::
assertContains
(
'l',
$criteria
->
getIds
(
)
)
;
return
new
PropertyGroupOptionCollection
(
[
(
new
PropertyGroupOptionEntity
(
)
)
->
assign
(
[
'id' => 'red',
'groupId' => 'color',
'position' => 1,
'group'
=>
(
new
PropertyGroupEntity
(
)
)
->
assign
(
[
'id' => 'color',
'position' => 1,
]
)
,
]
)
,
(
new
PropertyGroupOptionEntity
(
)
)
->
assign
(
[
'id' => 'green',
'groupId' => 'color',
'position' => 2,
'group'
=>
(
new
PropertyGroupEntity
(
)
)
->
assign
(
[
'id' => 'color',
'position' => 2,
]
)
,
}
public
function
groupByPropertyGroups
(
)
: PropertyGroupCollection
{
$groups
=
new
PropertyGroupCollection
(
)
;
foreach
(
$this
->
getIterator
(
)
as
$element
)
{
if
(
$groups
->
has
(
$element
->
getGroupId
(
)
)
)
{
$group
=
$groups
->
get
(
$element
->
getGroupId
(
)
)
;
}
else
{
$group
= PropertyGroupEntity::
createFrom
(
$element
->
getGroup
(
)
??
new
PropertyGroupEntity
(
)
)
;
$groups
->
add
(
$group
)
;
$group
->
setOptions
(
new
self
(
)
)
;
}
if
(
$group
->
getOptions
(
)
)
{
$group
->
getOptions
(
)
->
add
(
$element
)
;
}
}
return
$groups
;
}
[
]
,
]
;
yield
'Test with valid product' =>
[
(
new
ProductEntity
(
)
)
->
assign
(
[
'_uniqueIdentifier' => Uuid::
randomHex
(
)
,
'options' =>
new
PropertyGroupOptionCollection
(
[
(
new
PropertyGroupOptionEntity
(
)
)
->
assign
(
[
'_uniqueIdentifier' => Uuid::
randomHex
(
)
,
'translated' =>
[
'name' => 'red'
]
,
'group'
=>
(
new
PropertyGroupEntity
(
)
)
->
assign
(
[
'_uniqueIdentifier' => Uuid::
randomHex
(
)
,
'translated' =>
[
'name' => 'color'
]
,
]
)
,
]
)
,
]
)
,
]
)
,
[
[
'group' => 'color', 'option' => 'red'
]
,
]
,
]
;
$propertyGroup
->
sortByConfig
(
)
;
$propertyOptionsArray
=
json_decode
(
json_encode
(
$propertyGroup
->
first
(
)
->
getOptions
(
)
, \JSON_THROW_ON_ERROR
)
, true, 512, \JSON_THROW_ON_ERROR
)
;
static
::
assertEquals
(
self::
$notShuffledName
,
array_column
(
$propertyOptionsArray
, 'name'
)
)
;
}
private
function
getPropertyGroupAlphaNumericOnlyNumbers
(
)
: PropertyGroupCollection
{
$propertyGroup
=
new
PropertyGroupEntity
(
)
;
$propertyGroup
->
setId
(
Uuid::
randomHex
(
)
)
;
$propertyGroup
->
setName
(
'Alphanumeric only numbers'
)
;
$propertyGroup
->
setSortingType
(
PropertyGroupDefinition::SORTING_TYPE_ALPHANUMERIC
)
;
$propertyGroup
->
setDisplayType
(
PropertyGroupDefinition::DISPLAY_TYPE_TEXT
)
;
$propertyGroup
->
setPosition
(
1
)
;
$propertyGroup
->
setOptions
(
$this
->
getPropertyOptionsOnlyNumbers
(
)
)
;
return
new
PropertyGroupCollection
(
[
$propertyGroup
]
)
;
}
private
function
getPropertyGroupAlphaNumericNumbersFirstThenLetters
(
)
: PropertyGroupCollection
{
$groups
=
new
PropertyGroupCollection
(
)
;
foreach
(
$this
->
getIterator
(
)
as
$element
)
{
if
(
!
$element
->
getOption
(
)
)
{
continue
;
}
if
(
$groups
->
has
(
$element
->
getOption
(
)
->
getGroupId
(
)
)
)
{
$group
=
$groups
->
get
(
$element
->
getOption
(
)
->
getGroupId
(
)
)
;
}
else
{
$group
= PropertyGroupEntity::
createFrom
(
$element
->
getOption
(
)
->
getGroup
(
)
??
new
PropertyGroupEntity
(
)
)
;
$groups
->
add
(
$group
)
;
$group
->
setOptions
(
new
PropertyGroupOptionCollection
(
)
)
;
}
if
(
$group
->
getOptions
(
)
)
{
$group
->
getOptions
(
)
->
add
(
$element
->
getOption
(
)
)
;
}
}
public
function
testGetDecoratedShouldThrowException
(
)
: void
{
static
::
expectException
(
DecorationPatternException::
class
)
;
$this
->searchIndexer->
getDecorated
(
)
;
}
public
function
testGlobalData
(
)
: void
{
$context
= Context::
createDefaultContext
(
)
;
$repository
=
$this
->
createMock
(
EntityRepository::
class
)
;
$propertyGroup
=
new
PropertyGroupEntity
(
)
;
$propertyGroup
->
setUniqueIdentifier
(
Uuid::
randomHex
(
)
)
;
$repository
->
method
(
'search'
)
->
willReturn
(
new
EntitySearchResult
(
'property_group',
1,
new
EntityCollection
(
[
$propertyGroup
]
)
,
null,
new
Criteria
(
)
,
$context
)
)
;