Use resource repository

This commit is contained in:
Paweł Jędrzejewski 2012-11-05 01:33:03 +01:00
parent d5f4f1e2fc
commit 9145ce70d1
2 changed files with 19 additions and 8 deletions

View file

@ -14,6 +14,7 @@ namespace Sylius\Bundle\CartBundle\Provider;
use Sylius\Bundle\CartBundle\Model\CartInterface; use Sylius\Bundle\CartBundle\Model\CartInterface;
use Sylius\Bundle\CartBundle\Storage\CartStorageInterface; use Sylius\Bundle\CartBundle\Storage\CartStorageInterface;
use Sylius\Bundle\ResourceBundle\Manager\ResourceManagerInterface; use Sylius\Bundle\ResourceBundle\Manager\ResourceManagerInterface;
use Sylius\Bundle\ResourceBundle\Repository\ResourceRepositoryInterface;
/** /**
* Default provider cart. * Default provider cart.
@ -34,7 +35,14 @@ class CartProvider implements CartProviderInterface
* *
* @var ResourceManagerInterface * @var ResourceManagerInterface
*/ */
protected $cartManager; protected $manager;
/**
* Cart repository.
*
* @var ResourceRepositoryInterface
*/
protected $repository;
/** /**
* Cart. * Cart.
@ -46,13 +54,15 @@ class CartProvider implements CartProviderInterface
/** /**
* Constructor. * Constructor.
* *
* @param CartStorageInterface $storage * @param CartStorageInterface $storage
* @param ResourceManagerInterface $cartManager * @param ResourceManagerInterface $manager
* @param ResourceRepositoryInterface $repository
*/ */
public function __construct(CartStorageInterface $storage, ResourceManagerInterface $cartManager) public function __construct(CartStorageInterface $storage, ResourceManagerInterface $manager, ResourceRepositoryInterface $repository)
{ {
$this->storage = $storage; $this->storage = $storage;
$this->cartManager = $cartManager; $this->manager = $manager;
$this->repository = $repository;
} }
/** /**
@ -70,8 +80,8 @@ class CartProvider implements CartProviderInterface
return $this->cart = $cart; return $this->cart = $cart;
} }
$cart = $this->cartManager->create(); $cart = $this->manager->create();
$this->cartManager->persist($cart); $this->manager->persist($cart);
$this->setCart($cart); $this->setCart($cart);
@ -104,6 +114,6 @@ class CartProvider implements CartProviderInterface
*/ */
protected function getCartByIdentifier($identifier) protected function getCartByIdentifier($identifier)
{ {
return $this->cartManager->find($identifier); return $this->repository->get(array('id' => $identifier));
} }
} }

View file

@ -47,6 +47,7 @@
<service id="sylius_cart.provider" class="%sylius_cart.provider.class%"> <service id="sylius_cart.provider" class="%sylius_cart.provider.class%">
<argument type="service" id="sylius_cart.storage" /> <argument type="service" id="sylius_cart.storage" />
<argument type="service" id="sylius_cart.manager.cart" /> <argument type="service" id="sylius_cart.manager.cart" />
<argument type="service" id="sylius_cart.repository.cart" />
</service> </service>
<service id="sylius_cart.storage.session" class="%sylius_cart.storage.session.class%"> <service id="sylius_cart.storage.session" class="%sylius_cart.storage.session.class%">