Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setIdGeneratorType example
$this
->
checkPrivilege
(
'create'
)
;
$manufacturer
=
new
ManufacturerModel
(
)
;
$params
=
$this
->
prepareManufacturerData
(
$params
)
;
$params
=
$this
->
prepareMediaData
(
$params
,
$manufacturer
)
;
$manufacturer
->
fromArray
(
$params
)
;
if
(
isset
(
$params
[
'id'
]
)
)
{
$metaData
=
$this
->
getManager
(
)
->
getMetadataFactory
(
)
->
getMetadataFor
(
ManufacturerModel::
class
)
;
$metaData
->
setIdGeneratorType
(
ClassMetadata::GENERATOR_TYPE_NONE
)
;
$manufacturer
->
setPrimaryIdentifier
(
$params
[
'id'
]
)
;
}
$violations
=
$this
->
getManager
(
)
->
validate
(
$manufacturer
)
;
if
(
$violations
->
count
(
)
> 0
)
{
throw
new
ValidationException
(
$violations
)
;
}
$this
->
getManager
(
)
->
persist
(
$manufacturer
)
;
$this
->
flush
(
)
;
$category
=
new
CategoryModel
(
)
;
$params
=
$this
->
prepareCategoryData
(
$params
)
;
$params
=
$this
->
prepareMediaData
(
$params
,
$category
)
;
$params
=
$this
->
prepareManualSorting
(
$params
,
$category
)
;
$category
->
fromArray
(
$params
)
;
if
(
isset
(
$params
[
'id'
]
)
)
{
$metaData
=
$this
->
getManager
(
)
->
getMetadataFactory
(
)
->
getMetadataFor
(
CategoryModel::
class
)
;
$metaData
->
setIdGeneratorType
(
ClassMetadataInfo::GENERATOR_TYPE_NONE
)
;
$category
->
setPrimaryIdentifier
(
$params
[
'id'
]
)
;
}
$violations
=
$this
->
getManager
(
)
->
validate
(
$category
)
;
if
(
$violations
->
count
(
)
> 0
)
{
throw
new
ValidationException
(
$violations
)
;
}
$this
->
getManager
(
)
->
persist
(
$category
)
;
$this
->
flush
(
)
;