Skip to content

Commit

Permalink
Fix magento#12802 - allow to override preference over \Magento\Quote\…
Browse files Browse the repository at this point in the history
…Api\Data\CartInterface and return correct object from QuoteRepository (+4 squashed commits)

Squashed commits:
[55b9f3ec52b] Fix magento#12802 - fix phpmd, mark quoteFactory as deprecated
[56ca9a42468] Fix magento#12802 - change condition in quoteRepository
[734212812a4] Fix magento#12802 - revert change of constructor parameters names
[ba8ad543e0f] Fix magento#12802 - remove instanceof condition
  • Loading branch information
Bartlomiejsz committed Apr 5, 2019
1 parent 05217b0 commit 865d7df
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 67 deletions.
70 changes: 41 additions & 29 deletions app/code/Magento/Quote/Model/QuoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
*/
namespace Magento\Quote\Model;

use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Framework\Api\Search\FilterGroup;
use Magento\Framework\Api\SearchCriteria\CollectionProcessor;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Api\SortOrder;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Api\Search\FilterGroup;
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
use Magento\Quote\Api\Data\CartInterfaceFactory;
use Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory;
use Magento\Quote\Model\QuoteRepository\SaveHandler;
use Magento\Quote\Model\QuoteRepository\LoadHandler;
use Magento\Quote\Model\ResourceModel\Quote\Collection as QuoteCollection;
use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteCollectionFactory;
use Magento\Store\Model\StoreManagerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
class QuoteRepository implements CartRepositoryInterface
{
/**
* @var Quote[]
Expand All @@ -37,6 +40,7 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface

/**
* @var QuoteFactory
* @deprecated
*/
protected $quoteFactory;

Expand All @@ -46,13 +50,13 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
protected $storeManager;

/**
* @var \Magento\Quote\Model\ResourceModel\Quote\Collection
* @var QuoteCollection
* @deprecated 100.2.0
*/
protected $quoteCollection;

/**
* @var \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory
* @var CartSearchResultsInterfaceFactory
*/
protected $searchResultsDataFactory;

Expand All @@ -77,39 +81,47 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
private $collectionProcessor;

/**
* @var \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory
* @var QuoteCollectionFactory
*/
private $quoteCollectionFactory;

/**
* @var CartInterfaceFactory
*/
private $cartFactory;

/**
* Constructor
*
* @param QuoteFactory $quoteFactory
* @param StoreManagerInterface $storeManager
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection
* @param \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory
* @param QuoteCollection $quoteCollection
* @param CartSearchResultsInterfaceFactory $searchResultsDataFactory
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
* @param CollectionProcessorInterface|null $collectionProcessor
* @param \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory|null $quoteCollectionFactory
* @param QuoteCollectionFactory|null $quoteCollectionFactory
* @param CartInterfaceFactory|null $cartFactory
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
QuoteFactory $quoteFactory,
StoreManagerInterface $storeManager,
\Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection,
\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory,
QuoteCollection $quoteCollection,
CartSearchResultsInterfaceFactory $searchResultsDataFactory,
JoinProcessorInterface $extensionAttributesJoinProcessor,
CollectionProcessorInterface $collectionProcessor = null,
\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory = null
QuoteCollectionFactory $quoteCollectionFactory = null,
CartInterfaceFactory $cartFactory = null
) {
$this->quoteFactory = $quoteFactory;
$this->storeManager = $storeManager;
$this->searchResultsDataFactory = $searchResultsDataFactory;
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
$this->collectionProcessor = $collectionProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessor::class);
$this->quoteCollectionFactory = $quoteCollectionFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory::class);
$this->collectionProcessor = $collectionProcessor ?: ObjectManager::getInstance()
->get(CollectionProcessor::class);
$this->quoteCollectionFactory = $quoteCollectionFactory ?: ObjectManager::getInstance()
->get(QuoteCollectionFactory::class);
$this->cartFactory = $cartFactory ?: ObjectManager::getInstance()->get(CartInterfaceFactory::class);
}

/**
Expand Down Expand Up @@ -166,7 +178,7 @@ public function getActiveForCustomer($customerId, array $sharedStoreIds = [])
/**
* {@inheritdoc}
*/
public function save(\Magento\Quote\Api\Data\CartInterface $quote)
public function save(CartInterface $quote)
{
if ($quote->getId()) {
$currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
Expand All @@ -186,7 +198,7 @@ public function save(\Magento\Quote\Api\Data\CartInterface $quote)
/**
* {@inheritdoc}
*/
public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
public function delete(CartInterface $quote)
{
$quoteId = $quote->getId();
$customerId = $quote->getCustomerId();
Expand All @@ -203,13 +215,13 @@ public function delete(\Magento\Quote\Api\Data\CartInterface $quote)
* @param int $identifier
* @param int[] $sharedStoreIds
* @throws NoSuchEntityException
* @return Quote
* @return CartInterface
*/
protected function loadQuote($loadMethod, $loadField, $identifier, array $sharedStoreIds = [])
{
/** @var Quote $quote */
$quote = $this->quoteFactory->create();
if ($sharedStoreIds) {
/** @var CartInterface $quote */
$quote = $this->cartFactory->create();
if ($sharedStoreIds && method_exists($quote, 'setSharedStoreIds')) {
$quote->setSharedStoreIds($sharedStoreIds);
}
$quote->setStoreId($this->storeManager->getStore()->getId())->$loadMethod($identifier);
Expand All @@ -222,7 +234,7 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
public function getList(SearchCriteriaInterface $searchCriteria)
{
$this->quoteCollection = $this->quoteCollectionFactory->create();
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
Expand Down
Loading

0 comments on commit 865d7df

Please sign in to comment.