Changeset 3268954
- Timestamp:
- 04/08/2025 01:59:03 PM (12 months ago)
- Location:
- superfrete
- Files:
-
- 37 added
- 6 edited
-
tags/2.1.0 (added)
-
tags/2.1.0/README.md (added)
-
tags/2.1.0/api (added)
-
tags/2.1.0/api/Helpers (added)
-
tags/2.1.0/api/Helpers/Logger.php (added)
-
tags/2.1.0/api/Http (added)
-
tags/2.1.0/api/Http/Request.php (added)
-
tags/2.1.0/app (added)
-
tags/2.1.0/app/App.php (added)
-
tags/2.1.0/app/Controllers (added)
-
tags/2.1.0/app/Controllers/Admin (added)
-
tags/2.1.0/app/Controllers/Admin/Admin_Menu.php (added)
-
tags/2.1.0/app/Controllers/Admin/SuperFrete_OrderActions.php (added)
-
tags/2.1.0/app/Controllers/Admin/SuperFrete_Settings.php (added)
-
tags/2.1.0/app/Controllers/ProductShipping.php (added)
-
tags/2.1.0/app/Controllers/SuperFrete_Order.php (added)
-
tags/2.1.0/app/Helpers (added)
-
tags/2.1.0/app/Helpers/SuperFrete_Notice.php (added)
-
tags/2.1.0/app/Shipping (added)
-
tags/2.1.0/app/Shipping/SuperFreteMiniEnvio.php (added)
-
tags/2.1.0/app/Shipping/SuperFretePAC.php (added)
-
tags/2.1.0/app/Shipping/SuperFreteSEDEX.php (added)
-
tags/2.1.0/app/Shipping/SuperFreteShipping.php (added)
-
tags/2.1.0/assets (added)
-
tags/2.1.0/assets/img (added)
-
tags/2.1.0/assets/img/loading-3.gif (added)
-
tags/2.1.0/assets/scripts (added)
-
tags/2.1.0/assets/scripts/admin.js (added)
-
tags/2.1.0/assets/scripts/superfrete-calculator.js (added)
-
tags/2.1.0/assets/scripts/superfrete-popup.js (added)
-
tags/2.1.0/assets/styles (added)
-
tags/2.1.0/assets/styles/superfrete.css (added)
-
tags/2.1.0/readme.txt (added)
-
tags/2.1.0/superfrete.php (added)
-
tags/2.1.0/templates (added)
-
tags/2.1.0/templates/woocommerce (added)
-
tags/2.1.0/templates/woocommerce/shipping-calculator.php (added)
-
trunk/app/Controllers/ProductShipping.php (modified) (1 diff)
-
trunk/app/Shipping/SuperFreteMiniEnvio.php (modified) (3 diffs)
-
trunk/app/Shipping/SuperFretePAC.php (modified) (3 diffs)
-
trunk/app/Shipping/SuperFreteSEDEX.php (modified) (3 diffs)
-
trunk/assets/scripts/superfrete-calculator.js (modified) (2 diffs)
-
trunk/templates/woocommerce/shipping-calculator.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
superfrete/trunk/app/Controllers/ProductShipping.php
r3266581 r3268954 132 132 WC()->cart->calculate_totals(); 133 133 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 141 137 $original_cart = WC()->cart->get_cart(); 142 138 WC()->cart->empty_cart(); 143 139 $item_key = self::addTestProductForProperShippingCost(); 140 144 141 WC()->shipping()->calculate_shipping(); 145 142 WC()->cart->calculate_totals(); 146 143 $packages = WC()->shipping()->get_packages(); 144 147 145 148 146 149 }147 150 148 151 149 $shipping_methods = self::getShippingMethods($packages); -
superfrete/trunk/app/Shipping/SuperFreteMiniEnvio.php
r3266581 r3268954 10 10 11 11 class 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 13 17 public function __construct( $instance_id = 'superfrete_mini_envio') { 14 18 $this->id = 'superfrete_mini_envio'; … … 39 43 'label' => __('Ativar frete grátis para este método', 'superfrete'), 40 44 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 ), 41 68 ), 42 69 ); 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 46 77 add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 47 78 } … … 112 143 if (!empty($response)) { 113 144 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 151 if ($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 118 160 $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : ""; 119 161 120 162 $rate = [ 121 163 '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, 123 165 'cost' => $frete_custo 124 166 ]; -
superfrete/trunk/app/Shipping/SuperFretePAC.php
r3266581 r3268954 12 12 13 13 public $free_shipping; 14 public $extra_days; 15 public $extra_cost; 16 public $extra_cost_type; 14 17 public function __construct( $instance_id = 'superfrete_pac') { 15 18 $this->id = 'superfrete_pac'; … … 41 44 42 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 ), 69 ), 43 70 ); 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 47 78 add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) ); 48 79 } … … 110 141 $response = $request->call_superfrete_api('/api/v0/calculator', 'POST', $payload); 111 142 112 if (!empty($response) ) {143 if (!empty($response)) { 113 144 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 151 if ($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 119 160 $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : ""; 120 161 121 162 $rate = [ 122 163 '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, 124 165 'cost' => $frete_custo 125 166 ]; -
superfrete/trunk/app/Shipping/SuperFreteSEDEX.php
r3266581 r3268954 9 9 exit; // Segurança 10 10 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( 11 class 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( 18 24 'shipping-zones', 19 25 'instance-settings', … … 21 27 $this->instance_form_fields = array( 22 28 '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', 27 33 ), 28 34 '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'), 32 38 'default' => __('Entrega via Sedex SuperFrete', 'superfrete'), 33 'desc_tip' => true39 'desc_tip' => true 34 40 ), 35 'free_shipping' => array(41 'free_shipping' => array( 36 42 'title' => __('Frete Grátis', 'superfrete'), 37 43 'type' => 'checkbox', 38 44 '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 ), 40 69 ), 41 70 ); 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')); 46 79 } 80 47 81 protected function get_service_id() { 48 82 return 2; // ID do Sedex na API 49 83 } 50 84 51 52 85 /** 53 86 * Calcula o frete e retorna as opções disponíveis. 54 87 */ 55 public function calculate_shipping($package = []) {88 public function calculate_shipping($package = []) { 56 89 57 90 if (!$this->enabled || empty($package['destination']['postcode'])) { … … 61 94 $cep_destino = $package['destination']['postcode']; 62 95 $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']; 74 100 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'); 81 104 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 } 85 113 86 $cep_origem = get_option('woocommerce_store_postcode');114 $cep_origem = get_option('woocommerce_store_postcode'); 87 115 88 if (!$cep_origem) {89 return;90 }116 if (!$cep_origem) { 117 return; 118 } 91 119 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 ]; 102 132 103 'products' => $produtos, 104 ]; 133 $request = new Request(); 105 134 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); 109 136 110 137 if (!empty($response)) { 111 138 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 145 if ($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 115 154 $frete_desc = ($this->free_shipping === 'yes') ? "- Frete Grátis" : ""; 116 155 117 156 $rate = [ 118 157 '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, 120 159 'cost' => $frete_custo 121 160 ]; -
superfrete/trunk/assets/scripts/superfrete-calculator.js
r3266581 r3268954 75 75 request.done(function(res){ 76 76 parent.setLocation(res); 77 78 77 parent.showCalculator(); 79 78 parent.setVariation(data); … … 165 164 if(this.form_present() == false) return; 166 165 167 var e = jQuery('form.superfrete-woocommerce-shipping-calculator ');166 var e = jQuery('form.superfrete-woocommerce-shipping-calculator:visible').first(); 168 167 var parent = this; 169 168 if (jQuery("#superfrete-variation-id").length && jQuery("#superfrete-variation-id").val() == 0) { -
superfrete/trunk/templates/woocommerce/shipping-calculator.php
r3266581 r3268954 66 66 <p class="form-row form-row-wide" id="calc_shipping_state_field"> 67 67 <?php 68 $current_cc = WC()->customer->get_shipping_country();68 $current_cc = "BR"; 69 69 $current_r = WC()->customer->get_shipping_state(); 70 70 $states = WC()->countries->get_states($current_cc);
Note: See TracChangeset
for help on using the changeset viewer.