Plugin Directory

Changeset 3268954


Ignore:
Timestamp:
04/08/2025 01:59:03 PM (12 months ago)
Author:
superfrete
Message:

Nova versão 2.1.0

Location:
superfrete
Files:
37 added
6 edited

Legend:

Unmodified
Added
Removed
  • superfrete/trunk/app/Controllers/ProductShipping.php

    r3266581 r3268954  
    132132            WC()->cart->calculate_totals();
    133133 
    134             $original_cart = false;
    135 
    136             if (WC()->cart->get_cart_contents_count() == 0) {
    137                 $item_key = self::addTestProductForProperShippingCost();
    138                 $packages = WC()->shipping()->get_packages();
    139              
    140             } else {
     134         
     135
     136   
    141137                    $original_cart = WC()->cart->get_cart();
    142138                    WC()->cart->empty_cart();
    143139                    $item_key = self::addTestProductForProperShippingCost();
     140
    144141                    WC()->shipping()->calculate_shipping();
    145142                    WC()->cart->calculate_totals();
    146143                    $packages = WC()->shipping()->get_packages();
     144                               
    147145   
    148146           
    149             }
     147           
    150148
    151149            $shipping_methods = self::getShippingMethods($packages);
  • superfrete/trunk/app/Shipping/SuperFreteMiniEnvio.php

    r3266581 r3268954  
    1010
    1111class SuperFreteMiniEnvios extends \WC_Shipping_Method {
    12  public $free_shipping;
     12    public $free_shipping;
     13    public $extra_days;
     14    public $extra_cost;
     15    public $extra_cost_type;
     16   
    1317 public function __construct( $instance_id = 'superfrete_mini_envio') {
    1418        $this->id                    = 'superfrete_mini_envio';
     
    3943                'label' => __('Ativar frete grátis para este método', 'superfrete'),
    4044         
     45            ),'extra_days' => array(
     46                'title' => __('Dias extras no prazo', 'superfrete'),
     47                'type' => 'number',
     48                'description' => __('Dias adicionais ao prazo estimado pela SuperFrete', 'superfrete'),
     49                'default' => 0,
     50                'desc_tip' => true
     51            ),
     52            'extra_cost' => array(
     53                'title' => __('Valor adicional no frete', 'superfrete'),
     54                'type' => 'price',
     55                'description' => __('Valor extra a ser somado ao custo do frete', 'superfrete'),
     56                'default' => '0',
     57                'desc_tip' => true
     58            ),
     59            'extra_cost_type' => array(
     60                'title' => __('Tipo de valor adicional', 'superfrete'),
     61                'type' => 'select',
     62                'description' => __('Escolha se o valor adicional será fixo (R$) ou percentual (%) sobre o frete original.', 'superfrete'),
     63                'default' => 'fixed',
     64                'options' => array(
     65                    'fixed' => __('Valor fixo (R$)', 'superfrete'),
     66                    'percent' => __('Porcentagem (%)', 'superfrete'),
     67                ),
    4168            ),
    4269        );
    43         $this->enabled              = $this->get_option( 'enabled' );
    44         $this->free_shipping                = $this->get_option( 'free_shipping' );
    45         $this->title                = $this->get_option( 'title' );
     70        $this->enabled = $this->get_option('enabled');
     71        $this->free_shipping = $this->get_option('free_shipping');
     72        $this->title = $this->get_option('title');
     73        $this->extra_days = $this->get_option('extra_days', 0);
     74        $this->extra_cost = $this->get_option('extra_cost', 0);
     75        $this->extra_cost_type = $this->get_option('extra_cost_type', 'fixed');
     76
    4677        add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
    4778    }
     
    112143        if (!empty($response)) {
    113144            foreach ($response as $frete) {
    114                
    115                 $text_dias = ($frete['delivery_time'] <= 1)? "dia útil" : "dias úteis";
    116                  if (!$frete['has_error'] && !isset($frete["error"]) ) {
    117                     $frete_custo = ($this->free_shipping === 'yes') ? "0" : floatval($frete['price']);
     145                $prazo_total = $frete['delivery_time'] + $this->extra_days;
     146                $text_dias = ($prazo_total <= 1) ? "dia útil" : "dias úteis";
     147
     148                if (!$frete['has_error'] && !isset($frete["error"])) {
     149                   $frete_custo = 0;
     150
     151if ($this->free_shipping !== 'yes') {
     152    $frete_base = floatval($frete['price']);
     153    if ($this->extra_cost_type === 'percent') {
     154        $frete_custo = $frete_base + ($frete_base * ($this->extra_cost / 100));
     155    } else {
     156        $frete_custo = $frete_base + $this->extra_cost;
     157    }
     158}
     159
    118160                    $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : "";
    119                  
     161
    120162                    $rate = [
    121163                        'id' => $this->id . '_' . $frete['id'],
    122                         'label' => $frete['name'] . ' - Promocional - (' . $frete['delivery_time'] . ' ' . $text_dias . ') '. $frete_desc,
     164                        'label' => $frete['name'] . ' - Promocional - (' . $prazo_total . ' ' . $text_dias . ') ' . $frete_desc,
    123165                        'cost' => $frete_custo
    124166                    ];
  • superfrete/trunk/app/Shipping/SuperFretePAC.php

    r3266581 r3268954  
    1212
    1313    public $free_shipping;
     14    public $extra_days;
     15    public $extra_cost;
     16    public $extra_cost_type;
    1417 public function __construct( $instance_id = 'superfrete_pac') {
    1518        $this->id                    = 'superfrete_pac';
     
    4144         
    4245            ),
     46            'extra_days' => array(
     47                'title' => __('Dias extras no prazo', 'superfrete'),
     48                'type' => 'number',
     49                'description' => __('Dias adicionais ao prazo estimado pela SuperFrete', 'superfrete'),
     50                'default' => 0,
     51                'desc_tip' => true
     52            ),
     53            'extra_cost' => array(
     54                'title' => __('Valor adicional no frete', 'superfrete'),
     55                'type' => 'price',
     56                'description' => __('Valor extra a ser somado ao custo do frete', 'superfrete'),
     57                'default' => '0',
     58                'desc_tip' => true
     59            ),
     60            'extra_cost_type' => array(
     61                'title' => __('Tipo de valor adicional', 'superfrete'),
     62                'type' => 'select',
     63                'description' => __('Escolha se o valor adicional será fixo (R$) ou percentual (%) sobre o frete original.', 'superfrete'),
     64                'default' => 'fixed',
     65                'options' => array(
     66                    'fixed' => __('Valor fixo (R$)', 'superfrete'),
     67                    'percent' => __('Porcentagem (%)', 'superfrete'),
     68                ),
     69            ),
    4370        );
    44         $this->enabled              = $this->get_option( 'enabled' );
    45         $this->free_shipping                = $this->get_option( 'free_shipping' );
    46         $this->title                = $this->get_option( 'title' );
     71        $this->enabled = $this->get_option('enabled');
     72        $this->free_shipping = $this->get_option('free_shipping');
     73        $this->title = $this->get_option('title');
     74        $this->extra_days = $this->get_option('extra_days', 0);
     75        $this->extra_cost = $this->get_option('extra_cost', 0);
     76        $this->extra_cost_type = $this->get_option('extra_cost_type', 'fixed');
     77
    4778        add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
    4879    }
     
    110141$response = $request->call_superfrete_api('/api/v0/calculator', 'POST', $payload);
    111142
    112         if (!empty($response) ) {
     143        if (!empty($response)) {
    113144            foreach ($response as $frete) {
    114                 $text_dias = ($frete['delivery_time'] <= 1)? "dia útil" : "dias úteis";
    115                 $frete_desc = "";
    116            
    117                 if (!$frete['has_error'] && !isset($frete["error"]) ) {
    118                     $frete_custo = ($this->free_shipping === 'yes') ? "0" : floatval($frete['price']);
     145                $prazo_total = $frete['delivery_time'] + $this->extra_days;
     146                $text_dias = ($prazo_total <= 1) ? "dia útil" : "dias úteis";
     147
     148                if (!$frete['has_error'] && !isset($frete["error"])) {
     149                   $frete_custo = 0;
     150
     151if ($this->free_shipping !== 'yes') {
     152    $frete_base = floatval($frete['price']);
     153    if ($this->extra_cost_type === 'percent') {
     154        $frete_custo = $frete_base + ($frete_base * ($this->extra_cost / 100));
     155    } else {
     156        $frete_custo = $frete_base + $this->extra_cost;
     157    }
     158}
     159
    119160                    $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : "";
    120                  
     161
    121162                    $rate = [
    122163                        'id' => $this->id . '_' . $frete['id'],
    123                         'label' => $frete['name'] . ' - Promocional - (' . $frete['delivery_time'] . ' ' . $text_dias . ') '. $frete_desc,
     164                        'label' => $frete['name'] . ' - Promocional - (' . $prazo_total . ' ' . $text_dias . ') ' . $frete_desc,
    124165                        'cost' => $frete_custo
    125166                    ];
  • superfrete/trunk/app/Shipping/SuperFreteSEDEX.php

    r3266581 r3268954  
    99    exit; // Segurança
    1010
    11 class SuperFreteSEDEX extends \WC_Shipping_Method { public $free_shipping;
    12  public function __construct( $instance_id = 'superfrete_sedex') {
    13         $this->id                    = 'superfrete_sedex';
    14         $this->instance_id           = absint( $instance_id );
    15         $this->method_title          = __( 'Sedex SuperFrete' );
    16         $this->method_description    = __( 'Envia utilizando Sedex' );
    17         $this->supports              = array(
     11class SuperFreteSEDEX extends \WC_Shipping_Method {
     12
     13    public $free_shipping;
     14    public $extra_days;
     15    public $extra_cost;
     16    public $extra_cost_type;
     17
     18    public function __construct($instance_id = 'superfrete_sedex') {
     19        $this->id = 'superfrete_sedex';
     20        $this->instance_id = absint($instance_id);
     21        $this->method_title = __('Sedex SuperFrete');
     22        $this->method_description = __('Envia utilizando Sedex');
     23        $this->supports = array(
    1824            'shipping-zones',
    1925            'instance-settings',
     
    2127        $this->instance_form_fields = array(
    2228            'enabled' => array(
    23                 'title'         => __( 'Ativar/Desativar' ),
    24                 'type'             => 'checkbox',
    25                 'label'         => __('Ativar SuperFrete nas áreas de entrega', 'superfrete'),
    26                 'default'         => 'yes',
     29                'title' => __('Ativar/Desativar'),
     30                'type' => 'checkbox',
     31                'label' => __('Ativar SuperFrete nas áreas de entrega', 'superfrete'),
     32                'default' => 'yes',
    2733            ),
    2834            'title' => array(
    29                 'title'         => __( 'Method Title' ),
    30                 'type'             => 'text',
    31                   'description' => __('Este título aparecerá no checkout', 'superfrete'),
     35                'title' => __('Method Title'),
     36                'type' => 'text',
     37                'description' => __('Este título aparecerá no checkout', 'superfrete'),
    3238                'default' => __('Entrega via Sedex SuperFrete', 'superfrete'),
    33                 'desc_tip'        => true
     39                'desc_tip' => true
    3440            ),
    35               'free_shipping' => array(
     41            'free_shipping' => array(
    3642                'title' => __('Frete Grátis', 'superfrete'),
    3743                'type' => 'checkbox',
    3844                'label' => __('Ativar frete grátis para este método', 'superfrete'),
    39          
     45            ),
     46            'extra_days' => array(
     47                'title' => __('Dias extras no prazo', 'superfrete'),
     48                'type' => 'number',
     49                'description' => __('Dias adicionais ao prazo estimado pela SuperFrete', 'superfrete'),
     50                'default' => 0,
     51                'desc_tip' => true
     52            ),
     53            'extra_cost' => array(
     54                'title' => __('Valor adicional no frete', 'superfrete'),
     55                'type' => 'price',
     56                'description' => __('Valor extra a ser somado ao custo do frete', 'superfrete'),
     57                'default' => '0',
     58                'desc_tip' => true
     59            ),
     60            'extra_cost_type' => array(
     61                'title' => __('Tipo de valor adicional', 'superfrete'),
     62                'type' => 'select',
     63                'description' => __('Escolha se o valor adicional será fixo (R$) ou percentual (%) sobre o frete original.', 'superfrete'),
     64                'default' => 'fixed',
     65                'options' => array(
     66                    'fixed' => __('Valor fixo (R$)', 'superfrete'),
     67                    'percent' => __('Porcentagem (%)', 'superfrete'),
     68                ),
    4069            ),
    4170        );
    42         $this->enabled              = $this->get_option( 'enabled' );
    43         $this->free_shipping                = $this->get_option( 'free_shipping' );
    44         $this->title                = $this->get_option( 'title' );
    45         add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
     71        $this->enabled = $this->get_option('enabled');
     72        $this->free_shipping = $this->get_option('free_shipping');
     73        $this->title = $this->get_option('title');
     74        $this->extra_days = $this->get_option('extra_days', 0);
     75        $this->extra_cost = $this->get_option('extra_cost', 0);
     76        $this->extra_cost_type = $this->get_option('extra_cost_type', 'fixed');
     77
     78        add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));
    4679    }
     80
    4781    protected function get_service_id() {
    4882        return 2; // ID do Sedex na API
    4983    }
    5084
    51 
    5285    /**
    5386     * Calcula o frete e retorna as opções disponíveis.
    5487     */
    55      public function calculate_shipping($package = []) {
     88    public function calculate_shipping($package = []) {
    5689
    5790        if (!$this->enabled || empty($package['destination']['postcode'])) {
     
    6194        $cep_destino = $package['destination']['postcode'];
    6295        $peso_total = 0;
    63 $produtos = [];
    64      $insurance_value = 0;
    65 foreach ($package['contents'] as $item) {
    66     $product = $item['data'];
    67    
    68    
    69    
    70    
    71   $insurance_value += $product->get_price() * $item['quantity'];
    72 $weight_unit = get_option('woocommerce_weight_unit');
    73 $dimension_unit = get_option('woocommerce_dimension_unit');
     96        $produtos = [];
     97        $insurance_value = 0;
     98        foreach ($package['contents'] as $item) {
     99            $product = $item['data'];
    74100
    75     $produtos[] = [
    76         'quantity' => $item['quantity'],
    77       'weight'   => ($weight_unit === 'g') ? floatval($product->get_weight()) / 1000 : floatval($product->get_weight()),
    78     'height'   => ($dimension_unit === 'm') ? floatval($product->get_height()) * 100 : floatval($product->get_height()),
    79     'width'    => ($dimension_unit === 'm') ? floatval($product->get_width()) * 100 : floatval($product->get_width()),
    80     'length'   => ($dimension_unit === 'm') ? floatval($product->get_length()) * 100 : floatval($product->get_length()),
     101            $insurance_value += $product->get_price() * $item['quantity'];
     102            $weight_unit = get_option('woocommerce_weight_unit');
     103            $dimension_unit = get_option('woocommerce_dimension_unit');
    81104
    82     ];
    83  
    84 }
     105            $produtos[] = [
     106                'quantity' => $item['quantity'],
     107                'weight' => ($weight_unit === 'g') ? floatval($product->get_weight()) / 1000 : floatval($product->get_weight()),
     108                'height' => ($dimension_unit === 'm') ? floatval($product->get_height()) * 100 : floatval($product->get_height()),
     109                'width' => ($dimension_unit === 'm') ? floatval($product->get_width()) * 100 : floatval($product->get_width()),
     110                'length' => ($dimension_unit === 'm') ? floatval($product->get_length()) * 100 : floatval($product->get_length()),
     111            ];
     112        }
    85113
    86 $cep_origem = get_option('woocommerce_store_postcode');
     114        $cep_origem = get_option('woocommerce_store_postcode');
    87115
    88 if (!$cep_origem) {
    89     return;
    90 }
     116        if (!$cep_origem) {
     117            return;
     118        }
    91119
    92 $payload = [
    93     'from' => ['postal_code' => $cep_origem],
    94     'to' => ['postal_code' => $cep_destino],
    95     'services' => "2",
    96     'options'=> [
    97       "own_hand"=>false,
    98       "receipt"=>false,
    99       "insurance_value"=> $insurance_value,
    100       "use_insurance_value"=>false
    101           ],
     120        $payload = [
     121            'from' => ['postal_code' => $cep_origem],
     122            'to' => ['postal_code' => $cep_destino],
     123            'services' => "2",
     124            'options' => [
     125                "own_hand" => false,
     126                "receipt" => false,
     127                "insurance_value" => $insurance_value,
     128                "use_insurance_value" => false
     129            ],
     130            'products' => $produtos,
     131        ];
    102132
    103     'products' => $produtos,
    104 ];
     133        $request = new Request();
    105134
    106 $request = new Request();
    107 
    108 $response = $request->call_superfrete_api('/api/v0/calculator', 'POST', $payload);
     135        $response = $request->call_superfrete_api('/api/v0/calculator', 'POST', $payload);
    109136
    110137        if (!empty($response)) {
    111138            foreach ($response as $frete) {
    112                 $text_dias = ($frete['delivery_time'] <= 1)? "dia útil" : "dias úteis";
    113             if (!$frete['has_error'] && !isset($frete["error"]) ) {
    114                     $frete_custo = ($this->free_shipping === 'yes') ? "0" : floatval($frete['price']);
     139                $prazo_total = $frete['delivery_time'] + $this->extra_days;
     140                $text_dias = ($prazo_total <= 1) ? "dia útil" : "dias úteis";
     141
     142                if (!$frete['has_error'] && !isset($frete["error"])) {
     143                   $frete_custo = 0;
     144
     145if ($this->free_shipping !== 'yes') {
     146    $frete_base = floatval($frete['price']);
     147    if ($this->extra_cost_type === 'percent') {
     148        $frete_custo = $frete_base + ($frete_base * ($this->extra_cost / 100));
     149    } else {
     150        $frete_custo = $frete_base + $this->extra_cost;
     151    }
     152}
     153
    115154                    $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : "";
    116                  
     155
    117156                    $rate = [
    118157                        'id' => $this->id . '_' . $frete['id'],
    119                         'label' => $frete['name'] . ' - Promocional - (' . $frete['delivery_time'] . ' ' . $text_dias . ') '. $frete_desc,
     158                        'label' => $frete['name'] . ' - Promocional - (' . $prazo_total . ' ' . $text_dias . ') ' . $frete_desc,
    120159                        'cost' => $frete_custo
    121160                    ];
  • superfrete/trunk/assets/scripts/superfrete-calculator.js

    r3266581 r3268954  
    7575                            request.done(function(res){
    7676                                parent.setLocation(res);
    77 
    7877                                parent.showCalculator();
    7978                                parent.setVariation(data);
     
    165164            if(this.form_present() == false) return;
    166165           
    167             var e = jQuery('form.superfrete-woocommerce-shipping-calculator');
     166            var e = jQuery('form.superfrete-woocommerce-shipping-calculator:visible').first();
    168167            var parent = this;
    169168            if (jQuery("#superfrete-variation-id").length && jQuery("#superfrete-variation-id").val() == 0) {
  • superfrete/trunk/templates/woocommerce/shipping-calculator.php

    r3266581 r3268954  
    6666                    <p class="form-row form-row-wide" id="calc_shipping_state_field">
    6767                        <?php
    68                         $current_cc = WC()->customer->get_shipping_country();
     68                        $current_cc = "BR";
    6969                        $current_r = WC()->customer->get_shipping_state();
    7070                        $states = WC()->countries->get_states($current_cc);
Note: See TracChangeset for help on using the changeset viewer.