Plugin Directory

Changeset 2471669


Ignore:
Timestamp:
02/09/2021 02:09:31 PM (5 years ago)
Author:
csewp
Message:

Исправлена ошибка расчета стоимости в зависимости от массы груза

Location:
cse-delivery/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cse-delivery/trunk/README.txt

    r2446694 r2471669  
    4646= 1.0.1 =
    4747* Исправление ошибок
     48= 1.0.2 =
     49* Конвертация величин при расчете стоимости
  • cse-delivery/trunk/cse-delivery.php

    r2446694 r2471669  
    33/**
    44 * @link              https://cse.ru
    5  * @since             1.0.1
     5 * @since             1.0.2
    66 * @package           CSEDelivery
    77 *
     
    1010 * Plugin URI:        www.cse.ru
    1111 * Description:       Модуль интеграции со службой доставки Курьер Сервис Экспресс: расчет стоимости доставки, формирование накладных и заказов на доставку, отслеживание грузов и получение статистики
    12  * Version:           1.0.1
     12 * Version:           1.0.2
    1313 * Author:            CSE
    1414 * Author URI:        https://cse.ru
  • cse-delivery/trunk/includes/WCShippingCSE.php

    r2446694 r2471669  
    1919     */
    2020    public function __construct( $instance_id = 0 ) {
     21
     22        parent::__construct($instance_id);
     23
    2124        $this->id                 = 'cse';
    22         $this->instance_id        = absint( $instance_id );
    2325        $this->method_title       = "Доставка КСЕ";
    2426        $this->title              = "Доставка КСЕ";
     
    5860
    5961            foreach ( $package['contents'] as $content ) {
     62
     63                $convertRate = $this->getConvertRate();
     64
    6065                /** @var $product WC_Product */
    6166                $product       = $content['data'];
    62                 $productWeight = ! empty( $product->get_weight() ) ? $product->get_weight() : $this->options['wc_cse_weight'] ?? 0;
     67                $productWeight = ! empty( $product->get_weight() ) ? ($product->get_weight() * $convertRate['weight']) : $this->options['wc_cse_weight'] ?? 0;
    6368                $quantity      = $content["quantity"];
    6469
    65                 $width  = ! empty( $product->get_width() ) ? $product->get_width() : 0;
    66                 $height = ! empty( $product->get_height() ) ? $product->get_height() : 0;
    67                 $length = ! empty( $product->get_length() ) ? $product->get_length() : 0;
     70                $width  = ! empty( $product->get_width() ) ? ($product->get_width() * $convertRate['length']): 0;
     71                $height = ! empty( $product->get_height() ) ? ($product->get_height() * $convertRate['length']) : 0;
     72                $length = ! empty( $product->get_length() ) ? ($product->get_length() * $convertRate['length']) : 0;
    6873
    6974                $volumeWeight  = round( ( ( floatval( $width ) * floatval( $height ) * floatval( $length ) ) / 5000 ) * $quantity, 2 );
     
    137142        return $result < 0 ? 0 : $result;
    138143    }
     144
     145    private function getConvertRate() {
     146
     147        $weightUnit    = get_option( 'woocommerce_weight_unit' );
     148        $dimensionUnit = get_option( 'woocommerce_dimension_unit' );
     149
     150        switch ( $weightUnit ) {
     151            case 'g':
     152                $weightRate = 0.001;
     153                break;
     154            default:
     155                $weightRate = 1;
     156        }
     157
     158        switch ( $dimensionUnit ) {
     159            case 'm':
     160                $dimensionRate = 100;
     161                break;
     162            default:
     163                $dimensionRate = 1;
     164        }
     165
     166        return [
     167            'length'  => $dimensionRate,
     168            'weight' => $weightRate,
     169        ];
     170    }
    139171}
Note: See TracChangeset for help on using the changeset viewer.