When adding an item to the cart that already exists (same ID), the cart always sums quantities and merges attributes. Some use cases need the ability to add the same product as a separate line item instead.
Add a configurable AddItemBehavior enum that controls what happens when addItem encounters a duplicate ID.
AddItemBehaviorUpdate — Sum quantities, merge attributes, keep conditions (current behavior)New — Always add as a separate line item with a unique suffixed ID// config/flexicart.php
'add_item_behavior' => 'update',
public function addItem(array|CartItem $item, ?AddItemBehavior $behavior = null): self
$behavior is null, resolve from config('flexicart.add_item_behavior')Update: existing updateExistingItem logic (no change)New: if the ID already exists, append :{n} suffix to create a unique IDWhen behavior is New and the base ID exists in the cart:
{id}:1, {id}:2, etc.CartInterface::addItem updated to accept the optional behavior parameter.
CommerceClientInterface::addToCart updated to accept and pass through the behavior parameter.
Both LocalCommerceDriver::addToCart and CommerceClient::addToCart gain an optional ?AddItemBehavior $behavior parameter, forwarded to Cart::addItem.
Create:
src/Enums/AddItemBehavior.phpModify:
config/flexicart.php — add add_item_behavior keysrc/Contracts/CartInterface.php — update addItem signaturesrc/Cart.php — update addItem to resolve and apply behaviorsrc/Contracts/CommerceClientInterface.php — update addToCart signaturesrc/Commerce/LocalCommerceDriver.php — pass behavior throughsrc/Commerce/CommerceClient.php — pass behavior throughHow can I help you explore Laravel packages today?