diff --git a/src/Sylius/Bundle/CartBundle/.gitignore b/src/Sylius/Bundle/CartBundle/.gitignore index 72de8f15d5..46aed33710 100644 --- a/src/Sylius/Bundle/CartBundle/.gitignore +++ b/src/Sylius/Bundle/CartBundle/.gitignore @@ -1,7 +1,5 @@ -phpunit.xml -Tests/autoload.php - vendor/ +bin/ composer.phar composer.lock diff --git a/src/Sylius/Bundle/CartBundle/.travis.yml b/src/Sylius/Bundle/CartBundle/.travis.yml index f545bfee90..7b3362010d 100644 --- a/src/Sylius/Bundle/CartBundle/.travis.yml +++ b/src/Sylius/Bundle/CartBundle/.travis.yml @@ -4,10 +4,9 @@ php: - 5.3 - 5.4 -before_script: - - wget http://getcomposer.org/composer.phar - - php composer.phar install --dev +before_script: composer install --dev + +script: php bin/phpspec run notifications: - email: - - travis-ci@sylius.org + email: travis-ci@sylius.org diff --git a/src/Sylius/Bundle/CartBundle/CHANGELOG.md b/src/Sylius/Bundle/CartBundle/CHANGELOG.md index 50464aec09..6e3532320d 100644 --- a/src/Sylius/Bundle/CartBundle/CHANGELOG.md +++ b/src/Sylius/Bundle/CartBundle/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +### 01-11-2012 + +* Bundle now uses [SyliusResourceBundle](http://github.com/Sylius/SyliusResourceBundle) for model persistence. +* New controller. +* Renamed **Item** to **CartItem**. +* Renamed **ItemType** to **CartItemType**. +* Introduce specs with [phpspec2](http://phpspec.net). + ### 28-05-2012 * Renamed **CartFormType** to **CartType** to be consistent. diff --git a/src/Sylius/Bundle/CartBundle/Command/FlushCartsCommand.php b/src/Sylius/Bundle/CartBundle/Command/FlushCartsCommand.php deleted file mode 100644 index 98c1c919a2..0000000000 --- a/src/Sylius/Bundle/CartBundle/Command/FlushCartsCommand.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ -class FlushCartsCommand extends ContainerAwareCommand -{ - /** - * {@inheritdoc} - */ - protected function configure() - { - $this - ->setName('sylius:cart:flush') - ->setDescription('Deletes expired carts.') - ->setHelp( -<<sylius:cart:flush command deletes expired carts: - - php sylius/console sylius:cart:flush -EOT - ) - ; - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $this->getContainer()->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_FLUSH); - $this->getContainer()->get('sylius_cart.manager.cart')->flushCarts(); - - $output->writeln('[Sylius:Cart] Deleted expired carts.'); - } -} diff --git a/src/Sylius/Bundle/CartBundle/Controller/CartController.php b/src/Sylius/Bundle/CartBundle/Controller/CartController.php new file mode 100644 index 0000000000..b21e2e8ca5 --- /dev/null +++ b/src/Sylius/Bundle/CartBundle/Controller/CartController.php @@ -0,0 +1,251 @@ + + */ +class CartController extends ResourceController +{ + /** + * Displays cart. + * + * @param Request + * + * @return Response + */ + public function showAction(Request $request) + { + $cart = $this->getCurrentCart(); + $form = $this->createForm($this->getResourceFormType(), $cart); + + return $this->renderResponse('show.html', array( + 'cart' => $cart, + 'form' => $form->createView() + )); + } + + /** + * Adds item to cart. + * + * @param Request $request + * + * @return Response + */ + public function addItemAction(Request $request) + { + $cart = $this->getCurrentCart(); + $item = $this->getResolver()->resolveItemToAdd($request); + + if (!$item) { + $this->setFlash('error', 'sylius_cart.flashes.add.error'); + + return $this->redirectToCart(); + } + + $cartOperator = $this->getOperator(); + + $cartOperator + ->addItem($cart, $item) + ->refresh($cart) + ; + + $errors = $this->get('validator')->validate($cart); + + if (0 === count($errors)) { + $this->setFlash('success', 'sylius_cart.flashes.add.success'); + $cartOperator->save($cart); + } + + return $this->redirectToCart(); + } + + /** + * Removes item from cart. + * + * @param Request $request + * + * @return Response + */ + public function removeItemAction(Request $request) + { + $cart = $this->getCurrentCart(); + $item = $this->getResolver()->resolveItemToRemove($request); + + if (!$item || false === $cart->hasItem($item)) { + $this->setFlash('error', 'sylius_cart.flashes.remove.error'); + + return $this->redirectToCart(); + } + + $this + ->getOperator() + ->removeItem($cart, $item) + ->refresh($cart) + ->save($cart) + ; + + $this->setFlash('success', 'sylius_cart.flashes.remove.success'); + + return $this->redirectToCart(); + } + + /** + * Saves cart. + * + * @param Request $request + * + * @return Response + */ + public function saveAction(Request $request) + { + $cart = $this->getCurrentCart(); + + $form = $this + ->createForm($this->getResourceFormType(), $cart) + ->bind($request) + ; + + if ($form->isValid()) { + $this + ->getOperator() + ->refresh($cart) + ->save($cart) + ; + + $this->setFlash('success', 'sylius_cart.flashes.saved'); + } + + return $this->renderResponse('show.html', array( + 'cart' => $cart, + 'form' => $form->createView() + )); + } + + /** + * Clears cart. + * + * @return Response + */ + public function clearAction() + { + $this + ->getOperator() + ->clear($this->getCurrentCart()) + ; + + $this->setFlash('success', 'sylius_cart.flashes.cleared'); + + return $this->redirectToCart(); + } + + /** + * Redirect to show cart action. + * + * @return RedirectResponse + */ + protected function redirectToCart() + { + return $this->redirect($this->generateUrl($this->getCartRoute())); + } + + /** + * Cart show action route. + * + * @return string + */ + protected function getCartRoute() + { + return 'sylius_cart_show'; + } + + /** + * Get current cart. + * + * @return CartInterface + */ + protected function getCurrentCart() + { + return $this + ->getProvider() + ->getCart() + ; + } + + /** + * Get cart provider. + * + * @return CartProviderInterface + */ + protected function getProvider() + { + return $this->get('sylius_cart.provider'); + } + + /** + * Get cart operator. + * + * @return CartOperatorInterface + */ + protected function getOperator() + { + return $this->get('sylius_cart.operator'); + } + + /** + * Get cart item resolver. + * + * @return CartResolverInterface + */ + protected function getResolver() + { + return $this->get('sylius_cart.resolver'); + } + + /** + * {@inheritdoc} + */ + protected function getResourceFormType() + { + return 'sylius_cart'; + } + + /** + * {@inheritdoc} + */ + protected function getBundlePrefix() + { + return 'sylius_cart'; + } + + /** + * {@inheritdoc} + */ + protected function getResourceName() + { + return 'cart'; + } + + /** + * {@inheritdoc} + */ + protected function getTemplateNamespace() + { + return 'SyliusCartBundle:Cart'; + } +} diff --git a/src/Sylius/Bundle/CartBundle/Controller/Frontend/CartController.php b/src/Sylius/Bundle/CartBundle/Controller/Frontend/CartController.php deleted file mode 100644 index 257438f962..0000000000 --- a/src/Sylius/Bundle/CartBundle/Controller/Frontend/CartController.php +++ /dev/null @@ -1,168 +0,0 @@ - - */ -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('sylius_cart'); - $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. - * - * @param Request $request - * - * @return Response - */ - public function addItemAction(Request $request) - { - $cart = $this->container->get('sylius_cart.provider')->getCart(); - $item = $this->container->get('sylius_cart.resolver')->resolveItemToAdd($request); - - if (!$item) { - $this->container->get('session')->setFlash('error', 'sylius_cart.flashes.add.error'); - - return new RedirectResponse($request->headers->get('referer')); - } - - $this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_ADD, new CartOperationEvent($cart, $item)); - - $cartOperator = $this->container->get('sylius_cart.operator'); - $cartOperator->addItem($cart, $item); - $cartOperator->refresh($cart); - - $errors = $this->container->get('validator')->validate($cart); - if (0 === count($errors)) { - $this->container->get('session')->setFlash('success', 'sylius_cart.flashes.add.success'); - $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(Request $request) - { - $cart = $this->container->get('sylius_cart.provider')->getCart(); - $item = $this->container->get('sylius_cart.resolver')->resolveItemToRemove($request); - - if (!$item || false === $cart->hasItem($item)) { - $this->container->get('session')->setFlash('error', 'sylius_cart.flashes.remove.error'); - - return new RedirectResponse($request->headers->get('referer')); - } - - $this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::ITEM_REMOVE, new CartOperationEvent($cart, $item)); - - $cartOperator = $this->container->get('sylius_cart.operator'); - $cartOperator->removeItem($cart, $item); - $cartOperator->refresh($cart); - $cartOperator->save($cart); - - $this->container->get('session')->setFlash('success', 'sylius_cart.flashes.remove.success'); - - return new RedirectResponse($this->container->get('router')->generate('sylius_cart_show')); - } - - /** - * Saves cart. - * - * @param Request $request - * - * @return Response - */ - public function saveAction(Request $request) - { - $cart = $this->container->get('sylius_cart.provider')->getCart(); - - $form = $this->container->get('form.factory')->create('sylius_cart'); - $form->setData($cart); - $form->bindRequest($request); - - if ($form->isValid()) { - $this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_SAVE, new FilterCartEvent($cart)); - - $cartOperator = $this->container->get('sylius_cart.operator'); - $cartOperator->refresh($cart); - $cartOperator->save($cart); - - $this->container->get('session')->setFlash('success', 'sylius_cart.flashes.saved'); - } - - return $this->container->get('templating')->renderResponse('SyliusCartBundle:Frontend/Cart:show.html.'.$this->getEngine(), array( - 'cart' => $cart, - 'form' => $form->createView() - )); - } - - /** - * Clears cart. - * - * @return Response - */ - public function clearAction() - { - $cart = $this->container->get('sylius_cart.provider')->getCart(); - - $this->container->get('event_dispatcher')->dispatch(SyliusCartEvents::CART_CLEAR, new FilterCartEvent($cart)); - $this->container->get('sylius_cart.operator')->clear($cart); - $this->container->get('session')->setFlash('success', 'sylius_cart.flashes.cleared'); - - 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'); - } -} diff --git a/src/Sylius/Bundle/CartBundle/DependencyInjection/Configuration.php b/src/Sylius/Bundle/CartBundle/DependencyInjection/Configuration.php index 7755b1632f..1eb53d30d3 100644 --- a/src/Sylius/Bundle/CartBundle/DependencyInjection/Configuration.php +++ b/src/Sylius/Bundle/CartBundle/DependencyInjection/Configuration.php @@ -70,22 +70,10 @@ class Configuration implements ConfigurationInterface ->scalarNode('item')->isRequired()->cannotBeEmpty()->end() ->end() ->end() - ->arrayNode('manager') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('cart')->defaultValue('Sylius\\Bundle\\CartBundle\\Entity\\CartManager')->end() - ->scalarNode('item')->defaultValue('Sylius\\Bundle\\CartBundle\\Entity\\ItemManager')->end() - ->end() - ->end() ->arrayNode('controller') ->addDefaultsIfNotSet() ->children() - ->arrayNode('frontend') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('cart')->defaultValue('Sylius\Bundle\\CartBundle\\Controller\\Frontend\\CartController')->end() - ->end() - ->end() + ->scalarNode('cart')->defaultValue('Sylius\\Bundle\\CartBundle\\Controller\\CartController')->end() ->end() ->end() ->arrayNode('form') @@ -95,17 +83,11 @@ class Configuration implements ConfigurationInterface ->addDefaultsIfNotSet() ->children() ->scalarNode('cart')->defaultValue('Sylius\Bundle\CartBundle\Form\Type\CartType')->end() - ->scalarNode('item')->defaultValue('Sylius\Bundle\CartBundle\Form\Type\ItemType')->end() + ->scalarNode('item')->defaultValue('Sylius\Bundle\CartBundle\Form\Type\CartItemType')->end() ->end() ->end() ->end() ->end() - ->arrayNode('listener') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('request')->defaultValue('Sylius\Bundle\\CartBundle\\EventDispatcher\\Listener\\RequestListener')->end() - ->end() - ->end() ->end() ->end() ->end(); diff --git a/src/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.php b/src/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.php index 1ad9166507..7aed2e84a2 100644 --- a/src/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.php +++ b/src/Sylius/Bundle/CartBundle/DependencyInjection/SyliusCartExtension.php @@ -35,14 +35,13 @@ class SyliusCartExtension extends Extension $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $config); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config/container')); if (!in_array($config['driver'], SyliusCartBundle::getSupportedDrivers())) { throw new \InvalidArgumentException(sprintf('Driver "%s" is unsupported for this extension.', $config['driver'])); } - if (!in_array($config['engine'], array('php', 'twig'))) { + if ('twig' !== $config['engine']) { throw new \InvalidArgumentException(sprintf('Engine "%s" is unsupported for this extension.', $config['engine'])); } @@ -58,62 +57,14 @@ class SyliusCartExtension extends Extension $container->setParameter('sylius_cart.provider.class', $config['classes']['provider']); - $configurations = array( - 'controllers', - 'forms', - 'provider', - 'storage' - ); + $loader->load('services.xml'); - foreach($configurations as $basename) { - $loader->load(sprintf('%s.xml', $basename)); - } + $container->setParameter('sylius_cart.model.cart.class', $config['classes']['model']['cart']); + $container->setParameter('sylius_cart.model.item.class', $config['classes']['model']['item']); - $this->remapParametersNamespaces($config['classes'], $container, array( - 'listener' => 'sylius_cart.listener.%s.class', - 'model' => 'sylius_cart.model.%s.class', - 'manager' => 'sylius_cart.manager.%s.class', - )); + $container->setParameter('sylius_cart.controller.cart.class', $config['classes']['controller']['cart']); - $this->remapParametersNamespaces($config['classes']['controller'], $container, array( - 'backend' => 'sylius_cart.controller.backend.%s.class', - 'frontend' => 'sylius_cart.controller.frontend.%s.class' - )); - - $this->remapParametersNamespaces($config['classes']['form'], $container, array( - 'type' => 'sylius_cart.form.type.%s.class', - )); - } - - protected function remapParameters(array $config, ContainerBuilder $container, array $map) - { - foreach ($map as $name => $paramName) { - if (isset($config[$name])) { - $container->setParameter($paramName, $config[$name]); - } - } - } - - protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces) - { - foreach ($namespaces as $ns => $map) { - if ($ns) { - if (!isset($config[$ns])) { - continue; - } - $namespaceConfig = $config[$ns]; - } else { - $namespaceConfig = $config; - } - if (is_array($map)) { - $this->remapParameters($namespaceConfig, $container, $map); - } else { - foreach ($namespaceConfig as $name => $value) { - if (null !== $value) { - $container->setParameter(sprintf($map, $name), $value); - } - } - } - } + $container->setParameter('sylius_cart.form.type.cart.class', $config['classes']['form']['type']['cart']); + $container->setParameter('sylius_cart.form.type.item.class', $config['classes']['form']['type']['item']); } } diff --git a/src/Sylius/Bundle/CartBundle/Entity/Cart.php b/src/Sylius/Bundle/CartBundle/Entity/Cart.php index b19d5f4190..7e93b952e4 100644 --- a/src/Sylius/Bundle/CartBundle/Entity/Cart.php +++ b/src/Sylius/Bundle/CartBundle/Entity/Cart.php @@ -11,9 +11,7 @@ namespace Sylius\Bundle\CartBundle\Entity; -use Doctrine\Common\Collections\ArrayCollection; use Sylius\Bundle\CartBundle\Model\Cart as BaseCart; -use Sylius\Bundle\CartBundle\Model\ItemInterface; /** * Cart entity. @@ -22,56 +20,4 @@ use Sylius\Bundle\CartBundle\Model\ItemInterface; */ class Cart extends BaseCart { - /** - * Constructor. - */ - public function __construct() - { - parent::__construct(); - - $this->items = new ArrayCollection(); - } - - /** - * {@inheritdoc} - */ - public function removeItem(ItemInterface $item) - { - if ($this->hasItem($item)) { - $this->items->removeElement($item); - $item->setCart(null); - } - } - - /** - * {@inheritdoc} - */ - public function hasItem(ItemInterface $item) - { - return $this->items->contains($item); - } - - /** - * {@inheritdoc} - */ - public function searchItem(ItemInterface $item) - { - return $this->items->indexOf($item); - } - - /** - * {@inheritdoc} - */ - public function isEmpty() - { - return $this->items->isEmpty(); - } - - /** - * {@inheritdoc} - */ - public function clearItems() - { - $this->items->clear(); - } } diff --git a/src/Sylius/Bundle/CartBundle/Entity/Item.php b/src/Sylius/Bundle/CartBundle/Entity/CartItem.php similarity index 76% rename from src/Sylius/Bundle/CartBundle/Entity/Item.php rename to src/Sylius/Bundle/CartBundle/Entity/CartItem.php index 594a3eb3a7..8f8cb2177a 100644 --- a/src/Sylius/Bundle/CartBundle/Entity/Item.php +++ b/src/Sylius/Bundle/CartBundle/Entity/CartItem.php @@ -11,13 +11,13 @@ namespace Sylius\Bundle\CartBundle\Entity; -use Sylius\Bundle\CartBundle\Model\Item as BaseItem; +use Sylius\Bundle\CartBundle\Model\CartItem as BaseCartItem; /** * Entity for cart items. - * + * * @author Paweł Jędrzejewski */ -abstract class Item extends BaseItem +abstract class CartItem extends BaseCartItem { } diff --git a/src/Sylius/Bundle/CartBundle/Entity/CartManager.php b/src/Sylius/Bundle/CartBundle/Entity/CartManager.php deleted file mode 100644 index ba1fb4a25b..0000000000 --- a/src/Sylius/Bundle/CartBundle/Entity/CartManager.php +++ /dev/null @@ -1,131 +0,0 @@ - - */ -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->repository = $this->entityManager->getRepository($class); - } - - /** - * {@inheritdoc} - */ - public function createCart() - { - $class = $this->getClass(); - - return new $class; - } - - /** - * {@inheritdoc} - */ - public function persistCart(CartInterface $cart) - { - $this->entityManager->persist($cart); - $this->entityManager->flush(); - } - - /** - * {@inheritdoc} - */ - public function removeCart(CartInterface $cart) - { - $this->entityManager->remove($cart); - $this->entityManager->flush(); - } - - /** - * {@inheritdoc} - */ - public function flushCarts() - { - $expiredCarts = $this->entityManager->createQueryBuilder() - ->select('c') - ->from($this->getClass(), 'c') - ->where('c.locked = false AND c.expiresAt < ?1') - ->setParameter(1, new \DateTime("now")) - ->getQuery() - ->getResult() - ; - - foreach ($expiredCarts as $cart) { - $this->removeCart($cart); - } - } - - /** - * {@inheritdoc} - */ - public function findCart($id) - { - return $this->repository->find($id); - } - - /** - * {@inheritdoc} - */ - public function findCartBy(array $criteria) - { - return $this->repository->findOneBy($criteria); - } - - /** - * {@inheritdoc} - */ - public function findCarts() - { - return $this->repository->findAll(); - } - - /** - * {@inheritdoc} - */ - public function findCartsBy(array $criteria) - { - return $this->findBy($criteria); - } -} diff --git a/src/Sylius/Bundle/CartBundle/Entity/ItemManager.php b/src/Sylius/Bundle/CartBundle/Entity/ItemManager.php deleted file mode 100644 index 74d21eaf9c..0000000000 --- a/src/Sylius/Bundle/CartBundle/Entity/ItemManager.php +++ /dev/null @@ -1,107 +0,0 @@ -entityManager = $entityManager; - $this->repository = $this->entityManager->getRepository($class); - } - - /** - * {@inheritdoc} - */ - public function createItem() - { - $class = $this->getClass(); - - return new $class; - } - - /** - * {@inheritdoc} - */ - public function persistItem(ItemInterface $cart) - { - $this->entityManager->persist($cart); - $this->entityManager->flush(); - } - - /** - * {@inheritdoc} - */ - public function removeItem(ItemInterface $cart) - { - $this->entityManager->remove($cart); - $this->entityManager->flush(); - } - - /** - * {@inheritdoc} - */ - public function findItem($id) - { - return $this->repository->find($id); - } - - /** - * {@inheritdoc} - */ - public function findItemBy(array $criteria) - { - return $this->repository->findOneBy($criteria); - } - - /** - * {@inheritdoc} - */ - public function findItems() - { - return $this->repository->findAll(); - } - - /** - * {@inheritdoc} - */ - public function findItemsBy(array $criteria) - { - return $this->findBy($criteria); - } -} diff --git a/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/CartOperationEvent.php b/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/CartOperationEvent.php deleted file mode 100644 index a5b73ec7e7..0000000000 --- a/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/CartOperationEvent.php +++ /dev/null @@ -1,53 +0,0 @@ - - */ -final class CartOperationEvent extends FilterCartEvent -{ - /** - * Cart item. - * - * @var ItemInterface - */ - private $item; - - /** - * 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; - } -} diff --git a/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/FilterCartEvent.php b/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/FilterCartEvent.php deleted file mode 100644 index 2a0e8b4abd..0000000000 --- a/src/Sylius/Bundle/CartBundle/EventDispatcher/Event/FilterCartEvent.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -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; - } -} diff --git a/src/Sylius/Bundle/CartBundle/EventDispatcher/SyliusCartEvents.php b/src/Sylius/Bundle/CartBundle/EventDispatcher/SyliusCartEvents.php deleted file mode 100644 index b4c266769f..0000000000 --- a/src/Sylius/Bundle/CartBundle/EventDispatcher/SyliusCartEvents.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -final class SyliusCartEvents -{ - const ITEM_ADD = 'sylius_cart.event.item.add'; - const ITEM_REMOVE = 'sylius_cart.event.item.remove'; - const CART_SAVE = 'sylius_cart.event.cart.save'; - const CART_CLEAR = 'sylius_cart.event.cart.clear'; - const CART_FLUSH = 'sylius_cart.event.cart.flush'; -} diff --git a/src/Sylius/Bundle/CartBundle/Form/Type/ItemType.php b/src/Sylius/Bundle/CartBundle/Form/Type/CartItemType.php similarity index 97% rename from src/Sylius/Bundle/CartBundle/Form/Type/ItemType.php rename to src/Sylius/Bundle/CartBundle/Form/Type/CartItemType.php index 1b33784684..0229c373d0 100644 --- a/src/Sylius/Bundle/CartBundle/Form/Type/ItemType.php +++ b/src/Sylius/Bundle/CartBundle/Form/Type/CartItemType.php @@ -20,7 +20,7 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface; * * @author Paweł Jędrzejewski */ -class ItemType extends AbstractType +class CartItemType extends AbstractType { /** * Data class. diff --git a/src/Sylius/Bundle/CartBundle/Model/Cart.php b/src/Sylius/Bundle/CartBundle/Model/Cart.php index 6fd434b2d2..a978642a60 100644 --- a/src/Sylius/Bundle/CartBundle/Model/Cart.php +++ b/src/Sylius/Bundle/CartBundle/Model/Cart.php @@ -11,6 +11,9 @@ namespace Sylius\Bundle\CartBundle\Model; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; + /** * Model for carts. * All driver entities and documents should extend this class or implement @@ -18,7 +21,7 @@ namespace Sylius\Bundle\CartBundle\Model; * * @author Paweł Jędrzejewski */ -abstract class Cart implements CartInterface +class Cart implements CartInterface { /** * Id. @@ -30,7 +33,7 @@ abstract class Cart implements CartInterface /** * Items in cart. * - * @var array + * @var Collection */ protected $items; @@ -41,6 +44,11 @@ abstract class Cart implements CartInterface */ protected $totalItems; + /** + * Total value. + */ + protected $total; + /** * Locked. * @@ -60,8 +68,9 @@ abstract class Cart implements CartInterface */ public function __construct() { - $this->items = array(); + $this->items = new ArrayCollection(); $this->totalItems = 0; + $this->total = 0; $this->locked = false; $this->incrementExpiresAt(); } @@ -74,14 +83,6 @@ abstract class Cart implements CartInterface return $this->id; } - /** - * {@inheritdoc} - */ - public function setId($id) - { - $this->id = $id; - } - /** * {@inheritdoc} */ @@ -101,9 +102,9 @@ abstract class Cart implements CartInterface /** * {@inheritdoc} */ - public function incrementTotalItems($amount = 1) + public function getTotalItems() { - $this->totalItems += $amount; + return $this->totalItems; } /** @@ -111,15 +112,23 @@ abstract class Cart implements CartInterface */ public function setTotalItems($totalItems) { + if (0 > $totalItems) { + throw new \OutOfRangeException('Total items must not be less than 0'); + } + $this->totalItems = $totalItems; } /** * {@inheritdoc} */ - public function getTotalItems() + public function changeTotalItems($amount) { - return $this->totalItems; + $this->totalItems += $amount; + + if (0 > $this->totalItems) { + $this->totalItems = 0; + } } /** @@ -141,11 +150,21 @@ abstract class Cart implements CartInterface /** * {@inheritdoc} */ - public function setItems($items) + public function setItems(Collection $items) { $this->items = $items; } + /** + * {@inheritdoc} + */ + public function clearItems() + { + $this->items->clear(); + + return $this; + } + /** * {@inheritdoc} */ @@ -157,60 +176,65 @@ abstract class Cart implements CartInterface /** * {@inheritdoc} */ - public function addItem(ItemInterface $item) + public function addItem(CartItemInterface $item) { - $exists = false; + if ($this->items->contains($item)) { + return $this; + } + foreach ($this->items as $existingItem) { - /** @var $existingItem ItemInterface */ if ($existingItem->equals($item)) { - $existingItem->incrementQuantity($item->getQuantity()); - $exists = true; - break; + $existingItem->setQuantity($existingItem->getQuantity() + $item->getQuantity()); + + return $this; } } - if (!$exists) { - $item->setCart($this); - $this->items[] = $item; - } + $this->items->add($item); + $item->setCart($this); + + return $this; } /** * {@inheritdoc} */ - public function removeItem(ItemInterface $item) + public function removeItem(CartItemInterface $item) { - $key = $this->searchItem($item); - if (false !== $key) { - unset($this->items[$key]); + if ($this->items->contains($item)) { + $this->items->removeElement($item); + $item->setCart(null); } + + return $this; } - /** - * {@inheritdoc} - */ - public function hasItem(ItemInterface $item) + public function hasItem(CartItemInterface $item) { - return false !== $this->searchItem($item); + return $this->items->contains($item); } - /** - * @param ItemInterface $item - * - * @return boolean|integer - */ - public function searchItem(ItemInterface $item) + public function getTotal() { - return array_search($item, $this->items, true); + return $this->total; } - /** - * {@inheritdoc} - */ - public function clearItems() + public function setTotal($total) { - $this->items = array(); + $this->total = $total; + } + + public function calculateTotal() + { + // Reset total. + $this->total = 0; + + foreach ($this->items as $item) { + $item->calculateTotal(); + + $this->total += $item->getTotal(); + } } /** @@ -218,7 +242,7 @@ abstract class Cart implements CartInterface */ public function isExpired() { - return $this->getExpiresAt() < new \DateTime; + return $this->getExpiresAt() < new \DateTime('now'); } /** diff --git a/src/Sylius/Bundle/CartBundle/Model/CartInterface.php b/src/Sylius/Bundle/CartBundle/Model/CartInterface.php index e57d63eb29..7d9579449d 100644 --- a/src/Sylius/Bundle/CartBundle/Model/CartInterface.php +++ b/src/Sylius/Bundle/CartBundle/Model/CartInterface.php @@ -11,49 +11,52 @@ namespace Sylius\Bundle\CartBundle\Model; +use Doctrine\Common\Collections\Collection; +use Sylius\Bundle\ResourceBundle\Model\ResourceInterface; + /** * Cart model interface. * All driver cart entities or documents should implement this interface. * * @author Paweł Jędrzejewski */ -interface CartInterface +interface CartInterface extends ResourceInterface { - /** - * Returns cart id. - * - * @return mixed - */ - function getId(); - - /** - * Sets cart id. - * - * @param mixed $id - */ - function setId($id); - /** * Returns number of items in cart. * * @return integer */ - function getTotalItems(); + public function getTotalItems(); /** * Sets number of items in cart. * * @param integer $totalItems; */ - function setTotalItems($totalItems); + public function setTotalItems($totalItems); /** - * Increments total items number by given amount. - * Default is 1. + * Change total items number by given amount. * * @param integer $amount */ - function incrementTotalItems($amount = 1); + public function changeTotalItems($amount); + + /** + * Get total cart value. + */ + public function getTotal(); + + /** + * Set total value. + */ + public function setTotal($total); + + /** + * Calculate total. + */ + public function calculateTotal(); /** * Checks whether the cart is locked or not. @@ -61,93 +64,93 @@ interface CartInterface * * @return Boolean */ - function isLocked(); + public function isLocked(); /** * Sets whether the cart is locked or not. * * @param Boolean $locked */ - function setLocked($locked); + public function setLocked($locked); /** * Checks whether the cart is empty or not. * * @return Boolean */ - function isEmpty(); + public function isEmpty(); /** * Counts manually all items in cart. * * @return integer */ - function countItems(); + public function countItems(); /** * Clears all items in cart. */ - function clearItems(); + public function clearItems(); /** * Sets collection of items * - * @param mixed $items + * @param Collection $items */ - function setItems($items); + public function setItems(Collection $items); /** * Returns collection of items in cart. * * @return mixed */ - function getItems(); + public function getItems(); /** * Adds item to cart. * - * @param ItemInterface $item + * @param CartItemInterface $item */ - function addItem(ItemInterface $item); + public function addItem(CartItemInterface $item); /** * Removes item from cart. * - * @param ItemInterface $item + * @param CartItemInterface $item */ - function removeItem(ItemInterface $item); + public function removeItem(CartItemInterface $item); /** * Checks whether given item is inside cart or not. * * @return Boolean */ - function hasItem(ItemInterface $item); + public function hasItem(CartItemInterface $item); /** * Gets expiration time. * * @return \DateTime */ - function getExpiresAt(); + public function getExpiresAt(); /** * Sets expiration time. * * @param \DateTime $expiresAt */ - function setExpiresAt(\DateTime $expiresAt = null); + public function setExpiresAt(\DateTime $expiresAt = null); /** * Bumps the expiration time. * Default is +3 hours. */ - function incrementExpiresAt(); + public function incrementExpiresAt(); /** * Checks whether the cart is expired or not. * * @return Boolean */ - function isExpired(); + public function isExpired(); } diff --git a/src/Sylius/Bundle/CartBundle/Model/Item.php b/src/Sylius/Bundle/CartBundle/Model/CartItem.php similarity index 63% rename from src/Sylius/Bundle/CartBundle/Model/Item.php rename to src/Sylius/Bundle/CartBundle/Model/CartItem.php index 367613e780..13f63298cd 100644 --- a/src/Sylius/Bundle/CartBundle/Model/Item.php +++ b/src/Sylius/Bundle/CartBundle/Model/CartItem.php @@ -16,12 +16,10 @@ namespace Sylius\Bundle\CartBundle\Model; * * @author Paweł Jędrzejewski */ -abstract class Item implements ItemInterface +class CartItem implements CartItemInterface { /** - * Id. - * - * @var mixed + * Cart item id. */ protected $id; @@ -39,12 +37,24 @@ abstract class Item implements ItemInterface */ protected $quantity; + /** + * Unit price. + */ + protected $unitPrice; + + /** + * Total value. + */ + protected $total; + /** * Constructor. */ public function __construct() { $this->quantity = 1; + $this->unitPrice = 0; + $this->total = 0; } /** @@ -55,14 +65,6 @@ abstract class Item implements ItemInterface return $this->id; } - /** - * {@inheritdoc} - */ - public function setId($id) - { - $this->id = $id; - } - /** * {@inheritdoc} */ @@ -93,34 +95,39 @@ abstract class Item implements ItemInterface public function setQuantity($quantity) { if (1 > $quantity) { - throw new \OutOfRangeException('Quantity value must be bigger than zero.'); + throw new \OutOfRangeException('Quantity must be greater than 0'); } $this->quantity = $quantity; } - /** - * {@inheritdoc} - */ - public function incrementQuantity($amount = 1) + public function getUnitPrice() { - $this->quantity += $amount; - - // Quantity must be bigger than zero - if (1 > $this->quantity) { - $this->quantity = 1; - } + return $this->unitPrice; } - /** - * {@inheritdoc} - */ - public function equals(ItemInterface $item) + public function setUnitPrice($unitPrice) { - if ($item->getId() !== $this->getId()) { - return false; - } + $this->unitPrice = $unitPrice; + } - return true; + public function getTotal() + { + return $this->total; + } + + public function setTotal($total) + { + $this->total = $total; + } + + public function calculateTotal() + { + $this->total = $this->quantity * $this->unitPrice; + } + + public function equals(CartItemInterface $cartItem) + { + return $this->getId() === $cartItem->getId(); } } diff --git a/src/Sylius/Bundle/CartBundle/Model/ItemInterface.php b/src/Sylius/Bundle/CartBundle/Model/CartItemInterface.php similarity index 55% rename from src/Sylius/Bundle/CartBundle/Model/ItemInterface.php rename to src/Sylius/Bundle/CartBundle/Model/CartItemInterface.php index 34f9537fb7..57594a3cab 100644 --- a/src/Sylius/Bundle/CartBundle/Model/ItemInterface.php +++ b/src/Sylius/Bundle/CartBundle/Model/CartItemInterface.php @@ -11,68 +11,75 @@ namespace Sylius\Bundle\CartBundle\Model; +use Sylius\Bundle\ResourceBundle\Model\ResourceInterface; + /** * Interface for cart item model. * * @author Paweł Jędrzejewski */ -interface ItemInterface +interface CartItemInterface extends ResourceInterface { - /** - * Returns item id. - * - * @return mixed - */ - function getId(); - - /** - * Sets item id. - * - * @param mixed $id - */ - function setId($id); - /** * Returns associated cart. * * @return CartInterface */ - function getCart(); + public function getCart(); /** * Sets cart. * * @param CartInterface */ - function setCart(CartInterface $cart = null); + public function setCart(CartInterface $cart = null); /** * Returns quantity. * * @return integer */ - function getQuantity(); + public function getQuantity(); /** * Sets quantity. * * @param $quantity */ - function setQuantity($quantity); + public function setQuantity($quantity); /** - * Increment quantity by given amount. - * By 1 as default. - * - * @param integer $quantity + * Get item price. */ - function incrementQuantity($amount = 1); + public function getUnitPrice(); + + /** + * Set item price. + */ + public function setUnitPrice($price); + + /** + * Set total. + */ + public function getTotal(); + + /** + * Set total. + */ + public function setTotal($total); + + /** + * Calulcate line total. + */ + public function calculateTotal(); /** * Checks whether the item given as argument corresponds to * the same cart item. Can be overriden to sum up quantity. * + * @param CartItemInterface $cartItem + * * @return Boolean */ - function equals(ItemInterface $item); + public function equals(CartItemInterface $cartItem); } diff --git a/src/Sylius/Bundle/CartBundle/Model/CartManager.php b/src/Sylius/Bundle/CartBundle/Model/CartManager.php deleted file mode 100644 index cc41ec3444..0000000000 --- a/src/Sylius/Bundle/CartBundle/Model/CartManager.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -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} - */ - public function getClass() - { - return $this->class; - } -} diff --git a/src/Sylius/Bundle/CartBundle/Model/CartManagerInterface.php b/src/Sylius/Bundle/CartBundle/Model/CartManagerInterface.php deleted file mode 100644 index a67a65a4cf..0000000000 --- a/src/Sylius/Bundle/CartBundle/Model/CartManagerInterface.php +++ /dev/null @@ -1,84 +0,0 @@ - - */ -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); - - /** - * Removes all saved carts that are expired. - */ - function flushCarts(); - - /** - * 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(); -} diff --git a/src/Sylius/Bundle/CartBundle/Model/ItemManager.php b/src/Sylius/Bundle/CartBundle/Model/ItemManager.php deleted file mode 100644 index 2dc1d83de5..0000000000 --- a/src/Sylius/Bundle/CartBundle/Model/ItemManager.php +++ /dev/null @@ -1,45 +0,0 @@ - - */ -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} - */ - public function getClass() - { - return $this->class; - } -} diff --git a/src/Sylius/Bundle/CartBundle/Model/ItemManagerInterface.php b/src/Sylius/Bundle/CartBundle/Model/ItemManagerInterface.php deleted file mode 100644 index 7a885ea550..0000000000 --- a/src/Sylius/Bundle/CartBundle/Model/ItemManagerInterface.php +++ /dev/null @@ -1,74 +0,0 @@ - - */ -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); -} diff --git a/src/Sylius/Bundle/CartBundle/Operator/CartOperator.php b/src/Sylius/Bundle/CartBundle/Operator/CartOperator.php index 089afb690e..0441d3b885 100644 --- a/src/Sylius/Bundle/CartBundle/Operator/CartOperator.php +++ b/src/Sylius/Bundle/CartBundle/Operator/CartOperator.php @@ -12,8 +12,8 @@ namespace Sylius\Bundle\CartBundle\Operator; use Sylius\Bundle\CartBundle\Model\CartInterface; -use Sylius\Bundle\CartBundle\Model\CartManagerInterface; -use Sylius\Bundle\CartBundle\Model\ItemInterface; +use Sylius\Bundle\CartBundle\Model\CartItemInterface; +use Sylius\Bundle\ResourceBundle\Manager\ResourceManagerInterface; /** * Base class for cart operator. @@ -22,21 +22,21 @@ use Sylius\Bundle\CartBundle\Model\ItemInterface; * * @author Paweł Jędrzejewski */ -abstract class CartOperator implements CartOperatorInterface +class CartOperator implements CartOperatorInterface { /** * Cart manager. * - * @var CartManagerInterface + * @var ResourceManagerInterface */ protected $cartManager; /** * Constructor. * - * @param CartManagerInterface $cartManager; + * @param ResourceManagerInterface $cartManager; */ - public function __construct(CartManagerInterface $cartManager) + public function __construct(ResourceManagerInterface $cartManager) { $this->cartManager = $cartManager; } @@ -44,17 +44,21 @@ abstract class CartOperator implements CartOperatorInterface /** * {@inheritdoc} */ - public function addItem(CartInterface $cart, ItemInterface $item) + public function addItem(CartInterface $cart, CartItemInterface $item) { $cart->addItem($item); + + return $this; } /** * {@inheritdoc} */ - public function removeItem(CartInterface $cart, ItemInterface $item) + public function removeItem(CartInterface $cart, CartItemInterface $item) { $cart->removeItem($item); + + return $this; } /** @@ -62,7 +66,10 @@ abstract class CartOperator implements CartOperatorInterface */ public function refresh(CartInterface $cart) { + $cart->calculateTotal(); $cart->setTotalItems($cart->countItems()); + + return $this; } /** @@ -70,7 +77,9 @@ abstract class CartOperator implements CartOperatorInterface */ public function clear(CartInterface $cart) { - $this->cartManager->removeCart($cart); + $this->cartManager->remove($cart); + + return $this; } /** @@ -78,6 +87,8 @@ abstract class CartOperator implements CartOperatorInterface */ public function save(CartInterface $cart) { - $this->cartManager->persistCart($cart); + $this->cartManager->persist($cart); + + return $this; } } diff --git a/src/Sylius/Bundle/CartBundle/Operator/CartOperatorInterface.php b/src/Sylius/Bundle/CartBundle/Operator/CartOperatorInterface.php index 9db24159ed..1ae12ccfb2 100644 --- a/src/Sylius/Bundle/CartBundle/Operator/CartOperatorInterface.php +++ b/src/Sylius/Bundle/CartBundle/Operator/CartOperatorInterface.php @@ -12,7 +12,7 @@ namespace Sylius\Bundle\CartBundle\Operator; use Sylius\Bundle\CartBundle\Model\CartInterface; -use Sylius\Bundle\CartBundle\Model\ItemInterface; +use Sylius\Bundle\CartBundle\Model\CartItemInterface; /** * Interface for cart operator. @@ -24,37 +24,37 @@ interface CartOperatorInterface /** * Adds item to cart. * - * @param CartInterface $cart - * @param ItemInterface $item + * @param CartInterface $cart + * @param CartItemInterface $item */ - function addItem(CartInterface $cart, ItemInterface $item); + public function addItem(CartInterface $cart, CartItemInterface $item); /** * Removes item from cart. * - * @param CartInterface $cart - * @param ItemInterface $item + * @param CartInterface $cart + * @param CartItemInterface $item */ - function removeItem(CartInterface $cart, ItemInterface $item); + public function removeItem(CartInterface $cart, CartItemInterface $item); /** * Refreshes cart data. * * @param CartInterface $cart */ - function refresh(CartInterface $cart); + public function refresh(CartInterface $cart); /** * Saves cart at current state. * * @param CartInterface $cart */ - function save(CartInterface $cart); + public function save(CartInterface $cart); /** * Clears current cart. * * @param CartInterface $cart */ - function clear(CartInterface $cart); + public function clear(CartInterface $cart); } diff --git a/src/Sylius/Bundle/CartBundle/Provider/CartProvider.php b/src/Sylius/Bundle/CartBundle/Provider/CartProvider.php index 81d6c05171..868a555703 100644 --- a/src/Sylius/Bundle/CartBundle/Provider/CartProvider.php +++ b/src/Sylius/Bundle/CartBundle/Provider/CartProvider.php @@ -12,8 +12,8 @@ namespace Sylius\Bundle\CartBundle\Provider; use Sylius\Bundle\CartBundle\Model\CartInterface; -use Sylius\Bundle\CartBundle\Model\CartManagerInterface; use Sylius\Bundle\CartBundle\Storage\CartStorageInterface; +use Sylius\Bundle\ResourceBundle\Manager\ResourceManagerInterface; /** * Default provider cart. @@ -32,7 +32,7 @@ class CartProvider implements CartProviderInterface /** * Cart manager. * - * @var CartManagerInterface + * @var ResourceManagerInterface */ protected $cartManager; @@ -46,10 +46,10 @@ class CartProvider implements CartProviderInterface /** * Constructor. * - * @param CartStorageInterface $storage - * @param CartManagerInterface $cartManager + * @param CartStorageInterface $storage + * @param ResourceManagerInterface $cartManager */ - public function __construct(CartStorageInterface $storage, CartManagerInterface $cartManager) + public function __construct(CartStorageInterface $storage, ResourceManagerInterface $cartManager) { $this->storage = $storage; $this->cartManager = $cartManager; @@ -68,12 +68,13 @@ class CartProvider implements CartProviderInterface if ($cart) { $this->cart = $cart; + return $cart; } } - $cart = $this->cartManager->createCart(); - $this->cartManager->persistCart($cart); + $cart = $this->cartManager->create(); + $this->cartManager->persist($cart); $this->storage->setCurrentCartIdentifier($cart); $this->cart = $cart; @@ -103,11 +104,11 @@ class CartProvider implements CartProviderInterface /** * Gets cart by cart identifier. * - * @param mixed $identifier + * @param mixed $identifier * @return CartInterface|null */ protected function getCartByIdentifier($identifier) { - return $this->cartManager->findCart($identifier); + return $this->cartManager->find($identifier); } } diff --git a/src/Sylius/Bundle/CartBundle/Provider/CartProviderInterface.php b/src/Sylius/Bundle/CartBundle/Provider/CartProviderInterface.php index bbbee5807c..e5342097c3 100644 --- a/src/Sylius/Bundle/CartBundle/Provider/CartProviderInterface.php +++ b/src/Sylius/Bundle/CartBundle/Provider/CartProviderInterface.php @@ -27,7 +27,7 @@ interface CartProviderInterface * * @return CartInterface */ - function getCart(); + public function getCart(); /** * Sets given cart as current one. @@ -35,10 +35,10 @@ interface CartProviderInterface * * @param CartInterface $cart */ - function setCart(CartInterface $cart); + public function setCart(CartInterface $cart); /** * Abandon current cart. */ - function abandonCart(); + public function abandonCart(); } diff --git a/src/Sylius/Bundle/CartBundle/README.md b/src/Sylius/Bundle/CartBundle/README.md index e0fffeba29..3d63f9de69 100644 --- a/src/Sylius/Bundle/CartBundle/README.md +++ b/src/Sylius/Bundle/CartBundle/README.md @@ -2,19 +2,7 @@ SyliusCartBundle [![Build status...](https://secure.travis-ci.org/Sylius/SyliusC ================ 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. - -Features --------- - -* Base support for many different persistence layers. Currently only Doctrine ORM driver is implemented. -* Cart item is simple model and you can make it look whatever you like. -* Sensible default model for cart. -* Flexible item resolver that allows you to build and add items the way you prefer. -* Default cart operator implementation handles most basic cart scenario and can be easily extended. -* Common actions like adding/removing items, updating, clearing and viewing the cart are implemented in controllers shipped with the bundle. -* Flushing expired carts. -* Thanks to awesome [Symfony2](http://symfony.com) everything is configurable and extensible. +Should be considered as base for building solution that fits your exact needs. Sylius ------ @@ -26,7 +14,7 @@ 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/SyliusCartBundle) for CI. +This bundle uses [travis-ci.org](http://travis-ci.org/Sylius/SyliusCartBundle). [![Build status...](https://secure.travis-ci.org/Sylius/SyliusCartBundle.png)](http://travis-ci.org/Sylius/SyliusCartBundle) Before running tests, load the dependencies using [Composer](http://packagist.org). diff --git a/src/Sylius/Bundle/CartBundle/Resolver/ItemResolverInterface.php b/src/Sylius/Bundle/CartBundle/Resolver/ItemResolverInterface.php index a85a75fb4e..4085ff23bf 100644 --- a/src/Sylius/Bundle/CartBundle/Resolver/ItemResolverInterface.php +++ b/src/Sylius/Bundle/CartBundle/Resolver/ItemResolverInterface.php @@ -11,7 +11,7 @@ namespace Sylius\Bundle\CartBundle\Resolver; -use Sylius\Bundle\CartBundle\Model\ItemInterface; +use Sylius\Bundle\CartBundle\Model\CartItemInterface; use Symfony\Component\HttpFoundation\Request; /** @@ -27,16 +27,16 @@ interface ItemResolverInterface * * @param Request $request * - * @return ItemInterface + * @return CartItemInterface */ - function resolveItemToAdd(Request $request); + public function resolveItemToAdd(Request $request); /** * Returns item to remove. * * @param Request $request * - * @return ItemInterface + * @return CartItemInterface */ - function resolveItemToRemove(Request $request); + public function resolveItemToRemove(Request $request); } diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/controllers.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/controllers.xml deleted file mode 100644 index 13a6793ac6..0000000000 --- a/src/Sylius/Bundle/CartBundle/Resources/config/container/controllers.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/driver/doctrine/orm.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/driver/doctrine/orm.xml index 759227d8c1..06a2bc73fc 100644 --- a/src/Sylius/Bundle/CartBundle/Resources/config/container/driver/doctrine/orm.xml +++ b/src/Sylius/Bundle/CartBundle/Resources/config/container/driver/doctrine/orm.xml @@ -1,4 +1,4 @@ - + - - - - diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/engine/twig.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/engine/twig.xml index 5f577cbca2..15eafcc252 100644 --- a/src/Sylius/Bundle/CartBundle/Resources/config/container/engine/twig.xml +++ b/src/Sylius/Bundle/CartBundle/Resources/config/container/engine/twig.xml @@ -1,4 +1,4 @@ - + - - - - - - %sylius_cart.model.cart.class% - - - - %sylius_cart.model.item.class% - - - - - diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/provider.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/provider.xml deleted file mode 100644 index b16c8be21a..0000000000 --- a/src/Sylius/Bundle/CartBundle/Resources/config/container/provider.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/services.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/services.xml new file mode 100644 index 0000000000..d1fed9b863 --- /dev/null +++ b/src/Sylius/Bundle/CartBundle/Resources/config/container/services.xml @@ -0,0 +1,54 @@ + + + + + + + + Sylius\Bundle\CartBundle\Operator\CartOperator + Sylius\Bundle\CartBundle\Storage\SessionCartStorage + + + + + + + + + + + %sylius_cart.model.cart.class% + + + + %sylius_cart.model.item.class% + + + + + + + + + + + + + + + + + + diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/container/storage.xml b/src/Sylius/Bundle/CartBundle/Resources/config/container/storage.xml deleted file mode 100644 index 305b4a0788..0000000000 --- a/src/Sylius/Bundle/CartBundle/Resources/config/container/storage.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - Sylius\Bundle\CartBundle\Storage\SessionCartStorage - - - - - - - - - diff --git a/src/Sylius/Bundle/CartBundle/Resources/config/doctrine/Cart.orm.xml b/src/Sylius/Bundle/CartBundle/Resources/config/doctrine/Cart.orm.xml index 331066b179..2223faf2a5 100644 --- a/src/Sylius/Bundle/CartBundle/Resources/config/doctrine/Cart.orm.xml +++ b/src/Sylius/Bundle/CartBundle/Resources/config/doctrine/Cart.orm.xml @@ -1,4 +1,4 @@ - +