Plugin Directory

Changeset 3264847


Ignore:
Timestamp:
04/01/2025 05:44:37 AM (12 months ago)
Author:
cdekit
Message:

v4.1.7-rc

Location:
cdekdelivery/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • cdekdelivery/trunk/README.md

    r3262145 r3264847  
    7676* WP-159 Fix error for paid on delivery with zero price
    7777* WP-156 Restore plugin settings on delivery zone page
    78 * WP-158 Fix missing delivery invoice information on order page
     78* WP-158 Fixed missing delivery invoice information on order page
     79* WP-173 Fixed save plugin settings with WP cache plugins
     80* WP-160 Product tax settings now set in delivery invoice
     81* WP-183 Fixed errors or warnings on admin pages
    7982
    8083= 4.0 =
  • cdekdelivery/trunk/lang/cdekdelivery.pot

    r3262118 r3264847  
    1010"X-Generator: GlotPress/4.0.1\n"
    1111"Language: ru\n"
    12 "Project-Id-Version: CDEKDelivery 4.1.6"
     12"Project-Id-Version: CDEKDelivery 4.1.7"
    1313
    1414#. translators: 1: attempt number
  • cdekdelivery/trunk/src/Actions/OrderCreateAction.php

    r3262118 r3264847  
    2929    use Cdek\Model\ShippingItem;
    3030    use Cdek\Model\Tariff;
     31    use Cdek\Model\Tax;
    3132    use Cdek\Model\ValidationResult;
    3233    use Cdek\Note;
     
    289290                             function_exists('wcml_get_woocommerce_currency_option') ? $this->order->currency : null;
    290291
    291             return array_map(function (array $p) use (&$shouldConvert, &$orderItems, &$shouldPay) {
     292            return array_map(function (array $p) use ($shouldConvert, $orderItems, $shouldPay) {
    292293                $weight = 0;
    293294
    294                 $items = array_values(array_filter(array_map(function ($item) use (
    295                     &$shouldConvert,
    296                     &$shouldPay,
    297                     &$orderItems,
    298                     &$weight
    299                 ) {
    300                     if ($item instanceof WC_Order_Item_Product) {
    301                         $qty = (int)$item->get_quantity();
    302                     } else {
    303                         $qty  = (int)$item['qty'];
    304                         $item = $orderItems[$item['id']] ?? null;
    305                     }
    306 
    307                     if ($item === null) {
    308                         return null;
    309                     }
    310 
    311                     assert($item instanceof WC_Order_Item_Product);
    312                     $product = $item->get_product();
    313 
    314                     $w      = WeightConverter::getWeightInGrams($product->get_weight());
    315                     $weight += $qty * $w;
    316                     $cost   = $shouldConvert === null ? (float)$item->get_total() : $this->convertCurrencyToRub(
    317                         (float)$item->get_total(),
    318                         $shouldConvert,
    319                     );
    320 
    321                     $cost /= $qty;
    322 
    323                     if ($shouldPay !== null) {
    324                         if ($shouldPay !== 0) {
    325                             $paymentValue = (int)(($shouldPay / 100) * $cost);
    326                         } else {
    327                             $paymentValue = $cost;
    328                         }
    329                     } else {
    330                         $paymentValue = 0;
    331                     }
    332 
    333                     return [
    334                         'ware_key'     => $product->get_sku() ?: $product->get_id(),
    335                         'payment'      => ['value' => $paymentValue],
    336                         'name'         => $item->get_name(),
    337                         'cost'         => $cost,
    338                         'amount'       => $qty,
    339                         'weight'       => $w,
    340                         'weight_gross' => $w + 1,
    341                     ];
    342                 }, $p['items'] ?: $orderItems)));
     295                $items = array_values(
     296                    array_filter(
     297                        array_map(
     298                            static function($item) use ($shouldConvert, $shouldPay, $orderItems, &$weight){
     299                                if ($item instanceof WC_Order_Item_Product) {
     300                                    $qty = (int)$item->get_quantity();
     301                                } else {
     302                                    $qty  = (int)$item['qty'];
     303                                    $item = $orderItems[$item['id']] ?? null;
     304                                }
     305
     306                                if ($item === null) {
     307                                    return null;
     308                                }
     309
     310                                assert($item instanceof WC_Order_Item_Product);
     311
     312                                return $this->buildItemData($item, $qty, $shouldConvert, $shouldPay, $weight);
     313                            },
     314                            $p['items'] ?: $orderItems
     315                        )
     316                    )
     317                );
    343318
    344319                $package = [
     
    359334        }
    360335
     336        private function buildItemData(
     337            WC_Order_Item_Product $item,
     338            int $qty,
     339            ?string $shouldConvert,
     340            ?int $shouldPay,
     341            int &$weight
     342        ): array
     343        {
     344            $product = $item->get_product();
     345
     346            $w      = WeightConverter::getWeightInGrams($product->get_weight());
     347            $weight += $qty * $w;
     348            $cost   = $shouldConvert === null ? (float)wc_get_price_including_tax($product) :
     349                $this->convertCurrencyToRub(
     350                    (float)wc_get_price_including_tax($product),
     351                    $shouldConvert,
     352                );
     353
     354            $payment = ['value' => 0];
     355
     356            if ($shouldPay !== null) {
     357                if ($shouldPay !== 0) {
     358                    $payment['value'] = (int)(($shouldPay / 100) * $cost);
     359
     360                    if($product->is_taxable()){
     361                        $taxCost = $shouldConvert === null ? (float)$item->get_total_tax() :
     362                            $this->convertCurrencyToRub(
     363                                (float)$item->get_total_tax(),
     364                                $shouldConvert,
     365                            );
     366
     367                        if($taxCost > 0){
     368                            $payment['vat_sum'] = (int)(($shouldPay / 100) * $taxCost);
     369                            $payment['vat_rate'] = Tax::getTax($product->get_tax_class());
     370                        }else{
     371                            $payment['vat_sum'] = 0;
     372                            $payment['vat_rate'] = 0;
     373                        }
     374                    }
     375                } else {
     376                    $payment['value'] = $cost;
     377                }
     378            }
     379
     380            return [
     381                'ware_key'     => $product->get_sku() ?: $product->get_id(),
     382                'payment'      => $payment,
     383                'name'         => $item->get_name(),
     384                'cost'         => $cost,
     385                'amount'       => $qty,
     386                'weight'       => $w,
     387                'weight_gross' => $w + 1,
     388            ];
     389        }
     390
    361391        private function convertCurrencyToRub(float $cost, string $currency): float
    362392        {
  • cdekdelivery/trunk/src/ShippingMethod.php

    r3213294 r3264847  
    120120        }
    121121
     122        final public function init_instance_settings(): void {
     123            parent::init_instance_settings();
     124
     125            if (doing_action("woocommerce_update_options_shipping_$this->id")){
     126                $this->instance_settings['token'] = null;
     127            }
     128        }
     129
     130        final public function init_settings(): void {
     131            parent::init_settings();
     132
     133            if (doing_action("woocommerce_update_options_shipping_$this->id")){
     134                $this->settings['token'] = null;
     135            }
     136        }
     137
    122138        /** @noinspection MissingReturnTypeInspection */
    123139        public function __get(string $key)
     
    216232            }
    217233        }
    218 
    219         final public function process_admin_options(): bool
    220         {
    221             FlushTokenCacheAction::new()();
    222 
    223             return parent::process_admin_options();
    224         }
    225234    }
    226235}
  • cdekdelivery/trunk/src/UI/Admin.php

    r3262118 r3264847  
    6565
    6666            if ($current_section !== Config::DELIVERY_NAME) {
     67                if (empty($_REQUEST['instance_id'])) {
     68                    return;
     69                }
     70
    6771                $shippingMethodCurrent = WC_Shipping_Zones::get_shipping_method(absint(wp_unslash($_REQUEST['instance_id'])));
    6872
  • cdekdelivery/trunk/vendor/composer/autoload_classmap.php

    r3234614 r3264847  
    7171    'Cdek\\Model\\Tariff' => $baseDir . '/src/Model/Tariff.php',
    7272    'Cdek\\Model\\TaskResult' => $baseDir . '/src/Model/TaskResult.php',
     73    'Cdek\\Model\\Tax' => $baseDir . '/src/Model/Tax.php',
    7374    'Cdek\\Model\\ValidationResult' => $baseDir . '/src/Model/ValidationResult.php',
    7475    'Cdek\\Note' => $baseDir . '/src/Note.php',
  • cdekdelivery/trunk/vendor/composer/autoload_static.php

    r3234614 r3264847  
    152152        'Cdek\\Model\\Tariff' => __DIR__ . '/../..' . '/src/Model/Tariff.php',
    153153        'Cdek\\Model\\TaskResult' => __DIR__ . '/../..' . '/src/Model/TaskResult.php',
     154        'Cdek\\Model\\Tax' => __DIR__ . '/../..' . '/src/Model/Tax.php',
    154155        'Cdek\\Model\\ValidationResult' => __DIR__ . '/../..' . '/src/Model/ValidationResult.php',
    155156        'Cdek\\Note' => __DIR__ . '/../..' . '/src/Note.php',
Note: See TracChangeset for help on using the changeset viewer.