Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HistoryRepository.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\Sales\Api\Data\OrderStatusHistoryInterfaceFactory;
14 use Magento\Sales\Api\Data\OrderStatusHistorySearchResultInterfaceFactory;
17 
19 {
23  private $historyResource;
24 
28  private $historyFactory;
29 
33  private $searchResultFactory;
34 
38  private $collectionProcessor;
39 
46  public function __construct(
47  OrderStatusHistoryResourceInterface $historyResource,
48  OrderStatusHistoryInterfaceFactory $historyFactory,
49  OrderStatusHistorySearchResultInterfaceFactory $searchResultFactory,
50  CollectionProcessorInterface $collectionProcessor
51  ) {
52 
53  $this->historyResource = $historyResource;
54  $this->historyFactory = $historyFactory;
55  $this->searchResultFactory = $searchResultFactory;
56  $this->collectionProcessor = $collectionProcessor;
57  }
58 
63  {
64  $searchResult = $this->searchResultFactory->create();
65  $this->collectionProcessor->process($searchCriteria, $searchResult);
66  $searchResult->setSearchCriteria($searchCriteria);
67  return $searchResult;
68  }
69 
73  public function get($id)
74  {
75  $entity = $this->historyFactory->create();
76  $this->historyResource->load($entity, $id);
77  return $entity;
78  }
79 
83  public function delete(OrderStatusHistoryInterface $entity)
84  {
85  try {
86  $this->historyResource->delete($entity);
87  } catch (\Exception $e) {
88  throw new CouldNotDeleteException(__('Could not delete the order status history.'), $e);
89  }
90  return true;
91  }
92 
97  {
98  try {
99  $this->historyResource->save($entity);
100  } catch (\Exception $e) {
101  throw new CouldNotSaveException(__('Could not save the order status history.'), $e);
102  }
103  return $entity;
104  }
105 }
getList(SearchCriteriaInterface $searchCriteria)
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
$searchCriteria
__construct(OrderStatusHistoryResourceInterface $historyResource, OrderStatusHistoryInterfaceFactory $historyFactory, OrderStatusHistorySearchResultInterfaceFactory $searchResultFactory, CollectionProcessorInterface $collectionProcessor)
$entity
Definition: element.phtml:22
save(OrderStatusHistoryInterface $entity)