PluginProbe
Packeta / 2.1
Packeta v2.1
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/Repository.php +25 -54 1.6.12.1 View file →
@@ -33,8 +33,9 @@
33 33 'country',
34 34 'currency',
35 35 'max_weight',
36 36 'deleted',
37 + 'available',
37 38 ];
38 39
39 40 /**
40 41 * WpdbAdapter object from global
@@ -43,26 +44,16 @@
43 44 */
44 45 private $wpdbAdapter;
45 46
46 47 /**
47 - * Internal pickup points config.
48 - *
49 - * @var PacketaPickupPointsConfig
50 - */
51 - private $pickupPointsConfig;
52 -
53 - /**
54 48 * Repository constructor.
55 49 *
56 - * @param WpdbAdapter $wpdbAdapter WpdbAdapter.
57 - * @param PacketaPickupPointsConfig $pickupPointsConfig Internal pickup points config.
50 + * @param WpdbAdapter $wpdbAdapter WpdbAdapter.
58 51 */
59 52 public function __construct(
60 - WpdbAdapter $wpdbAdapter,
61 - PacketaPickupPointsConfig $pickupPointsConfig
53 + WpdbAdapter $wpdbAdapter
62 54 ) {
63 - $this->wpdbAdapter = $wpdbAdapter;
64 - $this->pickupPointsConfig = $pickupPointsConfig;
55 + $this->wpdbAdapter = $wpdbAdapter;
65 56 }
66 57
67 58 /**
68 59 * Create table to store carriers.
@@ -69,9 +60,9 @@
69 60 *
70 61 * @return bool
71 62 */
72 63 public function createOrAlterTable(): bool {
73 - $createTableQuery = 'CREATE TABLE ' . $this->wpdbAdapter->packetery_carrier . ' (
64 + $createTableQuery = 'CREATE TABLE ' . $this->wpdbAdapter->packeteryCarrier . ' (
74 65 `id` int(11) NOT NULL,
75 66 `name` varchar(255) NOT NULL,
76 67 `is_pickup_points` tinyint(1) NOT NULL,
77 68 `has_carrier_direct_label` tinyint(1) NOT NULL,
@@ -83,23 +74,17 @@
83 74 `disallows_cod` tinyint(1) NOT NULL,
84 75 `country` varchar(255) NOT NULL,
85 76 `currency` varchar(255) NOT NULL,
86 77 `max_weight` float NOT NULL,
78 + `available` tinyint(1) NOT NULL DEFAULT 1,
87 79 `deleted` tinyint(1) NOT NULL,
88 80 PRIMARY KEY (`id`)
89 81 ) ' . $this->wpdbAdapter->get_charset_collate();
90 82
91 - return $this->wpdbAdapter->dbDelta( $createTableQuery, $this->wpdbAdapter->packetery_carrier );
83 + return $this->wpdbAdapter->dbDelta( $createTableQuery, $this->wpdbAdapter->packeteryCarrier );
92 84 }
93 85
94 86 /**
95 - * Drop table used to store carriers.
96 - */
97 - public function drop(): void {
98 - $this->wpdbAdapter->query( 'DROP TABLE IF EXISTS `' . $this->wpdbAdapter->packetery_carrier . '`' );
99 - }
100 -
101 - /**
102 87 * Gets is_pickup_point attribute of a carrier.
103 88 *
104 89 * @param int $carrierId Carrier id.
105 90 *
@@ -106,9 +91,9 @@
106 91 * @return bool
107 92 */
108 93 public function hasPickupPoints( int $carrierId ): bool {
109 94 return (bool) $this->wpdbAdapter->get_var(
110 - $this->wpdbAdapter->prepare( 'SELECT `is_pickup_points` FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `id` = %d', $carrierId )
95 + $this->wpdbAdapter->prepare( 'SELECT `is_pickup_points` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `id` = %d', $carrierId )
111 96 );
112 97 }
113 98
114 99 /**
@@ -115,15 +100,15 @@
115 100 * Gets Carrier value object by id.
116 101 *
117 102 * @param int $carrierId Carrier id.
118 103 *
119 - * @return array|null
104 + * @return array<string, string>|null
120 105 */
121 106 public function getById( int $carrierId ): ?array {
122 107 return $this->wpdbAdapter->get_row(
123 108 $this->wpdbAdapter->prepare(
124 109 'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
125 - FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `id` = %s',
110 + FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `id` = %s',
126 111 $carrierId
127 112 ),
128 113 ARRAY_A
129 114 );
@@ -132,16 +117,18 @@
132 117 /**
133 118 * Gets all active carriers for a country.
134 119 *
135 120 * @param string $country ISO code.
121 + * @param bool $includeUnavailable Include unavailable carriers.
136 122 *
137 123 * @return array|null
138 124 */
139 - public function getByCountry( string $country ): ?array {
125 + public function getByCountry( string $country, bool $includeUnavailable ): ?array {
140 126 return $this->wpdbAdapter->get_results(
141 127 $this->wpdbAdapter->prepare(
142 128 'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
143 - FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `country` = %s AND `deleted` = false',
129 + FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `country` = %s AND `deleted` = false' .
130 + ( $includeUnavailable ? '' : ' AND `available` = true' ),
144 131 $country
145 132 ),
146 133 ARRAY_A
147 134 );
@@ -154,9 +141,9 @@
154 141 */
155 142 public function getActiveCarriers(): ?array {
156 143 return $this->wpdbAdapter->get_results(
157 144 'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
158 - FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false',
145 + FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false AND `available` = true',
159 146 ARRAY_A
160 147 );
161 148 }
162 149
@@ -162,14 +149,14 @@
162 149
163 150 /**
164 151 * Gets all carriers.
165 152 *
166 - * @return array[]
153 + * @return array<int, array<string, string|float|bool>>
167 154 */
168 155 public function getAllRawIndexed(): array {
169 156 $unIndexedResult = $this->wpdbAdapter->get_results(
170 157 'SELECT `' . implode( '`, `', self::COLUMN_NAMES ) . '`
171 - FROM `' . $this->wpdbAdapter->packetery_carrier . '`',
158 + FROM `' . $this->wpdbAdapter->packeteryCarrier . '`',
172 159 ARRAY_A
173 160 );
174 161
175 162 return array_combine( array_column( $unIndexedResult, 'id' ), $unIndexedResult );
@@ -180,9 +167,9 @@
180 167 *
181 168 * @return bool
182 169 */
183 170 public function hasAnyActiveFeedCarrier(): bool {
184 - return (bool) $this->wpdbAdapter->get_var( 'SELECT 1 FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false LIMIT 1' );
171 + return (bool) $this->wpdbAdapter->get_var( 'SELECT 1 FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false AND `available` = true LIMIT 1' );
185 172 }
186 173
187 174 /**
188 175 * Gets all active countries.
@@ -188,10 +175,10 @@
188 175 * Gets all active countries.
189 176 *
190 177 * @return array
191 178 */
192 - public function getCountries(): array {
193 - return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packetery_carrier . '` WHERE `deleted` = false GROUP BY `country` ORDER BY `country`' );
179 + public function getCountriesWithUnavailable(): array {
180 + return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false GROUP BY `country` ORDER BY `country`' );
194 181 }
195 182
196 183 /**
197 184 * Set carriers specified by ids as deleted.
@@ -199,9 +186,9 @@
199 186 * @param array $carrierIdsNotInFeed Carriers not in feed.
200 187 */
201 188 public function set_as_deleted( array $carrierIdsNotInFeed ): void {
202 189 $this->wpdbAdapter->query(
203 - 'UPDATE `' . $this->wpdbAdapter->packetery_carrier . '`
190 + 'UPDATE `' . $this->wpdbAdapter->packeteryCarrier . '`
204 191 SET `deleted` = 1 WHERE `id` IN (' . implode( ',', $carrierIdsNotInFeed ) . ')'
205 192 );
206 193 }
207 194
@@ -210,9 +197,9 @@
210 197 *
211 198 * @param array $data Carrier data.
212 199 */
213 200 public function insert( array $data ): void {
214 - $this->wpdbAdapter->insert( $this->wpdbAdapter->packetery_carrier, $data );
201 + $this->wpdbAdapter->insert( $this->wpdbAdapter->packeteryCarrier, $data );
215 202 }
216 203
217 204 /**
218 205 * Updates carrier data in db.
@@ -217,26 +204,10 @@
217 204 /**
218 205 * Updates carrier data in db.
219 206 *
220 207 * @param array $data Carrier data.
221 - * @param int $carrier_id Carrier id.
208 + * @param int $carrierId Carrier id.
222 209 */
223 - public function update( array $data, int $carrier_id ): void {
224 - $this->wpdbAdapter->update( $this->wpdbAdapter->packetery_carrier, $data, [ 'id' => $carrier_id ] );
210 + public function update( array $data, int $carrierId ): void {
211 + $this->wpdbAdapter->update( $this->wpdbAdapter->packeteryCarrier, $data, [ 'id' => $carrierId ] );
225 212 }
226 -
227 - /**
228 - * Checks if carrier is home delivery carrier.
229 - *
230 - * @param string $carrierId Carrier ID.
231 - *
232 - * @return bool
233 - */
234 - public function isHomeDeliveryCarrier( string $carrierId ): bool {
235 - if ( $this->pickupPointsConfig->isInternalPickupPointCarrier( $carrierId ) ) {
236 - return false;
237 - }
238 -
239 - return false === $this->hasPickupPoints( (int) $carrierId );
240 - }
241 -
242 213 }