Plugin Directory

Changeset 3320352


Ignore:
Timestamp:
07/01/2025 07:22:20 AM (9 months ago)
Author:
caelan
Message:

feat: 4.2.4-rc.1

Location:
cdekdelivery/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cdekdelivery/trunk/README.md

    r3305668 r3320352  
    7474* WP-203 Fixed vat calculation for waybills
    7575* 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
    7677
    7778= 4.1 =
  • cdekdelivery/trunk/lang/cdekdelivery.pot

    r3305668 r3320352  
    1010"X-Generator: GlotPress/4.0.1\n"
    1111"Language: ru\n"
    12 "Project-Id-Version: CDEKDelivery 4.2.3"
     12"Project-Id-Version: CDEKDelivery main#ccdf9004"
    1313
    1414#: build/cdek-order-item.js:1
  • cdekdelivery/trunk/src/Helpers/CheckoutHelper.php

    r3301921 r3320352  
    2828
    2929        /** @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
    3047        public static function getCurrentValue(string $valueName, string $defaultValue = null): ?string
    3148        {
    3249            try {
    33                 $cdekValue = WC()->session->get(Config::DELIVERY_NAME."_$valueName");
     50                $cdekValue = WC()->session->get(Config::DELIVERY_NAME . "_$valueName");
    3451                if (!empty($cdekValue)) {
    3552                    return $cdekValue;
     
    6077
    6178            try {
    62                 $cdekValue = WC()->customer->get_meta(Config::DELIVERY_NAME."_$valueName");
     79                $cdekValue = WC()->customer->get_meta(Config::DELIVERY_NAME . "_$valueName");
    6380
    6481                if (!empty($cdekValue)) {
     
    7087
    7188            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_Rate
    90         {
    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): bool
    120         {
    121             return $rate->get_method_id() === Config::DELIVERY_NAME;
    12289        }
    12390
     
    153120            return $fields;
    154121        }
     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        }
    155161    }
    156162}
  • cdekdelivery/trunk/src/Loader.php

    r3301921 r3320352  
    239239
    240240            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));
    242242            add_action('woocommerce_order_before_calculate_totals', new RecalculateShippingAction, 10, 2);
    243243
  • cdekdelivery/trunk/src/Validator/CheckoutValidator.php

    r3305668 r3320352  
    2222    class CheckoutValidator
    2323    {
     24        private bool $checkOffice;
     25        public function __construct(bool $checkOffice = true)
     26        {
     27            $this->checkOffice = $checkOffice;
     28        }
    2429
    2530        public function __invoke(): void
     
    3439
    3540            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 ) {
    3742                    wc_add_notice(esc_html__('Order pickup point not selected.', 'cdekdelivery'), 'error');
    3843                }
Note: See TracChangeset for help on using the changeset viewer.