Skip to main content
Version: 4.0

Cart Processor

The Cart Processor in CoreShop is responsible for refreshing the state and prices of carts. It is automatically triggered every time the persistCart function of the Cart-Manager is called on a cart, ensuring that the cart is re-calculated.

The following processors are implemented by default:

These processors handle all necessary price calculations for the cart. To extend cart calculations, a new processor should be created.

Creating a Cart Processor

To create a Cart Processor, implement the interface CoreShop\Component\Order\Processor\CartProcessorInterface. Register this in the container with the tag coreshop.cart_processor and a priority attribute.

Example of a Cart Processor

Here's an example of a custom Cart Processor that calculates a unique field for the cart:

<?php

namespace App\CoreShop\Order\Cart\Processor;

use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\Processor\CartProcessorInterface;

final class CustomCartProcessor implements CartProcessorInterface
{
public function process(OrderInterface $cart): void
{
$cart->setCustomField(uniqid());
}
}

Registration of the processor:

App\CoreShop\Order\Cart\Processor\CustomCartProcessor:
tags:
- { name: coreshop.cart_processor, priority: 200 }

This custom processor will now assign a new unique ID to the custom field on every cart update.