Skip to main content
Version: 4.1

Cart Context

CoreShop uses a system of context and context resolvers to determine the current cart.

The Cart Context adheres to the interface CoreShop\Component\Order\Context\CartContextInterface and is implemented in the service coreshop.context.cart.

Getting the Current Cart

To obtain the current cart, use the coreshop.context.cart service:

$cartContext = $container->get('coreshop.context.cart');

// Get current cart, if none exists, a new one is created
$cart = $cartContext->getCart();

Context Types

The table below outlines the various contexts used for cart determination:

NamePriorityDescription
FixedCartContext-100For testing or backend order creation.
SessionAndStoreBasedCartContext-555Searches for a valid session cart in the given store context.
CustomerAndStoreBasedCartContext-777Searches for a cart based on a customer, activates post-login to find the last cart a user left.
CartContext-999Creates a new cart if other contexts fail.

Create a Custom Resolver

To register a custom context, use the tag coreshop.context.cart with an optional priority attribute.