Skip to content

Commit ede3748

Browse files
author
Cari Spruiell
committed
MAGETWO-36376: Magento\Quote\Api\GuestCartItemRepository
- refactor GuestCartItemRepository to use composition instead of inheritance - updated unit tests - removed saveForCustomer from guest interface and implementation - updated GuestCartTestHelper to allow magic method to be mocked
1 parent c30e6de commit ede3748

File tree

4 files changed

+93
-197
lines changed

4 files changed

+93
-197
lines changed

app/code/Magento/Quote/Api/GuestCartItemRepositoryInterface.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,4 @@ public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem);
4949
* @throws \Magento\Framework\Exception\CouldNotSaveException The item could not be removed.
5050
*/
5151
public function deleteById($cartId, $itemId);
52-
53-
/**
54-
* Adds the specified item to the specified cart.
55-
*
56-
* @param int $customerId Customer ID.
57-
* @param \Magento\Quote\Api\Data\CartItemInterface $cartItem The item.
58-
* @return \Magento\Quote\Api\Data\CartItemInterface Item.
59-
* @throws \Magento\Framework\Exception\NoSuchEntityException The specified cart does not exist.
60-
* @throws \Magento\Framework\Exception\CouldNotSaveException The specified item could not be saved to the cart.
61-
* @throws \Magento\Framework\Exception\InputException The specified item or cart is not valid.
62-
*/
63-
public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem);
6452
}

app/code/Magento/Quote/Model/GuestCart/GuestCartItemRepository.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
/**
1515
* Cart Item repository class for guest carts.
1616
*/
17-
class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface
17+
class GuestCartItemRepository implements \Magento\Quote\Api\GuestCartItemRepositoryInterface
1818
{
19+
/**
20+
* @var Repository
21+
*/
22+
protected $repository;
23+
1924
/**
2025
* @var QuoteIdMaskFactory
2126
*/
@@ -24,19 +29,15 @@ class GuestCartItemRepository extends Repository implements \Magento\Quote\Api\G
2429
/**
2530
* Constructs a read service object.
2631
*
27-
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
28-
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
29-
* @param \Magento\Quote\Api\Data\CartItemInterfaceFactory $itemDataFactory
32+
* @param \Magento\Quote\Model\Quote\Item\Repository $repository
3033
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3134
*/
3235
public function __construct(
33-
\Magento\Quote\Model\QuoteRepository $quoteRepository,
34-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
35-
\Magento\Quote\Api\Data\CartItemInterfaceFactory $itemDataFactory,
36+
\Magento\Quote\Model\Quote\Item\Repository $repository,
3637
QuoteIdMaskFactory $quoteIdMaskFactory
3738
) {
3839
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
39-
parent::__construct($quoteRepository, $productRepository, $itemDataFactory);
40+
$this->repository = $repository;
4041
}
4142

4243
/**
@@ -46,7 +47,7 @@ public function getList($cartId)
4647
{
4748
/** @var $quoteIdMask QuoteIdMask */
4849
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
49-
$cartItemList = parent::getList($quoteIdMask->getId());
50+
$cartItemList = $this->repository->getList($quoteIdMask->getId());
5051
/** @var $item CartItemInterface */
5152
foreach ($cartItemList as $item) {
5253
$item->setQuoteId($quoteIdMask->getMaskedId());
@@ -62,7 +63,7 @@ public function save(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
6263
/** @var $quoteIdMask QuoteIdMask */
6364
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id');
6465
$cartItem->setQuoteId($quoteIdMask->getId());
65-
return parent::save($cartItem);
66+
return $this->repository->save($cartItem);
6667
}
6768

6869
/**
@@ -72,17 +73,17 @@ public function deleteById($cartId, $itemId)
7273
{
7374
/** @var $quoteIdMask QuoteIdMask */
7475
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
75-
return parent::deleteById($quoteIdMask->getId(), $itemId);
76+
return $this->repository->deleteById($quoteIdMask->getId(), $itemId);
7677
}
7778

7879
/**
7980
* {@inheritdoc}
8081
*/
81-
public function saveForCustomer($customerId, \Magento\Quote\Api\Data\CartItemInterface $cartItem)
82+
public function delete(\Magento\Quote\Api\Data\CartItemInterface $cartItem)
8283
{
8384
/** @var $quoteIdMask QuoteIdMask */
8485
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartItem->getQuoteId(), 'masked_id');
8586
$cartItem->setQuoteId($quoteIdMask->getId());
86-
return parent::saveForCustomer($customerId, $cartItem);
87+
return $this->repository->delete($cartItem);
8788
}
8889
}

0 commit comments

Comments
 (0)