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/Shipping/ShippingProvider.php +29 -29 2.3.22.0.9 View file →
@@ -7,20 +7,28 @@
7 7 use Packetery\Core\Entity\Carrier;
8 8 use Packetery\Module\Carrier\CarDeliveryConfig;
9 9 use Packetery\Module\Carrier\CarrierOptionsFactory;
10 10 use Packetery\Module\Carrier\EntityRepository;
11 +use Packetery\Module\Carrier\PacketaPickupPointsConfig;
11 12 use Packetery\Module\ContextResolver;
13 +use Packetery\Module\Options\FlagManager\FeatureFlagProvider;
12 14 use Packetery\Module\ShippingMethod;
13 15 use Packetery\Module\ShippingZoneRepository;
14 -use WC_Abstract_Order;
16 +use WC_Order;
15 17
16 18 class ShippingProvider {
19 +
17 20 /**
18 - * @var array<int, array<string, string>>
21 + * @var FeatureFlagProvider
19 22 */
20 - private static $sortedMethodsCache = [];
23 + private $featureFlagProvider;
21 24
22 25 /**
26 + * @var PacketaPickupPointsConfig
27 + */
28 + private $pickupPointConfig;
29 +
30 + /**
23 31 * @var CarDeliveryConfig
24 32 */
25 33 private $carDeliveryConfig;
26 34
@@ -44,8 +52,10 @@
44 52 */
45 53 private $carrierOptionsFactory;
46 54
47 55 public function __construct(
56 + FeatureFlagProvider $featureFlagProvider,
57 + PacketaPickupPointsConfig $pickupPointConfig,
48 58 CarDeliveryConfig $carDeliveryConfig,
49 59 ContextResolver $contextResolver,
50 60 ShippingZoneRepository $shippingZoneRepository,
51 61 EntityRepository $carrierRepository,
@@ -50,8 +60,10 @@
50 60 ShippingZoneRepository $shippingZoneRepository,
51 61 EntityRepository $carrierRepository,
52 62 CarrierOptionsFactory $carrierOptionsFactory
53 63 ) {
64 + $this->featureFlagProvider = $featureFlagProvider;
65 + $this->pickupPointConfig = $pickupPointConfig;
54 66 $this->carDeliveryConfig = $carDeliveryConfig;
55 67 $this->contextResolver = $contextResolver;
56 68 $this->shippingZoneRepository = $shippingZoneRepository;
57 69 $this->carrierRepository = $carrierRepository;
@@ -85,8 +97,15 @@
85 97 if ( preg_match( '/^ShippingMethod_(' . $carDeliveryIds . ')\.php$/', $filename ) ) {
86 98 continue;
87 99 }
88 100 }
101 + if ( $this->featureFlagProvider->isSplitActive() === false ) {
102 + $internalCountries = implode( '|', $this->pickupPointConfig->getInternalCountries() );
103 + $vendorGroups = Carrier::VENDOR_GROUP_ZPOINT . '|' . Carrier::VENDOR_GROUP_ZBOX;
104 + if ( preg_match( '/^ShippingMethod_(' . $internalCountries . ')(' . $vendorGroups . ')\.php$/', $filename ) ) {
105 + continue;
106 + }
107 + }
89 108 require_once $generatedClassesPath . '/' . $filename;
90 109 }
91 110 }
92 111
@@ -103,9 +122,12 @@
103 122 }
104 123 );
105 124 }
106 125
107 - public static function wcOrderHasOurMethod( WC_Abstract_Order $wcOrder ): bool {
126 + /**
127 + * Checks if provided order uses our shipping method like native has_shipping_method method.
128 + */
129 + public static function wcOrderHasOurMethod( WC_Order $wcOrder ): bool {
108 130 foreach ( $wcOrder->get_shipping_methods() as $shippingMethod ) {
109 131 if ( self::isPacketaMethod( $shippingMethod->get_method_id() ) ) {
110 132 return true;
111 133 }
@@ -130,9 +152,9 @@
130 152 * @param array<string, string> $methods Previous state.
131 153 *
132 154 * @return array<string, string>
133 155 */
134 - private function addMethods( array $methods ): array {
156 + public function addMethods( array $methods ): array {
135 157 $zoneId = $this->contextResolver->getShippingZoneId();
136 158 if ( $zoneId === null ) {
137 159 return $this->addAllMethods( $methods );
138 160 }
@@ -142,9 +164,9 @@
142 164 return $this->addAllMethods( $methods );
143 165 }
144 166
145 167 foreach ( $allowedCountries as $countryCode ) {
146 - $carriers = $this->carrierRepository->getByCountryIncludingNonFeed( $countryCode, false );
168 + $carriers = $this->carrierRepository->getByCountryIncludingNonFeed( $countryCode );
147 169 foreach ( $carriers as $carrier ) {
148 170 foreach ( $this->getGeneratedClassnames() as $fullyQualifiedClassname ) {
149 171 if ( $carrier->getId() === $fullyQualifiedClassname::CARRIER_ID ) {
150 172 $methods = $this->addActiveCarrierMethod( $fullyQualifiedClassname, $methods );
@@ -202,9 +224,9 @@
202 224 * @param array<string, string> $methods Methods to sort.
203 225 *
204 226 * @return array<string, string>
205 227 */
206 - private function sortMethods( array $methods ): array {
228 + public function sortMethods( array $methods ): array {
207 229 uasort(
208 230 $methods,
209 231 function ( $classA, $classB ) {
210 232 $objectA = new $classA();
@@ -215,28 +237,6 @@
215 237 }
216 238 );
217 239
218 240 return $methods;
219 - }
220 -
221 - /**
222 - * @param array<string, string> $originalMethods
223 - *
224 - * @return array<string, string>
225 - */
226 - public function getSortedCachedMethods( array $originalMethods ): array {
227 - $areClassesLoaded = in_array( BaseShippingMethod::class, get_declared_classes(), true );
228 - if ( $areClassesLoaded === false ) {
229 - return $originalMethods;
230 - }
231 -
232 - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
233 - $cacheKey = crc32( serialize( $originalMethods ) );
234 -
235 - if ( ! isset( self::$sortedMethodsCache[ $cacheKey ] ) ) {
236 - $unsortedMethods = $this->addMethods( $originalMethods );
237 - self::$sortedMethodsCache[ $cacheKey ] = $this->sortMethods( $unsortedMethods );
238 - }
239 -
240 - return self::$sortedMethodsCache[ $cacheKey ];
241 241 }
242 242 }