Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TrackRepository.php
Go to the documentation of this file.
1 <?php
7 
13 use Magento\Sales\Api\Data\ShipmentTrackInterfaceFactory;
14 use Magento\Sales\Api\Data\ShipmentTrackSearchResultInterfaceFactory;
17 
19 {
23  private $trackResource;
24 
28  private $trackFactory;
29 
33  private $searchResultFactory;
34 
38  private $collectionProcessor;
39 
46  public function __construct(
47  ShipmentTrackResourceInterface $trackResource,
48  ShipmentTrackInterfaceFactory $trackFactory,
49  ShipmentTrackSearchResultInterfaceFactory $searchResultFactory,
50  CollectionProcessorInterface $collectionProcessor
51  ) {
52 
53  $this->trackResource = $trackResource;
54  $this->trackFactory = $trackFactory;
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->trackFactory->create();
76  $this->trackResource->load($entity, $id);
77  return $entity;
78  }
79 
83  public function delete(ShipmentTrackInterface $entity)
84  {
85  try {
86  $this->trackResource->delete($entity);
87  } catch (\Exception $e) {
88  throw new CouldNotDeleteException(__('Could not delete the shipment tracking.'), $e);
89  }
90  return true;
91  }
92 
97  {
98  try {
99  $this->trackResource->save($entity);
100  } catch (\Exception $e) {
101  throw new CouldNotSaveException(__('Could not save the shipment tracking.'), $e);
102  }
103  return $entity;
104  }
105 
109  public function deleteById($id)
110  {
111  $entity = $this->get($id);
112  return $this->delete($entity);
113  }
114 }
getList(SearchCriteriaInterface $searchCriteria)
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13
$searchCriteria
__construct(ShipmentTrackResourceInterface $trackResource, ShipmentTrackInterfaceFactory $trackFactory, ShipmentTrackSearchResultInterfaceFactory $searchResultFactory, CollectionProcessorInterface $collectionProcessor)
$entity
Definition: element.phtml:22