Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
markUnmodified example
$productId2
=
$this
->
createProduct
(
$currentContext
->
getContext
(
)
)
;
$productLineItem1
=
new
LineItem
(
$productId1
, LineItem::PRODUCT_LINE_ITEM_TYPE,
$productId1
)
;
$productLineItem2
=
new
LineItem
(
$productId2
, LineItem::PRODUCT_LINE_ITEM_TYPE,
$productId2
)
;
$productLineItem1
->
setStackable
(
true
)
;
$productLineItem2
->
setStackable
(
true
)
;
$productLineItem1
->
setQuantity
(
1
)
;
$guestProductQuantity
= 5;
$productLineItem2
->
setQuantity
(
$guestProductQuantity
)
;
$previousCart
->
addLineItems
(
new
LineItemCollection
(
[
$productLineItem1
,
$productLineItem2
]
)
)
;
$previousCart
->
markUnmodified
(
)
;
$cartMergedEvent
=
new
CartMergedEvent
(
new
Cart
(
'customerToken'
)
,
$currentContext
,
$previousCart
)
;
$subscriber
->
addCartMergedNoticeFlash
(
$cartMergedEvent
)
;
static
::
assertNotEmpty
(
$infoFlash
=
$session
->
getFlashBag
(
)
->
get
(
'info'
)
)
;
static
::
assertEquals
(
'checkout.cart-merged-hint',
$infoFlash
[
0
]
)
;
}
/** * @param array<string, mixed> $salesChannelData */
}
public
function
calculate
(
Cart
$cart
, SalesChannelContext
$context
)
: Cart
{
return
Profiler::
trace
(
'cart-calculation',
function
D
)
use
(
$cart
,
$context
)
{
// validate cart against the context rules
$cart
=
$this
->cartRuleLoader
->
loadByCart
(
$context
,
$cart
,
new
CartBehavior
(
$context
->
getPermissions
(
)
)
)
->
getCart
(
)
;
$cart
->
markUnmodified
(
)
;
foreach
(
$cart
->
getLineItems
(
)
->
getFlat
(
)
as
$lineItem
)
{
$lineItem
->
markUnmodified
(
)
;
}
return
$cart
;
}
)
;
}
}
$this
->contextPersister->
save
(
$customerContextToken
,
[
]
,
$customerContext
->
getSalesChannel
(
)
->
getId
(
)
,
$this
->customerId
)
;
$cart
=
new
Cart
(
$customerContextToken
)
;
$productId
=
$this
->
createProduct
(
$customerContext
->
getContext
(
)
)
;
$productLineItem
=
new
LineItem
(
Uuid::
randomHex
(
)
, LineItem::PRODUCT_LINE_ITEM_TYPE,
$productId
)
;
$productLineItem
->
setStackable
(
true
)
;
$productLineItem
->
setQuantity
(
1
)
;
$cart
->
add
(
$productLineItem
)
;
$cart
->
markUnmodified
(
)
;
static
::
assertCount
(
1,
$cart
->
getLineItems
(
)
)
;
$this
->
getContainer
(
)
->
get
(
CartPersister::
class
)
->
save
(
$cart
,
$customerContext
)
;
$this
->
getContainer
(
)
->
get
(
'product.repository'
)
->
delete
(
[
[
'id' =>
$productId
,
]
]
,
$customerContext
->
getContext
(
)
)
;
$guestContext
=
$this
->
createSalesChannelContext
(
'123123'
)
;
$restoreContext
=
$this
->cartRestorer->
restore
(
$this
->customerId,
$guestContext
)
;
$product
=
array_replace_recursive
(
$default
,
$options
)
;
$this
->
getContainer
(
)
->
get
(
'product.repository'
)
->
create
(
[
$product
]
, Context::
createDefaultContext
(
)
)
;
$this
->
addTaxDataToSalesChannel
(
$this
->salesChannelContext,
$product
[
'tax'
]
)
;
$lineItem
=
$this
->
getContainer
(
)
->
get
(
ProductLineItemFactory::
class
)
->
create
(
[
'id' =>
$id
, 'referencedId' =>
$id
]
,
$this
->salesChannelContext
)
;
$lineItem
->
markUnmodified
(
)
;
$lineItem
->
assign
(
[
'uniqueIdentifier' => 'foo'
]
)
;
$cart
->
add
(
$lineItem
)
;
$cart
=
$this
->
getContainer
(
)
->
get
(
Processor::
class
)
->
process
(
$cart
,
$this
->salesChannelContext,
new
CartBehavior
(
)
)
;
return
$cart
;
}