Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
QuoteRepository Class Reference
Inheritance diagram for QuoteRepository:
CartRepositoryInterface

Public Member Functions

 __construct (QuoteFactory $quoteFactory, StoreManagerInterface $storeManager, \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection, \Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory $searchResultsDataFactory, JoinProcessorInterface $extensionAttributesJoinProcessor, CollectionProcessorInterface $collectionProcessor=null, \Magento\Quote\Model\ResourceModel\Quote\CollectionFactory $quoteCollectionFactory=null)
 
 get ($cartId, array $sharedStoreIds=[])
 
 getForCustomer ($customerId, array $sharedStoreIds=[])
 
 getActive ($cartId, array $sharedStoreIds=[])
 
 getActiveForCustomer ($customerId, array $sharedStoreIds=[])
 
 save (\Magento\Quote\Api\Data\CartInterface $quote)
 
 delete (\Magento\Quote\Api\Data\CartInterface $quote)
 
- Public Member Functions inherited from CartRepositoryInterface
 get ($cartId)
 
 getList (\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 
 save (\Magento\Quote\Api\Data\CartInterface $quote)
 
 delete (\Magento\Quote\Api\Data\CartInterface $quote)
 

Protected Member Functions

 addFilterGroupToCollection (FilterGroup $filterGroup, QuoteCollection $collection)
 

Protected Attributes

 $quotesById = []
 
 $quotesByCustomerId = []
 
 $quoteFactory
 
 $storeManager
 
 $quoteCollection
 
 $searchResultsDataFactory
 

Detailed Description

@SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 26 of file QuoteRepository.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( QuoteFactory  $quoteFactory,
StoreManagerInterface  $storeManager,
\Magento\Quote\Model\ResourceModel\Quote\Collection  $quoteCollection,
\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory  $searchResultsDataFactory,
JoinProcessorInterface  $extensionAttributesJoinProcessor,
CollectionProcessorInterface  $collectionProcessor = null,
\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory  $quoteCollectionFactory = null 
)

Constructor

Parameters
QuoteFactory$quoteFactory
StoreManagerInterface$storeManager
\Magento\Quote\Model\ResourceModel\Quote\Collection$quoteCollection
\Magento\Quote\Api\Data\CartSearchResultsInterfaceFactory$searchResultsDataFactory
JoinProcessorInterface$extensionAttributesJoinProcessor
CollectionProcessorInterface | null$collectionProcessor
\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory | null$quoteCollectionFactory@SuppressWarnings(PHPMD.UnusedFormalParameter)

Definition at line 96 of file QuoteRepository.php.

104  {
105  $this->quoteFactory = $quoteFactory;
106  $this->storeManager = $storeManager;
107  $this->searchResultsDataFactory = $searchResultsDataFactory;
108  $this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
109  $this->collectionProcessor = $collectionProcessor ?: \Magento\Framework\App\ObjectManager::getInstance()
110  ->get(\Magento\Framework\Api\SearchCriteria\CollectionProcessor::class);
111  $this->quoteCollectionFactory = $quoteCollectionFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
112  ->get(\Magento\Quote\Model\ResourceModel\Quote\CollectionFactory::class);
113  }

Member Function Documentation

◆ addFilterGroupToCollection()

addFilterGroupToCollection ( FilterGroup  $filterGroup,
QuoteCollection  $collection 
)
protected

Adds a specified filter group to the specified quote collection.

Parameters
FilterGroup$filterGroupThe filter group.
QuoteCollection$collectionThe quote collection.
Returns
void
Deprecated:
101.0.0
Exceptions
InputExceptionThe specified filter group or quote collection does not exist.

Definition at line 252 of file QuoteRepository.php.

253  {
254  $fields = [];
255  $conditions = [];
256  foreach ($filterGroup->getFilters() as $filter) {
257  $fields[] = $filter->getField();
258  $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
259  $conditions[] = [$condition => $filter->getValue()];
260  }
261  if ($fields) {
262  $collection->addFieldToFilter($fields, $conditions);
263  }
264  }
$fields
Definition: details.phtml:14

◆ delete()

{}

Definition at line 189 of file QuoteRepository.php.

190  {
191  $quoteId = $quote->getId();
192  $customerId = $quote->getCustomerId();
193  $quote->delete();
194  unset($this->quotesById[$quoteId]);
195  unset($this->quotesByCustomerId[$customerId]);
196  }
$quote

◆ get()

get (   $cartId,
array  $sharedStoreIds = [] 
)

{}

Definition at line 118 of file QuoteRepository.php.

119  {
120  if (!isset($this->quotesById[$cartId])) {
121  $quote = $this->loadQuote('loadByIdWithoutStore', 'cartId', $cartId, $sharedStoreIds);
122  $this->getLoadHandler()->load($quote);
123  $this->quotesById[$cartId] = $quote;
124  }
125  return $this->quotesById[$cartId];
126  }
$quote
$cartId
Definition: quote.php:22

◆ getActive()

getActive (   $cartId,
array  $sharedStoreIds = [] 
)

{Get active quote by id

Parameters
int$cartId
int[]$sharedStoreIds
Returns
\Magento\Quote\Api\Data\CartInterface
Exceptions
}

Implements CartRepositoryInterface.

Definition at line 145 of file QuoteRepository.php.

146  {
147  $quote = $this->get($cartId, $sharedStoreIds);
148  if (!$quote->getIsActive()) {
150  }
151  return $quote;
152  }
$quote
$cartId
Definition: quote.php:22

◆ getActiveForCustomer()

getActiveForCustomer (   $customerId,
array  $sharedStoreIds = [] 
)

{Get active quote by customer Id

Parameters
int$customerId
int[]$sharedStoreIds
Returns
\Magento\Quote\Api\Data\CartInterface
Exceptions
}

Implements CartRepositoryInterface.

Definition at line 157 of file QuoteRepository.php.

158  {
159  $quote = $this->getForCustomer($customerId, $sharedStoreIds);
160  if (!$quote->getIsActive()) {
161  throw NoSuchEntityException::singleField('customerId', $customerId);
162  }
163  return $quote;
164  }
$quote
getForCustomer($customerId, array $sharedStoreIds=[])

◆ getForCustomer()

getForCustomer (   $customerId,
array  $sharedStoreIds = [] 
)

{Get quote by customer Id

Parameters
int$customerId
int[]$sharedStoreIds
Returns
\Magento\Quote\Api\Data\CartInterface
Exceptions
}

Implements CartRepositoryInterface.

Definition at line 131 of file QuoteRepository.php.

132  {
133  if (!isset($this->quotesByCustomerId[$customerId])) {
134  $quote = $this->loadQuote('loadByCustomer', 'customerId', $customerId, $sharedStoreIds);
135  $this->getLoadHandler()->load($quote);
136  $this->quotesById[$quote->getId()] = $quote;
137  $this->quotesByCustomerId[$customerId] = $quote;
138  }
139  return $this->quotesByCustomerId[$customerId];
140  }
$quote

◆ save()

{}

Definition at line 169 of file QuoteRepository.php.

170  {
171  if ($quote->getId()) {
172  $currentQuote = $this->get($quote->getId(), [$quote->getStoreId()]);
173 
174  foreach ($currentQuote->getData() as $key => $value) {
175  if (!$quote->hasData($key)) {
176  $quote->setData($key, $value);
177  }
178  }
179  }
180 
181  $this->getSaveHandler()->save($quote);
182  unset($this->quotesById[$quote->getId()]);
183  unset($this->quotesByCustomerId[$quote->getCustomerId()]);
184  }
$quote
$value
Definition: gender.phtml:16

Field Documentation

◆ $quoteCollection

$quoteCollection
protected

Definition at line 52 of file QuoteRepository.php.

◆ $quoteFactory

$quoteFactory
protected

Definition at line 41 of file QuoteRepository.php.

◆ $quotesByCustomerId

$quotesByCustomerId = []
protected

Definition at line 36 of file QuoteRepository.php.

◆ $quotesById

$quotesById = []
protected

Definition at line 31 of file QuoteRepository.php.

◆ $searchResultsDataFactory

$searchResultsDataFactory
protected

Definition at line 57 of file QuoteRepository.php.

◆ $storeManager

$storeManager
protected

Definition at line 46 of file QuoteRepository.php.


The documentation for this class was generated from the following file: