PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Carrier/EntityRepository.php +10 -30 trunk2.0.9 View file →
@@ -9,9 +9,8 @@
9 9
10 10 namespace Packetery\Module\Carrier;
11 11
12 12 use Packetery\Core\Entity;
13 -use Packetery\Core\Entity\Carrier;
14 13 use Packetery\Module\EntityFactory;
15 14
16 15 /**
17 16 * Class EntityRepository
@@ -20,13 +19,8 @@
20 19 */
21 20 class EntityRepository {
22 21
23 22 /**
24 - * @var array<int, Entity\Carrier|null>
25 - */
26 - private static $carrierDataCache = [];
27 -
28 - /**
29 23 * Carrier repository.
30 24 *
31 25 * @var Repository
32 26 */
@@ -87,9 +81,9 @@
87 81 * @param int $carrierId Carrier id.
88 82 *
89 83 * @return Entity\Carrier|null
90 84 */
91 - private function getById( int $carrierId ): ?Entity\Carrier {
85 + public function getById( int $carrierId ): ?Entity\Carrier {
92 86 $result = $this->repository->getById( $carrierId );
93 87 if ( $result === null ) {
94 88 return null;
95 89 }
@@ -96,25 +90,16 @@
96 90
97 91 return $this->carrierEntityFactory->fromDbResult( $result );
98 92 }
99 93
100 - private function getByIdCached( int $carrierId ): ?Entity\Carrier {
101 - if ( ! isset( self::$carrierDataCache[ $carrierId ] ) ) {
102 - self::$carrierDataCache[ $carrierId ] = $this->getById( $carrierId );
103 - }
104 -
105 - return self::$carrierDataCache[ $carrierId ];
106 - }
107 -
108 94 /**
109 95 * Gets feed carrier or Packeta carrier by id.
110 96 *
111 97 * @param string $carrierId Extended branch service id.
112 - * @param bool $useCache
113 98 *
114 99 * @return Entity\Carrier|null
115 100 */
116 - public function getAnyById( string $carrierId, bool $useCache = false ): ?Entity\Carrier {
101 + public function getAnyById( string $carrierId ): ?Entity\Carrier {
117 102 $nonFeedCarriers = $this->pickupPointsConfig->getCompoundAndVendorCarriers();
118 103
119 104 foreach ( $nonFeedCarriers as $nonFeedCarrier ) {
120 105 if ( $nonFeedCarrier->getId() === $carrierId ) {
@@ -125,12 +110,8 @@
125 110 if ( ! is_numeric( $carrierId ) ) {
126 111 return null;
127 112 }
128 113
129 - if ( $useCache === true ) {
130 - return $this->getByIdCached( (int) $carrierId );
131 - }
132 -
133 114 return $this->getById( (int) $carrierId );
134 115 }
135 116
136 117 /**
@@ -139,11 +120,11 @@
139 120 * @param string $country ISO code.
140 121 *
141 122 * @return Entity\Carrier[]
142 123 */
143 - public function getByCountry( string $country, bool $includeUnavailable ): array {
124 + public function getByCountry( string $country ): array {
144 125 $entities = [];
145 - $countryCarriers = $this->repository->getByCountry( $country, $includeUnavailable );
126 + $countryCarriers = $this->repository->getByCountry( $country );
146 127
147 128 foreach ( $countryCarriers as $carrierData ) {
148 129 $entities[] = $this->carrierEntityFactory->fromDbResult( $carrierData );
149 130 }
@@ -170,19 +151,18 @@
170 151 /**
171 152 * Gets all active carriers for a country including internal pickup point carriers.
172 153 *
173 154 * @param string $country ISO code.
174 - * @param bool $includeUnavailable Include unavailable carriers.
175 155 *
176 - * @return Carrier[]
156 + * @return Entity\Carrier[]
177 157 */
178 - public function getByCountryIncludingNonFeed( string $country, bool $includeUnavailable ): array {
158 + public function getByCountryIncludingNonFeed( string $country ): array {
179 159 $nonFeedCarriers = [];
180 160 $nonFeedCarriersArrays = $this->pickupPointsConfig->getNonFeedCarriersByCountry( $country );
181 161 foreach ( $nonFeedCarriersArrays as $nonFeedCarrierData ) {
182 162 $nonFeedCarriers[] = $this->carrierEntityFactory->fromNonFeedCarrierData( $nonFeedCarrierData );
183 163 }
184 - $feedCarriers = $this->getByCountry( $country, $includeUnavailable );
164 + $feedCarriers = $this->getByCountry( $country );
185 165
186 166 return array_merge( $nonFeedCarriers, $feedCarriers );
187 167 }
188 168
@@ -223,9 +203,9 @@
223 203 $activeCarriers = [];
224 204 $carriers = $this->getAllCarriersIncludingNonFeed();
225 205 foreach ( $carriers as $carrier ) {
226 206 $carrierOptions = $this->carrierOptionsFactory->createByCarrierId( $carrier->getId() );
227 - if ( $carrierOptions->isActive() ) {
207 + if ( $this->carrierActivityBridge->isActive( $carrier->getId(), $carrierOptions ) ) {
228 208 $activeCarriers[] = [
229 209 'option_id' => $carrierOptions->getOptionId(),
230 210 'label' => $carrierOptions->getName(),
231 211 ];
@@ -251,15 +231,15 @@
251 231 return ( isset( $compoundCarriers[ $customerCountry ] ) );
252 232 }
253 233
254 234 $carrier = $this->getById( (int) $carrierId );
255 - if ( $carrier === null || $carrier->isDeleted() || ! $carrier->isAvailable() || $customerCountry !== $carrier->getCountry() ) {
235 + if ( $carrier === null || $carrier->isDeleted() || $customerCountry !== $carrier->getCountry() ) {
256 236 return false;
257 237 }
258 238
259 239 $carrierOptions = $this->carrierOptionsFactory->createByCarrierId( $carrier->getId() );
260 240
261 - return $this->carrierActivityBridge->isActive( $carrier, $carrierOptions );
241 + return $this->carrierActivityBridge->isActive( $carrier->getId(), $carrierOptions );
262 242 }
263 243
264 244 /**
265 245 * Checks if carrier is home delivery carrier.