16 use Magento\Sales\Api\Data\TransactionSearchResultInterfaceFactory as SearchResultFactory;
19 use Magento\Sales\Model\EntityStorageFactory;
34 private $searchResultFactory =
null;
39 private $filterBuilder;
44 private $searchCriteriaBuilder;
54 private $sortOrderBuilder;
59 private $entityStorage;
64 private $collectionProcessor;
77 SearchResultFactory $searchResultFactory,
82 EntityStorageFactory $entityStorageFactory,
85 $this->searchResultFactory = $searchResultFactory;
86 $this->filterBuilder = $filterBuilder;
88 $this->sortOrderBuilder = $sortOrderBuilder;
89 $this->metaData = $metaData;
90 $this->entityStorage = $entityStorageFactory->create();
91 $this->collectionProcessor = $collectionProcessor ?: $this->getCollectionProcessor();
97 public function get(
$id)
100 throw new \Magento\Framework\Exception\InputException(
__(
'An ID is needed. Set the ID and try again.'));
102 if (!$this->entityStorage->has(
$id)) {
103 $entity = $this->metaData->getNewInstance()->load(
$id);
104 if (!
$entity->getTransactionId()) {
106 __(
"The entity that was requested doesn't exist. Verify the entity and try again.")
109 $this->entityStorage->add(
$entity);
111 return $this->entityStorage->get(
$id);
122 $identityFieldsForCache = [$transactionType, $paymentId];
123 $cacheStorage =
'txn_type';
124 $entity = $this->entityStorage->getByIdentifyingFields($identityFieldsForCache, $cacheStorage);
126 $typeFilter = $this->filterBuilder
128 ->setValue($transactionType)
130 $idFilter = $this->filterBuilder
132 ->setValue($paymentId)
134 $transactionIdSort = $this->sortOrderBuilder
135 ->setField(
'transaction_id')
138 $createdAtSort = $this->sortOrderBuilder
139 ->setField(
'created_at')
144 $this->searchCriteriaBuilder
145 ->addFilters([$typeFilter])
146 ->addFilters([$idFilter])
147 ->addSortOrder($transactionIdSort)
148 ->addSortOrder($createdAtSort)
153 $this->entityStorage->addByIdentifyingFields(
$entity, $identityFieldsForCache, $cacheStorage);
169 $identityFieldsForCache = [$transactionId, $paymentId, $orderId];
170 $cacheStorage =
'txn_id';
171 $entity = $this->entityStorage->getByIdentifyingFields($identityFieldsForCache, $cacheStorage);
173 $entity = $this->metaData->getNewInstance();
174 $this->metaData->getMapper()->loadObjectByTxnId(
181 $this->entityStorage->addByIdentifyingFields(
$entity, $identityFieldsForCache, $cacheStorage);
195 $collection = $this->searchResultFactory->create();
199 $collection->addOrderInformation([
'increment_id']);
208 $this->metaData->getMapper()->delete(
$entity);
209 $this->entityStorage->remove(
$entity->getTransactionId());
218 $this->metaData->getMapper()->save(
$entity);
219 $this->entityStorage->add(
$entity);
220 return $this->entityStorage->get(
$entity->getTransactionId());
230 return $this->metaData->getNewInstance();
239 private function getCollectionProcessor()
241 if (!$this->collectionProcessor) {
246 return $this->collectionProcessor;
save(\Magento\Sales\Api\Data\TransactionInterface $entity)
getByTransactionType($transactionType, $paymentId)
getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
getByTransactionId($transactionId, $paymentId, $orderId)
__construct(SearchResultFactory $searchResultFactory, FilterBuilder $filterBuilder, SearchCriteriaBuilder $searchCriteriaBuilder, SortOrderBuilder $sortOrderBuilder, Metadata $metaData, EntityStorageFactory $entityStorageFactory, CollectionProcessorInterface $collectionProcessor=null)