CoreShop Cart

CoreShop uses Pimcore Data Objects to persist Cart Information. But, it adds a little wrapper around it to be mire dynamic and configurable. It uses a Factory and Repository Pattern to do that.

Create

If you want to create a new Cart, we need to get our Factory Service for that:

$factory = $container->get('coreshop.factory.cart');
$cart = $factory->createNew();

No we have a new Cart and we can set all needed values.

If you now want to save it, just call the save function

$cart->save();

Read

To get carts, you need to use the Repository Service CoreShop provides you.

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


// Query by ID
$cartWithIdOne = $repository->findById(1);

// Get a Listing how you know it from Pimcore
$list = $repository->getList();
$list->setCondition("total > 100");
$carts = $list->getObjects();

Update

Update works the same as you are used to in Pimcore

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


// Query by ID
$cartWithIdOne = $repository->findById(1);

// Change values
$cartWithIdOne->setCustomer($customer);
$cartWithIdOne->save();

Delete

Delete works the same as you are used to in Pimcore

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


// Query by ID
$cartWithIdOne = $repository->findById(1);
$cartWithIdOne->delete();