mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
ideas revisited, cart to carts rename.
This commit is contained in:
parent
7f913aa76e
commit
922fa343d6
49 changed files with 1357 additions and 478 deletions
|
|
@ -9,23 +9,22 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Command;
|
||||
namespace Sylius\Bundle\CartsBundle\Command;
|
||||
|
||||
use Sylius\Bundle\CartBundle\EventDispatcher\SyliusCartEvents;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\Output;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* Command for console that deletes expired carts.
|
||||
*
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class FlushCommand extends ContainerAwareCommand
|
||||
class FlushCartsCommand extends ContainerAwareCommand
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -33,14 +32,16 @@ class FlushCommand extends ContainerAwareCommand
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('sylius:cart:flush')
|
||||
->setName('sylius:carts:flush')
|
||||
->setDescription('Deletes expried carts.')
|
||||
->setHelp(<<<EOT
|
||||
The <info>sylius:cart:clean</info> command deletes expired carts:
|
||||
->setHelp(
|
||||
<<<EOT
|
||||
The <info>sylius:carts:flush</info> command deletes expired carts:
|
||||
|
||||
<info>php sylius/console sylius:cart:clean</info>
|
||||
<info>php sylius/console sylius:carts:flush</info>
|
||||
EOT
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -51,6 +52,6 @@ EOT
|
|||
$this->getContainer()->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_FLUSH);
|
||||
$this->getContainer()->get('sylius_cart.manager.cart')->flushCarts();
|
||||
|
||||
$output->writeln('<info>[Sylius]</info> Deleted expired carts.');
|
||||
$output->writeln('<info>[Sylius:Carts]</info> Deleted expired carts.');
|
||||
}
|
||||
}
|
||||
|
|
@ -11,149 +11,139 @@
|
|||
|
||||
namespace Sylius\Bundle\CartBundle\Controller\Frontend;
|
||||
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Sylius\Bundle\CartBundle\EventDispatcher\Event\CartOperationEvent;
|
||||
use Sylius\Bundle\CartBundle\EventDispatcher\Event\FilterCartEvent;
|
||||
use Sylius\Bundle\CartBundle\EventDispatcher\SyliusCartEvents;
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Cart frontend controller.
|
||||
*
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class CartController extends ContainerAware
|
||||
{
|
||||
/**
|
||||
* Displays cart.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function showAction()
|
||||
{
|
||||
$cart = $this->container->get('sylius_cart.provider')->getCart();
|
||||
|
||||
$form = $this->container->get('form.factory')->create($this->container->get('sylius_cart.form.type.cart'));
|
||||
$form->setData($cart);
|
||||
|
||||
return $this->container->get('templating')->renderResponse('SyliusCartBundle:Frontend/Cart:show.html.' . $this->getEngine(), array(
|
||||
'cart' => $cart,
|
||||
'form' => $form->createView()
|
||||
$cart = $this->container->get('sylius_carts.provider')->getCart();
|
||||
|
||||
$form = $this->container->get('form.factory')->create('sylius_cart_show');
|
||||
$form->setData($cart);
|
||||
|
||||
return $this->container->get('templating')->renderResponse('SyliusCartBundle:Frontend/Cart:show.html.'.$this->getEngine(), array(
|
||||
'cart' => $cart,
|
||||
'form' => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds item to cart.
|
||||
*/
|
||||
public function addItemAction()
|
||||
{
|
||||
$itemManager = $this->container->get('sylius_cart.manager.item');
|
||||
$item = $itemManager->createItem();
|
||||
|
||||
$form = $this->container->get('form.factory')->create($this->container->get('sylius_cart.form.type.item'));
|
||||
$form->setData($item);
|
||||
$form->bindRequest($this->container->get('request'));
|
||||
|
||||
if ($form->isValid()) {
|
||||
$cart = $this->container->get('sylius_cart.provider')->getCart();
|
||||
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_ADD, new CartOperationEvent($item, $cart));
|
||||
|
||||
$cartOperator = $this->container->get('sylius_cart.operator');
|
||||
$cartOperator->addItem($cart, $item);
|
||||
$cartOperator->refreshCart($cart);
|
||||
|
||||
$cartManager = $this->container->get('sylius_cart.manager.cart');
|
||||
|
||||
$cartManager->persistCart($cart);
|
||||
$cartManager->flushCarts();
|
||||
/**
|
||||
* Adds item to cart.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function addItemAction(Request $request)
|
||||
{
|
||||
$cart = $this->container->get('sylius_carts.provider')->getCart();
|
||||
$item = $this->container->get('sylius_carts.resolver')->resolveItemToAdd($request);
|
||||
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('Requested item could not be added to cart');
|
||||
}
|
||||
|
||||
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_ADD, new CartOperationEvent($cart, $item));
|
||||
|
||||
$cartOperator = $this->container->get('sylius_carts.operator');
|
||||
$cartOperator->addItem($cart, $item);
|
||||
$cartOperator->refresh($cart);
|
||||
$cartOperator->save($cart);
|
||||
|
||||
return new RedirectResponse($this->container->get('router')->generate('sylius_cart_show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes item from cart.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function removeItemAction($id)
|
||||
public function removeItemAction(Request $request)
|
||||
{
|
||||
$itemManager = $this->container->get('sylius_cart.manager.item');
|
||||
$item = $itemManager->findItem($id);
|
||||
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('This cart item does not exist.');
|
||||
}
|
||||
|
||||
$cart = $this->container->get('sylius_cart.provider')->getCart();
|
||||
$cart = $this->container->get('sylius_carts.provider')->getCart();
|
||||
$item = $this->container->get('sylius_carts.resolver')->resolveItemToRemove($request);
|
||||
|
||||
if ($item->getCart() !== $cart) {
|
||||
throw new NotFoundHttpException('This cart item is not accessible.');
|
||||
if (!$item) {
|
||||
throw new NotFoundHttpException('Requested item could not be removed from cart');
|
||||
}
|
||||
|
||||
$cartOperator = $this->container->get('sylius_cart.operator');
|
||||
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_REMOVE, new CartOperationEvent($item, $cart));
|
||||
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_REMOVE, new CartOperationEvent($cart, $item));
|
||||
|
||||
$cartOperator = $this->container->get('sylius_carts.operator');
|
||||
$cartOperator->removeItem($cart, $item);
|
||||
$cartOperator->refreshCart($cart);
|
||||
|
||||
$itemManager->removeItem($item);
|
||||
|
||||
$this->container->get('sylius_cart.manager.cart')->persistCart($cart);
|
||||
|
||||
$cartOperator->refresh($cart);
|
||||
$cartOperator->save($cart);
|
||||
|
||||
return new RedirectResponse($this->container->get('router')->generate('sylius_cart_show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves cart.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
$cart = $this->container->get('sylius_cart.provider')->getCart();
|
||||
|
||||
$form = $this->container->get('form.factory')->create($this->container->get('sylius_cart.form.type.cart'));
|
||||
$form->setData($cart);
|
||||
$form->bindRequest($this->container->get('request'));
|
||||
|
||||
if ($form->isValid()) {
|
||||
$cartOperator = $this->container->get('sylius_cart.operator');
|
||||
|
||||
$existingItems = array();
|
||||
|
||||
foreach ($cart->getItems() as $item) {
|
||||
$existingItems[] = $item;
|
||||
public function saveAction(Request $request)
|
||||
{
|
||||
$cart = $this->container->get('sylius_carts.provider')->getCart();
|
||||
|
||||
$form = $this->container->get('form.factory')->create('sylius_cartss_cart');
|
||||
$form->setData($cart);
|
||||
$form->bindRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$cartOperator = $this->container->get('sylius_carts.operator');
|
||||
|
||||
if ($cartOperator->validate($cart)) {
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_SAVE, new FilterCartEvent($cart));
|
||||
$cartOperator->refreshCart($cart);
|
||||
$cartOperator->save($cart);
|
||||
}
|
||||
|
||||
$cart->clearItems();
|
||||
|
||||
foreach($existingItems as $item) {
|
||||
$cartOperator->addItem($cart, $item);
|
||||
}
|
||||
|
||||
$this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_UPDATE, new FilterCartEvent($cart));
|
||||
$cartOperator->refreshCart($cart);
|
||||
|
||||
$this->container->get('sylius_cart.manager.cart')->persistCart($cart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new RedirectResponse($this->container->get('router')->generate('sylius_cart_show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes cart.
|
||||
* Clears cart.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function clearAction()
|
||||
{
|
||||
$this->container->get('sylius_cart.manager.cart')->removeCart($this->container->get('sylius_cart.provider')->getCart());
|
||||
|
||||
$this->container->get('sylius_carts.operator')->clear($this->container->get('sylius_cart.provider')->getCart());
|
||||
|
||||
return new RedirectResponse($this->container->get('router')->generate('sylius_cart_show'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns templating engine name.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getEngine()
|
||||
{
|
||||
return $this->container->getParameter('sylius_cart.engine');
|
||||
return $this->container->getParameter('sylius_carts.engine');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,12 +9,11 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\DependencyInjection;
|
||||
namespace Sylius\Bundle\CartsBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
|
||||
/**
|
||||
* This class contains the configuration information for the bundle.
|
||||
|
|
@ -27,14 +26,12 @@ use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
|||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* Generates the configuration tree.
|
||||
*
|
||||
* @return \Symfony\Component\DependencyInjection\Configuration\NodeInterface
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder();
|
||||
$rootNode = $treeBuilder->root('sylius_cart');
|
||||
$rootNode = $treeBuilder->root('sylius_carts');
|
||||
|
||||
$rootNode
|
||||
->addDefaultsIfNotSet()
|
||||
|
|
@ -42,6 +39,7 @@ class Configuration implements ConfigurationInterface
|
|||
->scalarNode('driver')->cannotBeOverwritten()->isRequired()->cannotBeEmpty()->end()
|
||||
->scalarNode('engine')->defaultValue('twig')->end()
|
||||
->scalarNode('operator')->cannotBeOverwritten()->cannotBeEmpty()->end()
|
||||
->scalarNode('storage')->defaultValue('sylius_carts.storage.session')->end()
|
||||
->end();
|
||||
|
||||
$this->addClassesSection($rootNode);
|
||||
|
|
|
|||
|
|
@ -9,23 +9,23 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\DependencyInjection;
|
||||
namespace Sylius\Bundle\CartsBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* Cart extension.
|
||||
* Carts extension.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class SyliusCartExtension extends Extension
|
||||
class SyliusCartsExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* @see Extension/Symfony\Component\DependencyInjection\Extension.ExtensionInterface::load()
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $config, ContainerBuilder $container)
|
||||
{
|
||||
|
|
@ -36,7 +36,7 @@ class SyliusCartExtension extends Extension
|
|||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container'));
|
||||
|
||||
if (!in_array($config['driver'], array('ORM'))) {
|
||||
if (!in_array($config['driver'], array('doctrine/orm'))) {
|
||||
throw new \InvalidArgumentException(sprintf('Driver "%s" is unsupported for this extension.', $config['driver']));
|
||||
}
|
||||
|
||||
|
|
@ -47,17 +47,19 @@ class SyliusCartExtension extends Extension
|
|||
$loader->load(sprintf('driver/%s.xml', $config['driver']));
|
||||
$loader->load(sprintf('engine/%s.xml', $config['engine']));
|
||||
|
||||
$container->setParameter('sylius_cart.driver', $config['driver']);
|
||||
$container->setParameter('sylius_cart.engine', $config['engine']);
|
||||
$container->setParameter('sylius_carts.driver', $config['driver']);
|
||||
$container->setParameter('sylius_carts.engine', $config['engine']);
|
||||
|
||||
$container->setAlias('sylius_cart.operator', $config['operator']);
|
||||
$container->setAlias('sylius_carts.operator', $config['operator']);
|
||||
$container->setAlias('sylius_carts.resolver', $config['resolver']);
|
||||
$container->setAlias('sylius_carts.storage', $config['storage']);
|
||||
|
||||
$container->setParameter('sylius_cart.provider.class', $config['classes']['provider']);
|
||||
$container->setParameter('sylius_carts.provider.class', $config['classes']['provider']);
|
||||
|
||||
$configurations = array(
|
||||
'controllers',
|
||||
'forms',
|
||||
'provider',
|
||||
'provider'
|
||||
);
|
||||
|
||||
foreach($configurations as $basename) {
|
||||
|
|
@ -65,27 +67,20 @@ class SyliusCartExtension extends Extension
|
|||
}
|
||||
|
||||
$this->remapParametersNamespaces($config['classes'], $container, array(
|
||||
'model' => 'sylius_cart.model.%s.class',
|
||||
'listener' => 'sylius_cart.listener.%s.class',
|
||||
'listener' => 'sylius_carts.listener.%s.class',
|
||||
'model' => 'sylius_carts.model.%s.class',
|
||||
));
|
||||
|
||||
$this->remapParametersNamespaces($config['classes']['controller'], $container, array(
|
||||
'backend' => 'sylius_cart.controller.backend.%s.class',
|
||||
'frontend' => 'sylius_cart.controller.frontend.%s.class'
|
||||
'backend' => 'sylius_carts.controller.backend.%s.class',
|
||||
'frontend' => 'sylius_carts.controller.frontend.%s.class'
|
||||
));
|
||||
|
||||
$this->remapParametersNamespaces($config['classes']['form'], $container, array(
|
||||
'type' => 'sylius_cart.form.type.%s.class',
|
||||
'type' => 'sylius_carts.form.type.%s.class',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap parameters.
|
||||
*
|
||||
* @param $config
|
||||
* @param ContainerBuilder $container
|
||||
* @param $map
|
||||
*/
|
||||
protected function remapParameters(array $config, ContainerBuilder $container, array $map)
|
||||
{
|
||||
foreach ($map as $name => $paramName) {
|
||||
|
|
@ -95,13 +90,6 @@ class SyliusCartExtension extends Extension
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remap parameter namespaces.
|
||||
*
|
||||
* @param $config
|
||||
* @param ContainerBuilder $container
|
||||
* @param $map
|
||||
*/
|
||||
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces)
|
||||
{
|
||||
foreach ($namespaces as $ns => $map) {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<?php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
|
|
@ -9,12 +9,11 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Entity;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Model\ItemInterface;
|
||||
namespace Sylius\Bundle\CartsBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Sylius\Bundle\CartBundle\Model\Cart as BaseCart;
|
||||
use Sylius\Bundle\CartsBundle\Model\Cart as BaseCart;
|
||||
use Sylius\Bundle\CartsBundle\Model\ItemInterface;
|
||||
|
||||
/**
|
||||
* Cart entity.
|
||||
|
|
@ -23,13 +22,19 @@ use Sylius\Bundle\CartBundle\Model\Cart as BaseCart;
|
|||
*/
|
||||
class Cart extends BaseCart
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
|
||||
$this->items = new ArrayCollection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addItem(ItemInterface $item)
|
||||
{
|
||||
if (!$this->hasItem($item)) {
|
||||
|
|
@ -37,7 +42,10 @@ class Cart extends BaseCart
|
|||
$item->setCart($this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeItem(ItemInterface $item)
|
||||
{
|
||||
if ($this->hasItem($item)) {
|
||||
|
|
@ -45,12 +53,18 @@ class Cart extends BaseCart
|
|||
$item->setCart(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasItem(ItemInterface $item)
|
||||
{
|
||||
return $this->items->contains($item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearItems()
|
||||
{
|
||||
$this->items->clear();
|
||||
|
|
|
|||
|
|
@ -9,54 +9,57 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Entity;
|
||||
namespace Sylius\Bundle\CartsBundle\Entity;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\CartManager as BaseCartManager;
|
||||
use Symfony\Component\HttpFoundation\Session;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Bundle\CartsBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\CartManager as BaseCartManager;
|
||||
|
||||
/**
|
||||
* Cart manager.
|
||||
*
|
||||
* Cart manager for doctrine/orm driver.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class CartManager extends BaseCartManager
|
||||
{
|
||||
/**
|
||||
* Entity Manager.
|
||||
*
|
||||
*
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
|
||||
/**
|
||||
* Carts repository.
|
||||
*
|
||||
* @var EntityRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param EntityManager $entityManager
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager, $class)
|
||||
{
|
||||
parent::__construct($class);
|
||||
|
||||
$this->entityManager = $entityManager;
|
||||
|
||||
$this->entityManager = $entityManager;
|
||||
$this->repository = $this->entityManager->getRepository($class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createCart()
|
||||
{
|
||||
$class = $this->getClass();
|
||||
|
||||
return new $class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -65,7 +68,7 @@ class CartManager extends BaseCartManager
|
|||
$this->entityManager->persist($cart);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -74,23 +77,26 @@ class CartManager extends BaseCartManager
|
|||
$this->entityManager->remove($cart);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
public function flushCarts()
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearCarts()
|
||||
{
|
||||
$expiredCarts = $this->entityManager->createQueryBuilder()
|
||||
->select('c')
|
||||
->from($this->getClass(), 'c')
|
||||
->where('c.locked = false AND c.expiresAt < ?1')
|
||||
->setParameter(1, new \DateTime)
|
||||
->setParameter(1, new \DateTime("now"))
|
||||
->getQuery()
|
||||
->getResult()
|
||||
;
|
||||
|
||||
|
||||
foreach ($expiredCarts as $cart) {
|
||||
$this->removeCart($cart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -98,7 +104,7 @@ class CartManager extends BaseCartManager
|
|||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -106,7 +112,7 @@ class CartManager extends BaseCartManager
|
|||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -114,7 +120,7 @@ class CartManager extends BaseCartManager
|
|||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
namespace Sylius\Bundle\CartBundle\Entity;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Bundle\CartBundle\Model\ItemInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\ItemManager as BaseItemManager;
|
||||
|
||||
|
|
@ -19,38 +20,41 @@ class ItemManager extends BaseItemManager
|
|||
{
|
||||
/**
|
||||
* Entity Manager.
|
||||
*
|
||||
*
|
||||
* @var EntityManager
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
|
||||
/**
|
||||
* Items repository.
|
||||
*
|
||||
* @var EntityRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param EntityManager $entityManager
|
||||
*/
|
||||
public function __construct(EntityManager $entityManager, $class)
|
||||
{
|
||||
parent::__construct($class);
|
||||
|
||||
$this->entityManager = $entityManager;
|
||||
$this->repository = $this->entityManager->getRepository($class);
|
||||
|
||||
$this->entityManager = $entityManager;
|
||||
$this->repository = $this->entityManager->getRepository($class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createItem()
|
||||
{
|
||||
$class = $this->getClass();
|
||||
|
||||
return new $class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -59,7 +63,7 @@ class ItemManager extends BaseItemManager
|
|||
$this->entityManager->persist($cart);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -68,7 +72,7 @@ class ItemManager extends BaseItemManager
|
|||
$this->entityManager->remove($cart);
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -76,7 +80,7 @@ class ItemManager extends BaseItemManager
|
|||
{
|
||||
return $this->repository->find($id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -84,7 +88,7 @@ class ItemManager extends BaseItemManager
|
|||
{
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -92,7 +96,7 @@ class ItemManager extends BaseItemManager
|
|||
{
|
||||
return $this->repository->findAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Sylius\Bundle\CartBundle\EventDispatcher\Event;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Model\ItemInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\ItemInterface;
|
||||
|
||||
/**
|
||||
* Cart operation event.
|
||||
|
|
@ -21,17 +21,33 @@ use Sylius\Bundle\CartBundle\Model\CartInterface;
|
|||
*/
|
||||
final class CartOperationEvent extends FilterCartEvent
|
||||
{
|
||||
/**
|
||||
* Cart item.
|
||||
*
|
||||
* @var ItemInterface
|
||||
*/
|
||||
private $item;
|
||||
|
||||
public function __construct(ItemInterface $item, CartInterface $cart)
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
public function __construct(CartInterface $cart, ItemInterface $item)
|
||||
{
|
||||
$this->item = $item;
|
||||
|
||||
|
||||
parent::__construct($cart);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns item.
|
||||
*
|
||||
* @return ItemInterface
|
||||
*/
|
||||
public function getItem()
|
||||
{
|
||||
return $this->item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Sylius\Bundle\CartBundle\EventDispatcher\Event;
|
||||
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Filter cart event.
|
||||
|
|
@ -21,15 +21,30 @@ use Sylius\Bundle\CartBundle\Model\CartInterface;
|
|||
*/
|
||||
class FilterCartEvent extends Event
|
||||
{
|
||||
/**
|
||||
* Cart.
|
||||
*
|
||||
* @var CartInterface
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
public function __construct(CartInterface $cart)
|
||||
{
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns cart.
|
||||
*
|
||||
* @return CartInterface
|
||||
*/
|
||||
public function getCart()
|
||||
{
|
||||
return $this->cart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,18 +9,18 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\EventDispatcher;
|
||||
namespace Sylius\Bundle\CartsBundle\EventDispatcher;
|
||||
|
||||
/**
|
||||
* Events.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
final class SyliusCartEvents
|
||||
final class SyliusCartsEvents
|
||||
{
|
||||
const ITEM_ADD = 'sylius_cart.event.item.add';
|
||||
const ITEM_ADD = 'sylius_cart.event.item.add';
|
||||
const ITEM_REMOVE = 'sylius_cart.event.item.remove';
|
||||
const CART_UPDATE = 'sylius_cart.event.cart.update';
|
||||
const CART_CLEAR = 'sylius_cart.event.cart.clear';
|
||||
const CART_FLUSH = 'sylius_cart.event.cart.flush';
|
||||
const CART_CLEAR = 'sylius_cart.event.cart.clear';
|
||||
const CART_FLUSH = 'sylius_cart.event.cart.flush';
|
||||
}
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
namespace Sylius\Bundle\CartBundle\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilder;
|
||||
|
||||
/**
|
||||
* Cart form form.
|
||||
|
|
@ -23,21 +23,21 @@ class CartFormType extends AbstractType
|
|||
{
|
||||
/**
|
||||
* Data class.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dataClass;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param string $dataClass
|
||||
*/
|
||||
public function __construct($dataClass)
|
||||
{
|
||||
$this->dataClass = $dataClass;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -47,7 +47,7 @@ class CartFormType extends AbstractType
|
|||
'type' => 'sylius_cart_item',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -57,12 +57,12 @@ class CartFormType extends AbstractType
|
|||
'data_class' => $this->dataClass
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'sylius_cart';
|
||||
return 'sylius_carts_cart';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,60 +9,62 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Model for carts.
|
||||
*
|
||||
* All driver entities and documents should extend this class or implement
|
||||
* proper interface.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
abstract class Cart implements CartInterface
|
||||
{
|
||||
{
|
||||
/**
|
||||
* Id.
|
||||
*
|
||||
* @var integer
|
||||
* Id.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
|
||||
/**
|
||||
* Items in cart.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $items;
|
||||
|
||||
|
||||
/**
|
||||
* Total items count.
|
||||
*
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $totalItems;
|
||||
|
||||
|
||||
/**
|
||||
* Locked.
|
||||
*
|
||||
*
|
||||
* @var Boolean
|
||||
*/
|
||||
protected $locked;
|
||||
|
||||
|
||||
/**
|
||||
* Expiration time.
|
||||
*
|
||||
*
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $expiresAt;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
{
|
||||
$this->totalItems = 0;
|
||||
$this->locked = false;
|
||||
$this->incrementExpiresAt();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -70,22 +72,31 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isLocked()
|
||||
{
|
||||
return $this->locked;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setLocked($locked)
|
||||
{
|
||||
$this->locked = $locked;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function incrementTotalItems($amount = 1)
|
||||
{
|
||||
$this->totalItems += $amount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -93,7 +104,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
$this->totalItems = $totalItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -101,7 +112,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return $this->totalItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -109,7 +120,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return 0 === $this->countItems();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -117,7 +128,10 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setItems($items)
|
||||
{
|
||||
$this->items = $items;
|
||||
|
|
@ -144,7 +158,7 @@ abstract class Cart implements CartInterface
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeItem(ItemInterface $item)
|
||||
|
|
@ -155,7 +169,7 @@ abstract class Cart implements CartInterface
|
|||
$item->setCart(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -163,7 +177,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return $this === $item->getCart();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -171,12 +185,15 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
$this->items = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isExpired()
|
||||
{
|
||||
return $this->getExpiresAt() < new \DateTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -184,7 +201,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
return $this->expiresAt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -192,7 +209,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
$this->expiresAt = $expiresAt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -200,7 +217,7 @@ abstract class Cart implements CartInterface
|
|||
{
|
||||
$expiresAt = new \DateTime();
|
||||
$expiresAt->add(new \DateInterval('PT3H'));
|
||||
|
||||
|
||||
$this->expiresAt = $expiresAt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,30 +9,131 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Cart model interface.
|
||||
* All driver cart entities or documents should implement this interface.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
interface CartInterface
|
||||
{
|
||||
/**
|
||||
* Returns number of items in cart.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
function getTotalItems();
|
||||
|
||||
/**
|
||||
* Sets number of items in cart.
|
||||
*
|
||||
* @param integer $totalItems;
|
||||
*/
|
||||
function setTotalItems($totalItems);
|
||||
|
||||
/**
|
||||
* Increments total items number by given amount.
|
||||
* Default is 1.
|
||||
*
|
||||
* @param integer $amount
|
||||
*/
|
||||
function incrementTotalItems($amount = 1);
|
||||
|
||||
/**
|
||||
* Checks whether the cart is locked or not.
|
||||
* If cart is left unlocked, it should be deleted after expiration time.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function isLocked();
|
||||
|
||||
/**
|
||||
* Sets whether the cart is locked or not.
|
||||
*
|
||||
* @param Boolean $locked
|
||||
*/
|
||||
function setLocked($locked);
|
||||
|
||||
/**
|
||||
* Checks whether the cart is empty or not.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function isEmpty();
|
||||
|
||||
/**
|
||||
* Counts manually all items in cart.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
function countItems();
|
||||
|
||||
/**
|
||||
* Clears all items in cart.
|
||||
*/
|
||||
function clearItems();
|
||||
|
||||
/**
|
||||
* Sets collection of items
|
||||
*
|
||||
* @param mixed $items
|
||||
*/
|
||||
function setItems($items);
|
||||
|
||||
/**
|
||||
* Returns collection of items in cart.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getItems();
|
||||
|
||||
/**
|
||||
* Adds item to cart.
|
||||
*
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function addItem(ItemInterface $item);
|
||||
|
||||
/**
|
||||
* Removes item from cart.
|
||||
*
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function removeItem(ItemInterface $item);
|
||||
|
||||
/**
|
||||
* Checks whether given item is inside cart or not.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function hasItem(ItemInterface $item);
|
||||
|
||||
/**
|
||||
* Gets expiration time.
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
function getExpiresAt();
|
||||
function isExpired();
|
||||
|
||||
/**
|
||||
* Sets expiration time.
|
||||
*
|
||||
* @param \DateTime $expiresAt
|
||||
*/
|
||||
function setExpiresAt(\DateTime $expiresAt);
|
||||
|
||||
/**
|
||||
* Bumps the expiration time.
|
||||
* Default is +3 hours.
|
||||
*/
|
||||
function incrementExpiresAt();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the cart is expired or not.
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function isExpired();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Base class for cart model manager.
|
||||
|
|
@ -20,21 +20,21 @@ abstract class CartManager implements CartManagerInterface
|
|||
{
|
||||
/**
|
||||
* FQCN of cart model.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param string $class FQCN of cart model
|
||||
*/
|
||||
public function __construct($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Interface for cart manager.
|
||||
|
|
@ -18,62 +18,66 @@ namespace Sylius\Bundle\CartBundle\Model;
|
|||
*/
|
||||
interface CartManagerInterface
|
||||
{
|
||||
/* }}} */
|
||||
/**
|
||||
* Creates a new cart instance.
|
||||
*
|
||||
*
|
||||
* @return CartInterface
|
||||
*/
|
||||
function createCart();
|
||||
|
||||
|
||||
/**
|
||||
* Persists cart object.
|
||||
*
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
function persistCart(CartInterface $cart);
|
||||
|
||||
|
||||
/**
|
||||
* Removes cart object.
|
||||
*
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
function removeCart(CartInterface $cart);
|
||||
|
||||
function flushCarts();
|
||||
|
||||
|
||||
/**
|
||||
* Removes all saved carts that are expired.
|
||||
*/
|
||||
function clearCarts();
|
||||
|
||||
/**
|
||||
* Finds cart by id.
|
||||
*
|
||||
*
|
||||
* @param $id
|
||||
*
|
||||
*
|
||||
* @return CartInterface|null
|
||||
*/
|
||||
function findCart($id);
|
||||
|
||||
|
||||
/**
|
||||
* Finds cart by given criteria.
|
||||
*
|
||||
*
|
||||
* @param array $criteria
|
||||
*/
|
||||
function findCartBy(array $criteria);
|
||||
|
||||
|
||||
/**
|
||||
* Finds all carts.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function findCarts();
|
||||
|
||||
|
||||
/**
|
||||
* Finds carts by criteria.
|
||||
*
|
||||
*
|
||||
* @param array $criteria
|
||||
*/
|
||||
function findCartsBy(array $criteria);
|
||||
|
||||
|
||||
/**
|
||||
* Returns FQCN of cart model.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getClass();
|
||||
|
|
|
|||
|
|
@ -9,55 +9,78 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Model for cart items.
|
||||
*
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
abstract class Item implements ItemInterface
|
||||
{
|
||||
/**
|
||||
* Id.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
|
||||
/**
|
||||
* Cart.
|
||||
*
|
||||
*
|
||||
* @var CartInterface
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
|
||||
/**
|
||||
* Quantity.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $quantity;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->quantity = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getQuantity()
|
||||
{
|
||||
return $this->quantity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setQuantity($quantity)
|
||||
{
|
||||
$this->quantity = $quantity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCart()
|
||||
{
|
||||
return $this->cart;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets cart.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCart(CartInterface $cart = null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,14 +13,43 @@ namespace Sylius\Bundle\CartBundle\Model;
|
|||
|
||||
/**
|
||||
* Interface for cart item model.
|
||||
*
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
interface ItemInterface
|
||||
{
|
||||
/**
|
||||
* Returns cart id.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getId();
|
||||
|
||||
/**
|
||||
* Returns associated cart.
|
||||
*
|
||||
* @return CartInterface
|
||||
*/
|
||||
function getCart();
|
||||
|
||||
/**
|
||||
* Sets cart.
|
||||
*
|
||||
* @param CartInterface
|
||||
*/
|
||||
function setCart(CartInterface $cart = null);
|
||||
|
||||
/**
|
||||
* Returns quantity.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
function getQuantity();
|
||||
|
||||
/**
|
||||
* Sets quantity.
|
||||
*
|
||||
* @param $quantity
|
||||
*/
|
||||
function setQuantity($quantity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Model;
|
||||
namespace Sylius\Bundle\CartsBundle\Model;
|
||||
|
||||
/**
|
||||
* Base class for cart item model manager.
|
||||
|
|
@ -20,21 +20,21 @@ abstract class ItemManager implements ItemManagerInterface
|
|||
{
|
||||
/**
|
||||
* FQCN for cart item model.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param string $class The FQCN for cart item model
|
||||
*/
|
||||
public function __construct($class)
|
||||
{
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,54 +20,54 @@ interface ItemManagerInterface
|
|||
{
|
||||
/**
|
||||
* Returns FQCN of cart item model.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getClass();
|
||||
|
||||
|
||||
/**
|
||||
* Creates item model object.
|
||||
*/
|
||||
function createItem();
|
||||
|
||||
|
||||
/**
|
||||
* Persists item.
|
||||
*
|
||||
*
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function persistItem(ItemInterface $item);
|
||||
|
||||
|
||||
/**
|
||||
* Removes item.
|
||||
*
|
||||
*
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function removeItem(ItemInterface $item);
|
||||
|
||||
|
||||
/**
|
||||
* Finds item by id.
|
||||
*
|
||||
*
|
||||
* @param integer $id
|
||||
*/
|
||||
function findItem($id);
|
||||
|
||||
|
||||
/**
|
||||
* Finds item by criteria.
|
||||
*
|
||||
*
|
||||
* @param array $criteria
|
||||
*/
|
||||
function findItemBy(array $criteria);
|
||||
|
||||
|
||||
/**
|
||||
* Finds all items.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function findItems();
|
||||
|
||||
|
||||
/**
|
||||
* Finds items by criteria.
|
||||
*
|
||||
*
|
||||
* @param array $criteria
|
||||
*/
|
||||
function findItemsBy(array $criteria);
|
||||
|
|
|
|||
41
src/Sylius/Bundle/CartBundle/Operator/CartOperator.php
Normal file
41
src/Sylius/Bundle/CartBundle/Operator/CartOperator.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Operator;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\CartManagerInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\ItemInterface;
|
||||
|
||||
/**
|
||||
* Base class for cart operator.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
abstract class CartOperator implements CartOperatorInterface
|
||||
{
|
||||
/**
|
||||
* Cart manager.
|
||||
*
|
||||
* @var CartManagerInterface
|
||||
*/
|
||||
protected $cartManager;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CartManagerInterface $cartManager;
|
||||
*/
|
||||
public function __construct(CartManagerInterface $cartManager)
|
||||
{
|
||||
$this->cartManager = $cartManager;
|
||||
}
|
||||
}
|
||||
|
|
@ -9,39 +9,61 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Operator;
|
||||
namespace Sylius\Bundle\CartsBundle\Operator;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartBundle\Model\ItemInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\ItemInterface;
|
||||
|
||||
/**
|
||||
* Interface for cart operator.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
interface OperatorInterface
|
||||
interface CartOperatorInterface
|
||||
{
|
||||
/**
|
||||
* Builds proper item and adds it to cart.
|
||||
* If item exists just increases the quantity.
|
||||
*
|
||||
/**
|
||||
* Adds item to cart.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function addItem(CartInterface $cart, ItemInterface $item);
|
||||
|
||||
|
||||
/**
|
||||
* Removes item from cart.
|
||||
*
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
* @param ItemInterface $item
|
||||
*/
|
||||
function removeItem(CartInterface $cart, ItemInterface $item);
|
||||
|
||||
|
||||
/**
|
||||
* Refreshes cart data.
|
||||
*
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
function refreshCart(CartInterface $cart);
|
||||
function refresh(CartInterface $cart);
|
||||
|
||||
/**
|
||||
* Validates cart.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*
|
||||
* @return Boolean
|
||||
*/
|
||||
function validate(CartInterface $cart);
|
||||
|
||||
/**
|
||||
* Saves cart at current state.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
function save(CartInterface $cart);
|
||||
|
||||
/**
|
||||
* Clears current cart.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
function clear(CartInterface $cart);
|
||||
}
|
||||
99
src/Sylius/Bundle/CartBundle/Provider/CartProvider.php
Normal file
99
src/Sylius/Bundle/CartBundle/Provider/CartProvider.php
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Provider;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\Model\CartInterface;
|
||||
use Sylius\Bundle\CartsBundle\Model\CartManagerInterface;
|
||||
use Sylius\Bundle\CartsBundle\Storage\CartStorageInterface;
|
||||
|
||||
/**
|
||||
* Container for cart.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class CartProvider implements CartProviderInterface
|
||||
{
|
||||
/**
|
||||
* Cart identifier storage.
|
||||
*
|
||||
* @var CartStorageInterface
|
||||
*/
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Cart manager.
|
||||
*
|
||||
* @var CartManagerInterface
|
||||
*/
|
||||
protected $cartManager;
|
||||
|
||||
/**
|
||||
* Cart.
|
||||
*
|
||||
* @var CartInterface
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CartStorageInterface $storage
|
||||
* @param CartManagerInterface $cartManager
|
||||
*/
|
||||
public function __construct(CartStorageInterface $storage, CartManagerInterface $cartManager)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->cartManager = $cartManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current cart or creates a new one.
|
||||
*
|
||||
* @return CartInterface
|
||||
*/
|
||||
public function getCart()
|
||||
{
|
||||
if (null == $this->cart) {
|
||||
$cartManager = $this->container->get('sylius_cart.manager.cart');
|
||||
$session = $this->container->get('request')->getSession();
|
||||
|
||||
$cartId = $this->storage->getCurrentCartId();
|
||||
|
||||
if ($cartId) {
|
||||
$cart = $cartManager->findCart($cartId);
|
||||
|
||||
if ($cart) {
|
||||
$this->cart = $cart;
|
||||
return $cart;
|
||||
}
|
||||
}
|
||||
|
||||
$cart = $cartManager->createCart();
|
||||
$cartManager->persistCart($cart);
|
||||
$this->storage->setCurrentCartId($cart->getId());
|
||||
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
return $this->cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets current cart.
|
||||
*
|
||||
* @param CartInterface $cart
|
||||
*/
|
||||
public function setCart(CartInterface $cart)
|
||||
{
|
||||
$this->cart = $cart;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Provider;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
|
||||
interface CartProviderInterface
|
||||
{
|
||||
function getCart();
|
||||
function setCart(CartInterface $cart);
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Provider;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||
use Sylius\Bundle\CartBundle\Model\CartInterface;
|
||||
|
||||
/**
|
||||
* Container for cart.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class Provider extends ContainerAware
|
||||
{
|
||||
protected $cart;
|
||||
|
||||
public function getCart()
|
||||
{
|
||||
if (null == $this->cart) {
|
||||
$cartManager = $this->container->get('sylius_cart.manager.cart');
|
||||
$session = $this->container->get('request')->getSession();
|
||||
|
||||
$cartId = $session->get('sylius_cart.id', false);
|
||||
|
||||
if ($cartId) {
|
||||
$cart = $cartManager->findCart($cartId);
|
||||
|
||||
if ($cart) {
|
||||
$this->cart = $cart;
|
||||
return $cart;
|
||||
}
|
||||
}
|
||||
|
||||
$cart = $cartManager->createCart();
|
||||
$cartManager->persistCart($cart);
|
||||
$session->set('sylius_cart.id', $cart->getId());
|
||||
|
||||
$this->cart = $cart;
|
||||
}
|
||||
|
||||
return $this->cart;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +1,82 @@
|
|||
About SyliusCartBundle...
|
||||
=================================
|
||||
SyliusCartsBundle
|
||||
=================
|
||||
|
||||
Simple cart engine.
|
||||
Flexible cart engine for Symfony2. Allows you to add any object to cart, customize the structure of it and much more.
|
||||
Considered as base for building solution that fits your exact needs.
|
||||
|
||||
Sylius.
|
||||
-------
|
||||
[](http://travis-ci.org/Sylius/SyliusCategorizerBundle)
|
||||
|
||||
**Sylius** is simple but **end-user and developer friendly** webshop engine built on top of Symfony2. Visit [sylius.org](http://sylius.org).
|
||||
Sylius
|
||||
------
|
||||
|
||||
Examples.
|
||||
---------
|
||||
**Sylius** is simple but **end-user and developer friendly** webshop engine built on top of Symfony2.
|
||||
|
||||
If you want to see this and other bundles in action, try out the [Sylius sandbox application](http://github.com/Sylius/Sylius-Sandbox).
|
||||
Please visit [Sylius.org](http://sylius.org) for more details.
|
||||
|
||||
Testing and build status
|
||||
------------------------
|
||||
|
||||
This bundle uses [travis-ci.org](http://travis-ci.org/Sylius/SyliusCartsBundle) for CI.
|
||||
[](http://travis-ci.org/Sylius/SyliusCategorizerBundle)
|
||||
|
||||
Before running tests, load the dependencies using [Composer](http://packagist.org).
|
||||
|
||||
``` bash
|
||||
$ wget http://getcomposer.org/composer.phar
|
||||
$ php composer.phar install --install-suggests
|
||||
```
|
||||
|
||||
Now you can run the tests by simply using this command.
|
||||
|
||||
``` bash
|
||||
$ phpunit
|
||||
```
|
||||
|
||||
Code examples
|
||||
-------------
|
||||
|
||||
If you want to see working implementation, try out the [Sylius sandbox application](http://github.com/Sylius/Sylius-Sandbox).
|
||||
It's open sourced github project.
|
||||
|
||||
Documentation.
|
||||
--------------
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Docs are available [here](https://github.com/Sylius/SyliusCartBundle/blob/master/Resources/doc/index.md).
|
||||
Documentation is available on [Sylius.org](http://sylius.org/docs/bundles/SyliusCartsBundle.html).
|
||||
|
||||
Mailing lists.
|
||||
--------------
|
||||
Contributing
|
||||
------------
|
||||
|
||||
All informations about contributing to Sylius can be found on [this page](http://sylius.org/docs/contributing/index.html).
|
||||
|
||||
Mailing lists
|
||||
-------------
|
||||
|
||||
### Users
|
||||
|
||||
If you are using this bundle and have any questions, feel free to ask on users mailing list.
|
||||
[Mail](mailto:sylius@googlegroups.com) or [view it](http://groups.google.com/group/sylius).
|
||||
|
||||
### Developers
|
||||
|
||||
If you want to contribute, and develop this bundle, use the developers mailing list.
|
||||
[Mail](mailto:sylius-dev@googlegroups.com) or [view it](http://groups.google.com/group/sylius-dev).
|
||||
|
||||
Sylius twitter account.
|
||||
-----------------------
|
||||
Sylius twitter account
|
||||
----------------------
|
||||
|
||||
If you want to keep up with updates, [follow the official Sylius account on twitter](http://twitter.com/_Sylius)
|
||||
If you want to keep up with updates, [follow the official Sylius account on twitter](http://twitter.com/_Sylius)
|
||||
or [follow me](http://twitter.com/pjedrzejewski).
|
||||
|
||||
Bug tracking.
|
||||
-------------
|
||||
Bug tracking
|
||||
------------
|
||||
|
||||
This bundle uses [GitHub issues](https://github.com/Sylius/SyliusCartBundle/issues).
|
||||
This bundle uses [GitHub issues](https://github.com/Sylius/SyliusCartsBundle/issues).
|
||||
If you have found bug, please create an issue.
|
||||
|
||||
Versioning.
|
||||
-----------
|
||||
Versioning
|
||||
----------
|
||||
|
||||
Releases will be numbered with the format `<major>.<minor>.<patch>`.
|
||||
Releases will be numbered with the format `major.minor.patch`.
|
||||
|
||||
And constructed with the following guidelines.
|
||||
|
||||
|
|
@ -51,16 +84,16 @@ And constructed with the following guidelines.
|
|||
* New additions without breaking backwards compatibility bumps the minor.
|
||||
* Bug fixes and misc changes bump the patch.
|
||||
|
||||
For more information on SemVer, please visit [semver.org website](http://semver.org/).
|
||||
For more information on SemVer, please visit [semver.org website](http://semver.org/).
|
||||
This versioning method is same for all **Sylius** bundles and applications.
|
||||
|
||||
License.
|
||||
--------
|
||||
License
|
||||
-------
|
||||
|
||||
License can be found [here](https://github.com/Sylius/SyliusCartBundle/blob/master/Resources/meta/LICENSE).
|
||||
License can be found [here](https://github.com/Sylius/SyliusCartsBundle/blob/master/Resources/meta/LICENSE).
|
||||
|
||||
Authors.
|
||||
--------
|
||||
Authors
|
||||
-------
|
||||
|
||||
The bundle was originally created by [Paweł Jędrzejewski](http://diweb.pl).
|
||||
See the list of [contributors](https://github.com/Sylius/SyliusCartBundle/contributors).
|
||||
The bundle was originally created by [Paweł Jędrzejewski](http://pjedrzejewski.com).
|
||||
See the list of [contributors](https://github.com/Sylius/SyliusCartsBundle/contributors).
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Resolver;
|
||||
|
||||
c
|
||||
|
|
@ -1,15 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd"
|
||||
>
|
||||
|
||||
<services>
|
||||
<service id="sylius_cart.controller.frontend.cart" class="%sylius_cart.controller.frontend.cart.class%">
|
||||
<service id="sylius_carts.controller.frontend.cart" class="%sylius_carts.controller.frontend.cart.class%">
|
||||
<call method="setContainer">
|
||||
<argument type="service" id="service_container" />
|
||||
</call>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
|
||||
</container>
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd"
|
||||
>
|
||||
|
||||
<services>
|
||||
<service id="sylius_cart.form.type.cart" class="%sylius_cart.form.type.cart.class%">
|
||||
<argument>%sylius_cart.model.cart.class%</argument>
|
||||
<tag name="form.type" alias="sylius_cart" />
|
||||
<service id="sylius_carts.form.type.cart" class="%sylius_carts.form.type.cart.class%">
|
||||
<argument>%sylius_carts.model.cart.class%</argument>
|
||||
<tag name="form.type" alias="sylius_carts_cart" />
|
||||
</service>
|
||||
<service id="sylius_cart.form.type.item" class="%sylius_cart.form.type.item.class%">
|
||||
<argument>%sylius_cart.model.item.class%</argument>
|
||||
<tag name="form.type" alias="sylius_cart_item" />
|
||||
<service id="sylius_carts.form.type.item" class="%sylius_carts.form.type.item.class%">
|
||||
<argument>%sylius_carts.model.item.class%</argument>
|
||||
<tag name="form.type" alias="sylius_carts_item" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd"
|
||||
>
|
||||
|
||||
<services>
|
||||
<service id="sylius_cart.provider" class="%sylius_cart.provider.class%">
|
||||
<call method="setContainer">
|
||||
<argument type="service" id="service_container" />
|
||||
</call>
|
||||
<service id="sylius_carts.provider" class="%sylius_carts.provider.class%">
|
||||
<argument type="service" id="sylius_carts.storage" />
|
||||
<argument type="service" id="sylius_carts.manager.cart" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services
|
||||
http://symfony.com/schema/dic/services/services-1.0.xsd"
|
||||
>
|
||||
|
||||
<parameters>
|
||||
<parameter key="sylius_carts.storage.session.class">Sylius\Bundle\CartsBundle\Storage\SessionCartStorage</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="sylius_carts.storage.session" class="%sylius_carts.storage.session.class%">
|
||||
<argument type="service" id="session" />
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</container>
|
||||
|
|
@ -3,7 +3,8 @@
|
|||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
|
||||
>
|
||||
|
||||
<mapped-superclass name="Sylius\Bundle\CartBundle\Entity\Cart" table="sylius_cart">
|
||||
<field name="locked" column="locked" type="boolean" />
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
|
||||
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
|
||||
>
|
||||
|
||||
<mapped-superclass name="Sylius\Bundle\CartBundle\Entity\Item" table="sylius_item">
|
||||
<mapped-superclass name="Sylius\Bundle\CartBundle\Entity\Item" table="sylius_cart_item">
|
||||
<field name="quantity" column="quantity" type="integer" />
|
||||
</mapped-superclass>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,24 +1,20 @@
|
|||
sylius_cart_show:
|
||||
pattern: /cart
|
||||
defaults: { _controller: sylius_cart.controller.frontend.cart:showAction }
|
||||
|
||||
sylius_cart_update:
|
||||
pattern: /cart/update
|
||||
defaults: { _controller: sylius_cart.controller.frontend.cart:updateAction }
|
||||
requirements:
|
||||
_method: POST
|
||||
|
||||
defaults: { _controller: sylius_carts.controller.frontend.cart:showAction }
|
||||
|
||||
sylius_cart_save:
|
||||
pattern: /cart/save
|
||||
defaults: { _controller: sylius_carts.controller.frontend.cart:saveAction }
|
||||
|
||||
sylius_cart_clear:
|
||||
pattern: /cart/clear
|
||||
defaults: { _controller: sylius_cart.controller.frontend.cart:clearAction }
|
||||
|
||||
defaults: { _controller: sylius_carts.controller.frontend.cart:clearAction }
|
||||
|
||||
sylius_cart_item_add:
|
||||
pattern: /cart/item/add
|
||||
defaults: { _controller: sylius_cart.controller.frontend.cart:addItemAction }
|
||||
requirements:
|
||||
_method: POST
|
||||
|
||||
defaults: { _controller: sylius_carts.controller.frontend.cart:addItemAction }
|
||||
|
||||
sylius_cart_item_remove:
|
||||
pattern: /cart/item/{id}/remove
|
||||
defaults: { _controller: sylius_cart.controller.frontend.cart:removeItemAction }
|
||||
|
||||
defaults: { _controller: sylius_carts.controller.frontend.cart:removeItemAction }
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2011 Paweł Jędrzejewski
|
||||
Copyright (c) 2011-2012 Paweł Jędrzejewski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
# This file is part of the Sylius package.
|
||||
# (c) Paweł Jędrzejewski
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Storage;
|
||||
|
||||
/**
|
||||
* Interface for service that stores current cart id.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
interface CartStorageInterface
|
||||
{
|
||||
/**
|
||||
* Returns current cart id, used then to retrieve the cart.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function getCurrentCartIdentifier();
|
||||
|
||||
/**
|
||||
* Sets current cart id and persists it.
|
||||
*
|
||||
* @param mixed $identifier
|
||||
*/
|
||||
function setCurrentCartIdentifier($identifier);
|
||||
}
|
||||
56
src/Sylius/Bundle/CartBundle/Storage/SessionCartStorage.php
Normal file
56
src/Sylius/Bundle/CartBundle/Storage/SessionCartStorage.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Storage;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* Stores current cart id inside the user session.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class SessionCartStorage implements CartStorageInterface
|
||||
{
|
||||
/**
|
||||
* Session.
|
||||
*
|
||||
* @var SessionInterface
|
||||
*/
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SessionInterface $session
|
||||
*/
|
||||
public function __construct(SessionInterface $session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCurrentCartId()
|
||||
{
|
||||
return $this->session->get('_sylius.cart-id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCurrentCartId($identifier)
|
||||
{
|
||||
$this->session->set('_sylius.cart-id', $identifier);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,15 +9,16 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle;
|
||||
namespace Sylius\Bundle\CartsBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
/**
|
||||
* Bundle of cart system.
|
||||
*
|
||||
* Easy and flexible cart system bundle.
|
||||
* Clean and consistent architecture.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class SyliusCartBundle extends Bundle
|
||||
class SyliusCartsBundle extends Bundle
|
||||
{
|
||||
}
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Tests\DependencyInjection;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\DependencyInjection\SyliusCartsExtension;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
|
||||
/**
|
||||
* DIC extension test.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class SyliusCartsExtensionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessDriverSet()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
unset($config['driver']);
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessDriverIsValid()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
$config['driver'] = 'foo';
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessEngineIsValid()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
$config['engine'] = 'foo';
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessOperatorSet()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
unset($config['operator']);
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessResolverSet()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
unset($config['resolver']);
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessCartModelClassSet()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
unset($config['classes']['model']['cart']);
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
|
||||
*/
|
||||
public function testLoadThrowsExceptionUnlessItemModelClassSet()
|
||||
{
|
||||
$loader = new SyliusCartsExtension();
|
||||
$config = $this->getEmptyConfig();
|
||||
unset($config['classes']['model']['item']);
|
||||
$loader->load(array($config), new ContainerBuilder());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get testing config.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getEmptyConfig()
|
||||
{
|
||||
$yaml = <<<EOF
|
||||
driver: doctrine/orm
|
||||
operator: acme_carts.operator
|
||||
resolver: acme_carts.resolver
|
||||
classes:
|
||||
model:
|
||||
cart: Acme\\Bundle\\CartsBundle\\Entity\\Cart
|
||||
item: Acme\\Bundle\\CartsBundle\\Entity\\Item
|
||||
EOF;
|
||||
$parser = new Parser();
|
||||
|
||||
return $parser->parse($yaml);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Tests\Entity;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\Entity\CartManager;
|
||||
|
||||
/**
|
||||
* Cart manager test for doctrine/orm driver.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class CartManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testPersistCart()
|
||||
{
|
||||
$cart = $this->getMockCart();
|
||||
|
||||
$entityManager = $this->getMockEntityManager();
|
||||
$entityManager->expects($this->once())
|
||||
->method('persist')
|
||||
->with($this->equalTo($cart))
|
||||
;
|
||||
$entityManager->expects($this->once())
|
||||
->method('flush')
|
||||
;
|
||||
|
||||
$cartManager = new CartManager($entityManager, 'Foo\Bar');
|
||||
$cartManager->persistCart($cart);
|
||||
}
|
||||
|
||||
public function testRemoveCart()
|
||||
{
|
||||
$cart = $this->getMockCart();
|
||||
|
||||
$entityManager = $this->getMockEntityManager();
|
||||
$entityManager->expects($this->once())
|
||||
->method('remove')
|
||||
->with($this->equalTo($cart))
|
||||
;
|
||||
$entityManager->expects($this->once())
|
||||
->method('flush')
|
||||
;
|
||||
|
||||
$cartManager = new CartManager($entityManager, 'Foo\Bar');
|
||||
$cartManager->removeCart($cart);
|
||||
}
|
||||
|
||||
private function getMockCart()
|
||||
{
|
||||
return $this->getMock('Sylius\Bundle\CartsBundle\Model\CartInterface');
|
||||
}
|
||||
|
||||
private function getMockEntityManager()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Tests\Entity;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\Entity\ItemManager;
|
||||
|
||||
/**
|
||||
* Item manager test for doctrine/orm driver.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class ItemManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testPersistItem()
|
||||
{
|
||||
$item = $this->getMockItem();
|
||||
|
||||
$entityManager = $this->getMockEntityManager();
|
||||
$entityManager->expects($this->once())
|
||||
->method('persist')
|
||||
->with($this->equalTo($item))
|
||||
;
|
||||
$entityManager->expects($this->once())
|
||||
->method('flush')
|
||||
;
|
||||
|
||||
$itemManager = new ItemManager($entityManager, 'Foo\Bar');
|
||||
$itemManager->persistItem($item);
|
||||
}
|
||||
|
||||
public function testRemoveItem()
|
||||
{
|
||||
$item = $this->getMockItem();
|
||||
|
||||
$entityManager = $this->getMockEntityManager();
|
||||
$entityManager->expects($this->once())
|
||||
->method('remove')
|
||||
->with($this->equalTo($item))
|
||||
;
|
||||
$entityManager->expects($this->once())
|
||||
->method('flush')
|
||||
;
|
||||
|
||||
$itemManager = new ItemManager($entityManager, 'Foo\Bar');
|
||||
$itemManager->removeItem($item);
|
||||
}
|
||||
|
||||
private function getMockItem()
|
||||
{
|
||||
return $this->getMock('Sylius\Bundle\CartsBundle\Model\ItemInterface');
|
||||
}
|
||||
|
||||
private function getMockEntityManager()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartsBundle\Tests\EventDispatcher\Event;
|
||||
|
||||
use Sylius\Bundle\CartsBundle\EventDispatcher\Event\FilterCartEvent;
|
||||
|
||||
/**
|
||||
* Cart filtering event test.
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class FilterCartEventTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructor()
|
||||
{
|
||||
$category = $this->getMock('Sylius\Bundle\CartsBundle\Model\CartInterface');
|
||||
|
||||
$event = new FilterCartEvent($category);
|
||||
|
||||
$this->assertEquals($category, $event->getCart());
|
||||
}
|
||||
}
|
||||
40
src/Sylius/Bundle/CartBundle/Tests/autoload.php.dist
Normal file
40
src/Sylius/Bundle/CartBundle/Tests/autoload.php.dist
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (!file_exists($file = __DIR__.'/../vendor/.composer/autoload.php')) {
|
||||
|
||||
$vendorDir = __DIR__.'/../vendor';
|
||||
require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
|
||||
$loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony' => array($vendorDir.'/symfony/src', $vendorDir.'/bundles'),
|
||||
'Doctrine\\Common' => $vendorDir.'/doctrine-common/lib',
|
||||
'Doctrine\\DBAL' => $vendorDir.'/doctrine-dbal/lib',
|
||||
'Doctrine' => $vendorDir.'/doctrine/lib',
|
||||
));
|
||||
|
||||
$loader->register();
|
||||
|
||||
} else {
|
||||
require_once $file;
|
||||
}
|
||||
|
||||
spl_autoload_register(function($class) {
|
||||
if (0 === strpos($class, 'Sylius\\Bundle\\CartsBundle\\')) {
|
||||
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 3)).'.php';
|
||||
if (!stream_resolve_include_path($path)) {
|
||||
return false;
|
||||
}
|
||||
require_once $path;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
16
src/Sylius/Bundle/CartBundle/Tests/bootstrap.php
Normal file
16
src/Sylius/Bundle/CartBundle/Tests/bootstrap.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
if (file_exists($file = __DIR__.'/autoload.php')) {
|
||||
require_once $file;
|
||||
} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) {
|
||||
require_once $file;
|
||||
}
|
||||
|
|
@ -9,51 +9,61 @@
|
|||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Bundle\CartBundle\Twig;
|
||||
namespace Sylius\Bundle\CartsBundle\Twig;
|
||||
|
||||
use Sylius\Bundle\CartBundle\Provider\Provider;
|
||||
|
||||
use Twig_Function_Method;
|
||||
use Sylius\Bundle\CartsBundle\Provider\CartProviderInterface;
|
||||
use Twig_Extension;
|
||||
use Twig_Function_Method;
|
||||
|
||||
/**
|
||||
* Sylius cart engine twig extension.
|
||||
*
|
||||
*
|
||||
* @author Paweł Jędrzejewski <pjedrzejewski@diweb.pl>
|
||||
*/
|
||||
class SyliusCartExtension extends Twig_Extension
|
||||
class SyliusCartsExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Cart provider.
|
||||
*
|
||||
* @var CartProviderInterface
|
||||
*/
|
||||
private $cartProvider;
|
||||
|
||||
public function __construct(Provider $cartProvider)
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param CartProviderInterface $cartProvider
|
||||
*/
|
||||
public function __construct(CartProviderInterface $cartProvider)
|
||||
{
|
||||
$this->cartProvider = $cartProvider;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of global functions to add to the existing list.
|
||||
*
|
||||
* @return array An array of global functions
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
'sylius_cart_get' => new Twig_Function_Method($this, 'getCart', array('is_safe' => array('html'))),
|
||||
'sylius_carts_get' => new Twig_Function_Method($this, 'getCurrentCart'),
|
||||
);
|
||||
}
|
||||
|
||||
public function getCart()
|
||||
|
||||
/**
|
||||
* Returns current cart.
|
||||
*
|
||||
* @return CartInterface
|
||||
*/
|
||||
public function getCurrentCart()
|
||||
{
|
||||
return $this->cartProvider->getCart();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'sylius_cart';
|
||||
return 'sylius_carts';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,31 @@
|
|||
{
|
||||
"name": "sylius/cart-bundle",
|
||||
"name": "sylius/carts-bundle",
|
||||
"type": "symfony-bundle",
|
||||
"description": "Cart feature for your Symfony2 applications.",
|
||||
"keywords": ["shop", "ecommerce", "cart"],
|
||||
"description": "Carts feature for your next Symfony2 application. Clean architecture and simple usage.",
|
||||
"keywords": ["shop", "ecommerce", "cart", "carts"],
|
||||
"homepage": "http://sylius.org",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Paweł Jędrzejewski",
|
||||
"email": "pjedrzejewski@diweb.pl"
|
||||
"email": "pjedrzejewski@diweb.pl",
|
||||
"homepage": "http://pjedrzejewski.com"
|
||||
},
|
||||
{
|
||||
"name": "Community contributions",
|
||||
"homepage": "https://github.com/Sylius/SyliusCartBundle/contributors"
|
||||
"homepage": "https://github.com/Sylius/SyliusCartsBundle/contributors"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.3.2",
|
||||
"symfony/symfony": "2.*"
|
||||
|
||||
"symfony/symfony": "2.1.*"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/doctrine-bundle": "*"
|
||||
"doctrine/doctrine-bundle": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": { "Sylius\\Bundle\\CartBundle": "" }
|
||||
"psr-0": { "Sylius\\Bundle\\CartsBundle": "" }
|
||||
},
|
||||
"target-dir": "Sylius/Bundle/CartBundle"
|
||||
"target-dir": "Sylius/Bundle/CartsBundle"
|
||||
}
|
||||
|
|
|
|||
20
src/Sylius/Bundle/CartBundle/phpunit.xml.dist
Normal file
20
src/Sylius/Bundle/CartBundle/phpunit.xml.dist
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<phpunit bootstrap="./Tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="SyliusCartsBundle test suite">
|
||||
<directory suffix="Test.php">./Tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./</directory>
|
||||
<exclude>
|
||||
<directory>./Resources</directory>
|
||||
<directory>./Tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
Loading…
Add table
Reference in a new issue