Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setDirty example
$isSingleSnippet
= false;
$result
=
[
]
;
if
(
\
array_key_exists
(
'namespace',
$snippets
)
)
{
$snippets
=
[
$snippets
]
;
$isSingleSnippet
= true;
}
foreach
(
$snippets
as
$params
)
{
$snippet
=
new
Snippet
(
)
;
$snippet
->
fromArray
(
$params
)
;
$snippet
->
setDirty
(
true
)
;
if
(
!
$this
->
isSnippetValid
(
$snippet
)
)
{
$result
[
$snippet
->
getId
(
)
]
=
$params
;
continue
;
}
try
{
$this
->
get
(
'models'
)
->
persist
(
$snippet
)
;
$this
->
get
(
'models'
)
->
flush
(
)
;
}
catch
(
Exception
$e
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' =>
$e
->
getMessage
(
)
]
)
;
// Save data of the category tree
$params
[
'categories'
]
=
$this
->
prepareAssociationDataForSaving
(
'categories', Category::
class
,
$params
)
;
// Save data of the supplier filter
$params
[
'suppliers'
]
=
$this
->
prepareAssociationDataForSaving
(
'suppliers', Supplier::
class
,
$params
)
;
// Save data of the article filter
$params
[
'articles'
]
=
$this
->
prepareAssociationDataForSaving
(
'articles', Article::
class
,
$params
)
;
$productFeed
=
$this
->
setDirty
(
$productFeed
,
$params
)
;
$params
[
'fileName'
]
=
basename
(
$params
[
'fileName'
]
)
;
$productFeed
->
fromArray
(
$params
)
;
// Just for future use
$productFeed
->
setExpiry
(
new
DateTime
(
)
)
;
$productFeed
->
setLastChange
(
new
DateTime
(
)
)
;
// Clear feed cache
$cacheDir
=
$this
->container->
getParameter
(
'shopware.product_export.cache_dir'
)
;
if
(
!\
is_string
(
$cacheDir
)
)
{
throw
new
RuntimeException
(
'Parameter shopware.product_export.cache_dir has to be an string'
)
;
}