Skip to content

Commit

Permalink
publicar versão 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemas-jadlog committed Apr 17, 2020
1 parent 0bcb1f7 commit 318d9f8
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 165 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.log
/tags
/wordpress
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ O plugin *WooCommerce Jadlog* já está instalado, mas deve ser ativado no paine
## Changelog

* v0.1.0 - Lançamento (versão beta).
* v0.1.1 - Utilização da mesma chave do Embarcador para consulta de PUDOs.


## Licença
Expand Down
7 changes: 2 additions & 5 deletions doc/MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ Marque esta opção para ativar a modalidade de transporte Jadlog Pickup

- **URL da API de consulta de pontos Pickup**:
Endereço para consulta dos pontos de retirada (pickup).
Valor padrão: *http://mypudo.pickup-services.com/mypudo/mypudo.asmx/GetPudoList*

- **Chave de acesso Pickup**:
Chave do serviço de consulta de pontos de coleta fornecida pela Jadlog após a assinatura do contrato.
Valor padrão: *http://www.jadlog.com.br/embarcador/api/pickup/pudos*

- **Qtd de pontos pickup a mostrar**:
Quantidade de pontos pickup a serem mostrados no carrinho de compras
Quantidade de pontos pickup a serem mostrados no carrinho de compras. Valor máximo: 10.

