Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
setDataTimestamp example
// add products to data collection
foreach
(
$products
as
$product
)
{
$data
->
set
(
$this
->
getDataKey
(
$product
->
getId
(
)
)
,
$product
)
;
}
$hash
=
$this
->generator->
getSalesChannelContextHash
(
$context
,
[
RuleAreas::PRODUCT_AREA
]
)
;
// refresh data timestamp to prevent unnecessary gateway calls
foreach
(
$items
as
$lineItem
)
{
if
(
!\
in_array
(
$lineItem
->
getReferencedId
(
)
,
$products
->
getIds
(
)
, true
)
)
{
$lineItem
->
setDataTimestamp
(
null
)
;
continue
;
}
$lineItem
->
setDataTimestamp
(
new
\
DateTimeImmutable
(
)
)
;
$lineItem
->
setDataContextHash
(
$hash
)
;
}
}
foreach
(
$lineItems
as
$match
)
{
// enrich all products in original cart
$this
->
enrich
(
$context
,
$match
[
'item'
]
,
$data
,
$behavior
)
;
$payloadProtection
->
setValue
(
$position
->
getLineItem
(
)
,
[
]
)
;
foreach
(
$position
->
getLineItem
(
)
->
getChildren
(
)
as
$lineItem
)
{
$payloadProtection
->
setValue
(
$lineItem
,
[
]
)
;
}
}
}
}
private
function
resetDataTimestamps
(
LineItemCollection
$items
)
: void
{
foreach
(
$items
as
$item
)
{
$item
->
setDataTimestamp
(
null
)
;
$item
->
setDataContextHash
(
null
)
;
$this
->
resetDataTimestamps
(
$item
->
getChildren
(
)
)
;
}
}
private
function
removeExtensions
(
Cart
$cart
)
: void
{
$this
->
removeLineItemsExtension
(
$cart
->
getLineItems
(
)
)
;
foreach
(
$cart
->
getDeliveries
(
)
as
$delivery
)
{
$delivery
->
setExtensions
(
[
]
)
;