Changeset 3320352
- Timestamp:
- 07/01/2025 07:22:20 AM (9 months ago)
- Location:
- cdekdelivery/trunk
- Files:
-
- 5 edited
-
README.md (modified) (1 diff)
-
lang/cdekdelivery.pot (modified) (1 diff)
-
src/Helpers/CheckoutHelper.php (modified) (4 diffs)
-
src/Loader.php (modified) (1 diff)
-
src/Validator/CheckoutValidator.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cdekdelivery/trunk/README.md
r3305668 r3320352 74 74 * WP-203 Fixed vat calculation for waybills 75 75 * WP-211 Fixed error with shipment creation on new checkout due to missing office 76 * WP-214 Fixed critical error on plugin activation and checkout 76 77 77 78 = 4.1 = -
cdekdelivery/trunk/lang/cdekdelivery.pot
r3305668 r3320352 10 10 "X-Generator: GlotPress/4.0.1\n" 11 11 "Language: ru\n" 12 "Project-Id-Version: CDEKDelivery 4.2.3"12 "Project-Id-Version: CDEKDelivery main#ccdf9004" 13 13 14 14 #: build/cdek-order-item.js:1 -
cdekdelivery/trunk/src/Helpers/CheckoutHelper.php
r3301921 r3320352 28 28 29 29 /** @noinspection GlobalVariableUsageInspection */ 30 31 public static function passOfficeToCartPackages(array $packages): array 32 { 33 return array_map( 34 static function (array $package) { 35 $office = CheckoutHelper::getCurrentValue('office_code'); 36 37 if (!empty($office)) { 38 $package['destination'][MetaKeys::OFFICE_CODE] = $office; 39 } 40 41 return $package; 42 }, 43 $packages, 44 ); 45 } 46 30 47 public static function getCurrentValue(string $valueName, string $defaultValue = null): ?string 31 48 { 32 49 try { 33 $cdekValue = WC()->session->get(Config::DELIVERY_NAME ."_$valueName");50 $cdekValue = WC()->session->get(Config::DELIVERY_NAME . "_$valueName"); 34 51 if (!empty($cdekValue)) { 35 52 return $cdekValue; … … 60 77 61 78 try { 62 $cdekValue = WC()->customer->get_meta(Config::DELIVERY_NAME ."_$valueName");79 $cdekValue = WC()->customer->get_meta(Config::DELIVERY_NAME . "_$valueName"); 63 80 64 81 if (!empty($cdekValue)) { … … 70 87 71 88 return $checkout->get_value($valueName) ?: $defaultValue; 72 }73 74 public static function passOfficeToCartPackages(array $packages): array {75 return array_map(76 static function (array $package) {77 $office = CheckoutHelper::getCurrentValue('office_code');78 79 if (!empty($office)) {80 $package['destination'][MetaKeys::OFFICE_CODE] = $office;81 }82 83 return $package;84 },85 $packages,86 );87 }88 89 public static function getSelectedShippingRate(?WC_Cart $cart = null): ?WC_Shipping_Rate90 {91 if (is_null($cart)) {92 $cart = WC()->cart;93 }94 95 if (is_null($cart)) {96 return null;97 }98 99 $methods = $cart->get_shipping_methods();100 101 if (empty($methods)) {102 $methods = $cart->calculate_shipping();103 }104 105 if (is_null($methods)){106 return null;107 }108 109 foreach ($methods as $method) {110 assert($method instanceof WC_Shipping_Rate);111 if (self::isShippingRateSuitable($method)) {112 return $method;113 }114 }115 116 return null;117 }118 119 public static function isShippingRateSuitable(WC_Shipping_Rate $rate): bool120 {121 return $rate->get_method_id() === Config::DELIVERY_NAME;122 89 } 123 90 … … 153 120 return $fields; 154 121 } 122 123 public static function getSelectedShippingRate(?WC_Cart $cart = null): ?WC_Shipping_Rate 124 { 125 if (is_null($cart)) { 126 $cart = WC()->cart; 127 } 128 129 if (is_null($cart)) { 130 return null; 131 } 132 133 if (method_exists($cart, 'get_shipping_methods')) { 134 $methods = $cart->get_shipping_methods(); 135 } else { 136 $methods = []; 137 } 138 139 if (empty($methods)) { 140 $methods = $cart->calculate_shipping(); 141 } 142 143 if (is_null($methods)) { 144 return null; 145 } 146 147 foreach ($methods as $method) { 148 assert($method instanceof WC_Shipping_Rate); 149 if (self::isShippingRateSuitable($method)) { 150 return $method; 151 } 152 } 153 154 return null; 155 } 156 157 public static function isShippingRateSuitable(WC_Shipping_Rate $rate): bool 158 { 159 return $rate->get_method_id() === Config::DELIVERY_NAME; 160 } 155 161 } 156 162 } -
cdekdelivery/trunk/src/Loader.php
r3301921 r3320352 239 239 240 240 add_action('woocommerce_checkout_process', new CheckoutValidator); 241 add_action('woocommerce_store_api_checkout_update_order_meta', new CheckoutValidator );241 add_action('woocommerce_store_api_checkout_update_order_meta', new CheckoutValidator(false)); 242 242 add_action('woocommerce_order_before_calculate_totals', new RecalculateShippingAction, 10, 2); 243 243 -
cdekdelivery/trunk/src/Validator/CheckoutValidator.php
r3305668 r3320352 22 22 class CheckoutValidator 23 23 { 24 private bool $checkOffice; 25 public function __construct(bool $checkOffice = true) 26 { 27 $this->checkOffice = $checkOffice; 28 } 24 29 25 30 public function __invoke(): void … … 34 39 35 40 if ( in_array((int)$meta[MetaKeys::TARIFF_MODE], Tariff::listOfficeDeliveryModes(), true) ) { 36 if ( empty($meta[MetaKeys::OFFICE_CODE]) && empty($request['extensions'][Config::DELIVERY_NAME]['office_code'])) {41 if ( empty($meta[MetaKeys::OFFICE_CODE]) && $this->checkOffice ) { 37 42 wc_add_notice(esc_html__('Order pickup point not selected.', 'cdekdelivery'), 'error'); 38 43 }
Note: See TracChangeset
for help on using the changeset viewer.