- **FRAP**:
Marque esta opção se deseja que a cobrança de frete seja feita no destino na modalidade Pickup.
Expand Down
Binary file modified doc/img/woocommerceJadlog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added downloads/woocommerce-jadlog-v0.1.1.zip
Binary file not shown.
49 changes: 42 additions & 7 deletions woocommerce-jadlog/classes/EmbarcadorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@ public function __construct($jadlog_id) {
include_once("OrderHelper.php");
include_once("ServicesHelper.php");

$this->jadlog_delivery = DeliveryRepository::get_by_id($jadlog_id);
if (!empty($jadlog_id))
$this->jadlog_delivery = DeliveryRepository::get_by_id($jadlog_id);

$this->url_inclusao = get_option('wc_settings_tab_jadlog_url_inclusao_pedidos');
$this->url_cancelamento = get_option('wc_settings_tab_jadlog_url_cancelamento_pedidos');
$this->url_consulta = get_option('wc_settings_tab_jadlog_url_consulta_pedidos');
$this->url_pudos = get_option('wc_settings_tab_jadlog_url_consulta_pudos');
$this->key = get_option('wc_settings_tab_jadlog_key_embarcador');
$this->codigo_cliente = get_option('wc_settings_tab_jadlog_codigo_cliente');
$this->modalidade = Modalidade::codigo_modalidade($this->jadlog_delivery->modalidade);
if (!empty($this->jadlog_delivery))
$this->modalidade = Modalidade::codigo_modalidade($this->jadlog_delivery->modalidade);
$this->conta_corrente = get_option('wc_settings_tab_jadlog_conta_corrente');
$this->tipo_coleta = get_option('wc_settings_tab_jadlog_tipo_coleta');
$this->tipo_frete = get_option('wc_settings_tab_jadlog_tipo_frete');
$this->unidade_origem = get_option('wc_settings_tab_jadlog_unidade_origem');
$this->contrato = get_option('wc_settings_tab_jadlog_contrato');
$this->servico = get_option('wc_settings_tab_jadlog_servico');
$sufix = '_'.strtolower(Modalidade::TODOS[$this->modalidade]);
$this->valor_coleta = get_option('wc_settings_tab_jadlog_valor_coleta'.$sufix);
if (!empty($this->modalidade)) {
$sufix = '_'.strtolower(Modalidade::TODOS[$this->modalidade]);
$this->valor_coleta = get_option('wc_settings_tab_jadlog_valor_coleta'.$sufix);
}
$this->max_pudo_number = get_option('wc_settings_tab_jadlog_qtd_pontos_pickup');

$this->rem_nome = get_option('wc_settings_tab_jadlog_shipper_name');
$this->rem_cpf_cnpj = get_option('wc_settings_tab_jadlog_shipper_cnpj_cpf');
Expand Down Expand Up @@ -70,7 +76,7 @@ public function create($dfe) {

$response = wp_remote_post($this->url_inclusao, array(
'method' => 'POST',
'timeout' => 120,
'timeout' => 30,
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
Expand Down Expand Up @@ -183,7 +189,7 @@ public function cancel($shipment_id) {

$response = wp_remote_post($this->url_cancelamento, array(
'method' => 'POST',
'timeout' => 120,
'timeout' => 30,
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
Expand Down Expand Up @@ -221,7 +227,7 @@ public function get($shipment_id) {

$response = wp_remote_post($this->url_consulta, array(
'method' => 'POST',
'timeout' => 120,
'timeout' => 30,
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
Expand All @@ -244,4 +250,33 @@ public function get($shipment_id) {

return $result;
}

public function get_pudos($zip_code) {

$url = $this->url_pudos."/".urlencode($zip_code);

$response = wp_remote_post($url, array(
'method' => 'POST',
'timeout' => 30,
'blocking' => true,
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
'Authorization' => $this->key),
'cookies' => array()));
error_log( 'In ' . __FUNCTION__ . '(), $response = ' . var_export( $response, true ) );

if (is_wp_error($response)) {
Logger::log_error($response->get_error_message(), __FUNCTION__, $response);
$result = array('status' => $response->get_error_message(), 'erro' => array());
}
elseif ($response['response']['code'] == 500) {
Logger::log_error($response['body'], __FUNCTION__, $response);
$result = array('status' => $response['body'], 'erro' => array('descricao' => $response['response']['code']));
}
else
$result = json_decode($response['body'], true);

error_log(var_export($result, true));
return $result;
}
}
62 changes: 0 additions & 62 deletions woocommerce-jadlog/classes/JadLogMyPudo.php

This file was deleted.

62 changes: 62 additions & 0 deletions woocommerce-jadlog/classes/PudoInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
namespace WooCommerce\Jadlog\Classes;

class PudoInfo {

public function __construct($pudo_data) {
$this->_data = is_array($pudo_data) ? $pudo_data : array();
$this->_address = $this->_data['pudoEnderecoList'][0];
}

public function nao_esta_ativo() {
return $this->_data['ativo'] != 'S';
}

public function get_id() {
return $this->_data['pudoId'];
}

public function get_name() {
return $this->_data['razao'];
}

public function get_latitude() {
return $this->_address['latitude'];
}

public function get_longitude() {
return $this->_address['longitude'];
}

public function get_postcode() {
return $this->_address['cep'];
}

public function get_openning_hours() {
return $this->_data['pudoHorario'];
}

public function get_formatted_address() {
$address = $this->_address['endereco'];
if (!empty($this->_address['numero']))
$address .= ', '.$this->_address['numero'];
if (!empty($this->_address['compl2']))
$address .= ' - '.$this->_address['compl2'];
if (!empty($this->_address['bairro']) && $this->_address['bairro'] != $this->_address['compl2'])
$address .= ' - '.$this->_address['bairro'];
if (!empty($this->_address['cidade']))
$address .= ' - '.$this->_address['cidade'];
if (!empty($this->_address['cep']))
$address .= ' - CEP '.$this->format_postcode($this->_address['cep']);
return $address;
}

private function format_postcode($postcode) {
$postcode = str_pad($postcode, 8, "0", STR_PAD_LEFT);
return strlen($postcode) == 8 ? substr($postcode, 0, 5).'-'.substr($postcode, -3) : $postcode;
}

public function get_formatted_name_and_address() {
return $this->get_name().' ('.$this->get_formatted_address().')';
}
}
2 changes: 0 additions & 2 deletions woocommerce-jadlog/classes/ShippingPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ public function get_effective_weight() {
$weight = $this->get_weight();
$volumetric_weight = $this->get_volumetric_weight();
$this->effective_weight = empty($volumetric_weight) ? $weight : max($weight, $volumetric_weight);
if (empty($this->effective_weight))
$this->effective_weight = 0.1;
}
return $this->effective_weight;
}
Expand Down
40 changes: 40 additions & 0 deletions woocommerce-jadlog/classes/ShippingPrice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace WooCommerce\Jadlog\Classes;

class ShippingPrice {

public function __construct($postcode, $shipping_package) {
$this->_shipping_package = $shipping_package;
$this->_postcode = $postcode;
}

public function get_estimated_value() {
$values = $this->get_estimated_values();
return $values['estimated_value'];
}

public function get_formatted_estimated_time() {
$values = $this->get_estimated_values();
return isset($values['estimated_time']) ?
$values['estimated_time'].__(' dias úteis', 'jadlog') :
'';
}

public function get_estimated_time() {
$values = $this->get_estimated_values();
return $values['estimated_time'];
}

private function get_estimated_values() {
if (!isset($this->_estimated_values)) {
include_once('ShippingPriceService.php');
$service = new ShippingPriceService($this->_shipping_package->modalidade);
$this->_estimated_values = $service->estimate(
$this->_shipping_package->get_price(),
$this->_postcode,
$this->_shipping_package->get_effective_weight());
}

return $this->_estimated_values;
}
}
Loading

0 comments on commit 318d9f8

Please sign in to comment.