Skip to content

Add new cart events for modification of quantity #2851

@aashan10

Description

@aashan10

private function resolveItem(StorageListInterface $storageList, StorageListItemInterface $storageListItem): void
{
foreach ($storageList->getItems() as $item) {
if ($this->cartItemResolver->equals($item, $storageListItem)) {
$this->cartItemQuantityModifier->modify(
$item,
$item->getQuantity() + $storageListItem->getQuantity(),
);
return;
}
}
$this->eventDispatcher->dispatch(
new GenericEvent($storageList, ['item' => $storageListItem]),
CartEvents::PRE_ADD_ITEM,
);
$storageList->addItem($storageListItem);
$this->eventDispatcher->dispatch(
new GenericEvent($storageList, ['item' => $storageListItem]),
CartEvents::POST_ADD_ITEM,
);
}

We have events to intercept the addition/removal of items in cart, but there is no way of intercepting if an already existing item in cart has it's quantity changed.

For example, we want to conditionally verify that only x number of products can be added to the cart. An event like coreshop.cart.pre_item_quantity_modified would really be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions