WC_Correios_Shipping_Impresso_Normal

Impresso Normal shipping method class.

Defined (1)

The class is defined in the following location(s).

/includes/shipping/class-wc-correios-shipping-impresso-normal.php  
  1. class WC_Correios_Shipping_Impresso_Normal extends WC_Correios_Shipping_Impresso { 
  2.  
  3. /** 
  4. * Additional cost per kg or fraction. 
  5. * Cost based in 01/02/2017 from: 
  6. * https://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/impresso-normal 
  7. * @var float 
  8. */ 
  9. protected $additional_cost_per_kg = 4.05; 
  10.  
  11. /** 
  12. * Weight limit for this shipping method. 
  13. * Value based in 01/02/2017 from: 
  14. * https://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/impresso-normal 
  15. * @var float 
  16. */ 
  17. protected $shipping_method_weight_limit = 20000.000; 
  18.  
  19. /** 
  20. * Initialize Impresso Normal. 
  21. * @param int $instance_id Shipping zone instance. 
  22. */ 
  23. public function __construct( $instance_id = 0 ) { 
  24. $this->id = 'correios-impresso-normal'; 
  25. $this->method_title = __( 'Impresso Normal', 'woocommerce-correios' ); 
  26. $this->more_link = 'http://www.correios.com.br/para-voce/correios-de-a-a-z/impresso-normal'; 
  27.  
  28. parent::__construct( $instance_id ); 
  29.  
  30. /** 
  31. * Get costs. 
  32. * Costs based in 01/02/2017 from: 
  33. * https://www.correios.com.br/para-voce/consultas-e-solicitacoes/precos-e-prazos/servicos-nacionais_pasta/impresso-normal 
  34. * @return array 
  35. */ 
  36. protected function get_costs() { 
  37. return apply_filters( 'woocommerce_correios_impresso_normal_costs', array( 
  38. '20' => 1.05,  
  39. '50' => 1.60,  
  40. '100' => 2.10,  
  41. '150' => 2.55,  
  42. '200' => 3.00,  
  43. '250' => 3.50,  
  44. '300' => 3.95,  
  45. '350' => 4.40,  
  46. '400' => 4.90,  
  47. '450' => 5.40,  
  48. '500' => 5.90,  
  49. '550' => 6.25,  
  50. '600' => 6.70,  
  51. '650' => 7.15,  
  52. '700' => 7.50,  
  53. '750' => 7.90,  
  54. '800' => 8.30,  
  55. '850' => 8.75,  
  56. '900' => 9.25,  
  57. '950' => 9.65,  
  58. '1000' => 10.05,  
  59. ), $this->id, $this->instance_id ); 
  60.  
  61. /** 
  62. * Get shipping cost. 
  63. * @param array $package Order package. 
  64. * @return float 
  65. */ 
  66. protected function get_shipping_cost( $package ) { 
  67. $cost = 0; 
  68. $additional_weight_kgs = 0; 
  69. $additional_weight_gs = 0; 
  70.  
  71. if ( 'yes' === $this->debug ) { 
  72. $this->log->add( $this->id, 'Calculating cost for Impresso Normal' ); 
  73.  
  74. if ( '' === $this->shipping_class ) { 
  75. if ( 'yes' === $this->debug ) { 
  76. $this->log->add( $this->id, 'Error: No shipping class has been configured!' ); 
  77.  
  78. return 0; 
  79.  
  80. // Get the package weight and validate. 
  81. $weight = $this->get_package_weight( $package ); 
  82. if ( false === $weight ) { 
  83. return 0; 
  84.  
  85. if ( $weight <= $this->shipping_method_weight_limit ) { 
  86. if ( $weight > 1000 ) { 
  87. // Get the additional kgs over 1 kg. 
  88. $additional_weight_kgs = intval( $weight / 1000 ); 
  89.  
  90. // To ensure it will get the maximum price for 1 kg. 
  91. $additional_weight_gs = 1000; 
  92. } else { 
  93. // Get the cart weight itself. 
  94. $additional_weight_gs = $weight; 
  95.  
  96. foreach ( $this->get_costs() as $cost_weights => $costs ) { 
  97. if ( $additional_weight_gs <= $cost_weights ) { 
  98. $cost = $costs; 
  99.  
  100. if ( $additional_weight_kgs > 0 ) { 
  101. $cost += $additional_weight_kgs * $this->additional_cost_per_kg; 
  102.  
  103. if ( $weight > $this->reasonable_registry_weight_limit || 'yes' === $this->own_hands || 'RN' === $this->registry_type ) { 
  104. $cost += $this->national_registry_cost; 
  105. } else { 
  106. $cost += $this->reasonable_registry_cost; 
  107.  
  108. if ( 'yes' === $this->receipt_notice ) { 
  109. $cost += $this->receipt_notice_cost; 
  110.  
  111. if ( 'yes' === $this->own_hands ) { 
  112. $cost += $this->own_hands_cost; 
  113.  
  114. break; 
  115.  
  116. if ( 'yes' === $this->debug ) { 
  117. $this->log->add( $this->id, sprintf( 'Total cost for %sg and %s: %s', $weight, $this->registry_type, $cost ) ); 
  118. } else { 
  119. if ( 'yes' === $this->debug ) { 
  120. $this->log->add( $this->id, sprintf( 'The cart weight of %.3f exceeds the shipping method supported weight limit of %.3f', $weight, $this->shipping_method_weight_limit ) ); 
  121.  
  122. return $cost;