Skip to content
Browse files

Merge pull request #32 from rubas/master

add check if cart exists without creating a new one
  • Loading branch information...
2 parents 2e66c35 + 20f0d85 commit a1eff4033588f9ddbca466a6515a5531ca61fd3f @pjedrzejewski pjedrzejewski committed Mar 3, 2013
Showing with 29 additions and 2 deletions.
  1. +8 −0 Provider/CartProvider.php
  2. +8 −0 Provider/CartProviderInterface.php
  3. +13 −2 Twig/SyliusCartExtension.php
View
8 Provider/CartProvider.php
@@ -68,6 +68,14 @@ public function __construct(CartStorageInterface $storage, ObjectManager $manage
/**
* {@inheritdoc}
*/
+ public function hasCart()
+ {
+ return null !== $this->cart;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getCart()
{
if (null !== $this->cart) {
View
8 Provider/CartProviderInterface.php
@@ -22,6 +22,14 @@
interface CartProviderInterface
{
/**
+ * Returns true if a cart exists otherwise false.
+ * It does not create a new cart if none exists
+ *
+ * @return boolean
+ */
+ public function hasCart();
+
+ /**
* Returns current cart.
* If none found is by storage, it should create new one and save it.
*
View
15 Twig/SyliusCartExtension.php
@@ -65,8 +65,9 @@ public function __construct(CartProviderInterface $cartProvider, ObjectRepositor
public function getFunctions()
{
return array(
- 'sylius_cart_get' => new Twig_Function_Method($this, 'getCurrentCart'),
- 'sylius_cart_form' => new Twig_Function_Method($this, 'getItemFormView'),
+ 'sylius_cart_exists' => new Twig_Function_Method($this, 'hasCart'),
+ 'sylius_cart_get' => new Twig_Function_Method($this, 'getCurrentCart'),
+ 'sylius_cart_form' => new Twig_Function_Method($this, 'getItemFormView'),
);
}
@@ -81,6 +82,16 @@ public function getCurrentCart()
}
/**
+ * Check if a cart exists.
+ *
+ * @return boolean
+ */
+ public function hasCart()
+ {
+ return $this->cartProvider->hasCart();
+ }
+
+ /**
* Returns cart item form view.
*
* @param array $options

0 comments on commit a1eff40

Please sign in to comment.
Something went wrong with that request. Please try again.