Skip to content

Commit

Permalink
Publicar v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sistemas-jadlog committed Oct 28, 2020
1 parent a419612 commit bc198d4
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ Este plugin pode se integrar ao serviço de monitoramento de erros [Bugsnag](htt

## Changelog

- v0.2.0
- Modalidade Package.
- v0.1.4
- Correção na integração com *Brazilian Market on WooCommerce*
- Correção na integração com *Brazilian Market on WooCommerce*.
- v0.1.3
- Correções de bugs.
- v0.1.2
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ services:
args:
WORDPRESS_VERSION: 5.4
environment:
WORDPRESS_VERSION: 5.4
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: wordpress
Expand Down
4 changes: 3 additions & 1 deletion test-container/setup-tests
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

echo "==> Executing $0"
echo "Wordpress version: $WORDPRESS_VERSION"

cd /wordpress/wp-content/plugins/woocommerce-jadlog

Expand All @@ -9,7 +10,8 @@ DB_EXISTS=$(echo "show databases like '$WORDPRESS_DB_NAME';" | mysql -h $WORDPRE
echo "==> Installing wordpress tests lib"
SKIP_DB_CREATE=$(test -n "$DB_EXISTS" && echo -n true)
[ "$SKIP_DB_CREATE" ] && echo "==> Database $WORDPRESS_DB_NAME already exists"
WP_TESTS_DIR="/tmp/wordpress-tests-lib" ./bin/install-wp-tests.sh $WORDPRESS_DB_NAME $WORDPRESS_DB_USER $WORDPRESS_DB_PASSWORD $WORDPRESS_DB_HOST latest $SKIP_DB_CREATE
WP_TESTS_DIR="/tmp/wordpress-tests-lib" \
./bin/install-wp-tests.sh $WORDPRESS_DB_NAME $WORDPRESS_DB_USER $WORDPRESS_DB_PASSWORD $WORDPRESS_DB_HOST $WORDPRESS_VERSION $SKIP_DB_CREATE

[ $? != 0 ] && echo "==> Install failed. Please, try it again." && exit $?

Expand Down
2 changes: 1 addition & 1 deletion woocommerce-jadlog/classes/Modalidade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Modalidade {
const COD_PICKUP = 40;

const LABEL_EXPRESSO = 'EXPRESSO';
const LABEL_PACKAGE = '.PACKAGE';
const LABEL_PACKAGE = 'PACKAGE';
const LABEL_RODOVIARIO = 'RODOVIÁRIO';
const LABEL_ECONOMICO = 'ECONÔMICO';
const LABEL_DOC = 'DOC';
Expand Down
41 changes: 37 additions & 4 deletions woocommerce-jadlog/classes/jadlogShippingInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ function init() {
$this->init_form_fields();
$this->init_settings();

$this->jadlog_pickup_points_number = get_option('wc_settings_tab_jadlog_qtd_pontos_pickup');
$this->jadlog_modalidade_pickup_ativa = get_option('wc_settings_tab_jadlog_modalidade_pickup') == 'yes';
$this->jadlog_modalidade_com_ativa = get_option('wc_settings_tab_jadlog_modalidade_com') == 'yes';
$this->jadlog_pickup_points_number = get_option('wc_settings_tab_jadlog_qtd_pontos_pickup');
$this->jadlog_modalidade_com_ativa = get_option('wc_settings_tab_jadlog_modalidade_com') == 'yes';
$this->jadlog_modalidade_package_ativa = get_option('wc_settings_tab_jadlog_modalidade_package') == 'yes';
$this->jadlog_modalidade_pickup_ativa = get_option('wc_settings_tab_jadlog_modalidade_pickup') == 'yes';

// Save settings in admin if you have any defined
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
Expand All @@ -80,6 +81,9 @@ public function calculate_shipping($package = array()) {
if ($this->jadlog_modalidade_com_ativa)
$this->jadlog_add_com_rate($package, $postcode);

if ($this->jadlog_modalidade_package_ativa)
$this->jadlog_add_package_rate($package, $postcode);

if ($this->jadlog_modalidade_pickup_ativa)
$this->jadlog_add_pickup_rates($package, $postcode);
}
Expand All @@ -91,6 +95,7 @@ private function jadlog_add_com_rate($package, $postcode) {

if (!is_null($cost)) {
$rate = array(
'id' => 'jadlog_com',
'label' => $this->jadlog_build_com_label($shipping_price),
'cost' => $cost,
'taxes' => true,
Expand All @@ -104,6 +109,27 @@ private function jadlog_add_com_rate($package, $postcode) {
}
}

private function jadlog_add_package_rate($package, $postcode) {
$shipping_package = new ShippingPackage($package, Modalidade::COD_PACKAGE);
$shipping_price = new ShippingPrice($postcode, $shipping_package);
$cost = $shipping_price->get_estimated_value();

if (!is_null($cost)) {
$rate = array(
'id' => 'jadlog_package',
'label' => $this->jadlog_build_package_label($shipping_price),
'cost' => $cost,
'taxes' => true,
'meta_data' => [
'modalidade' => Modalidade::LABEL_PACKAGE,
'valor_total' => $shipping_package->get_price(),
'peso_taxado' => $shipping_package->get_effective_weight()
],
);
$this->add_rate($rate);
}
}

private function jadlog_add_pickup_rates($package, $postcode) {
$shipping_package = new ShippingPackage($package, Modalidade::COD_PICKUP);
$embarcador = new EmbarcadorService(null);
Expand All @@ -122,7 +148,7 @@ private function jadlog_add_pickup_rates($package, $postcode) {
$_SESSION[$pudo->get_id()] = $this->jadlog_build_session_array($pudo);

$rate = array(
'id' => $pudo->get_id(),
'id' => "jadlog_pudo_".$pudo->get_id(),
'label' => $this->jadlog_build_pickup_label($shipping_price, $pudo),
'cost' => $cost,
'taxes' => true,
Expand Down Expand Up @@ -158,6 +184,13 @@ private function jadlog_build_com_label($shipping_price) {
' - $1 '.__('dia útil', 'jadlog'));
}

private function jadlog_build_package_label($shipping_price) {
return __('Jadlog Package', 'jadlog').$this->jadlog_insert_if_present(
$shipping_price->get_estimated_time(),
' - $1 '.__('dias úteis', 'jadlog'),
' - $1 '.__('dia útil', 'jadlog'));
}

private function jadlog_build_pickup_label($shipping_price, $pudo) {
return __('Retire no ponto Pickup Jadlog', 'jadlog').' '.
$pudo->get_formatted_name_and_address().
Expand Down
70 changes: 68 additions & 2 deletions woocommerce-jadlog/woocommerce-jadlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Jadlog
* Plugin URI: https://github.com/Jadlog/woocommerce
* Description: Jadlog Shipping Module for WooCommerce 3 & 4
* Version: 0.1.4
* Version: 0.2.0
* Author: Jadlog Logística
* Author URI: https://www.jadlog.com.br/
* Text Domain: woocommerce-jadlog
Expand Down Expand Up @@ -117,6 +117,8 @@ public function settings_tab()
woocommerce_admin_fields( $this->get_shipments_settings() );
echo "<h3>".__('Modalidade Jadlog Expresso (.COM)', 'jadlog')."</h3>";
woocommerce_admin_fields( $this->get_com_settings() );
echo "<h3>".__('Modalidade Jadlog Package', 'jadlog')."</h3>";
woocommerce_admin_fields( $this->get_package_settings() );
echo "<h3>".__('Modalidade Jadlog Pickup', 'jadlog')."</h3>";
woocommerce_admin_fields( $this->get_pickup_settings() );
echo "<h3>".__('Dados do remetente', 'jadlog')."</h3>";
Expand All @@ -128,6 +130,7 @@ public function update_settings()
{
woocommerce_update_options( $this->get_shipments_settings() );
woocommerce_update_options( $this->get_com_settings() );
woocommerce_update_options( $this->get_package_settings() );
woocommerce_update_options( $this->get_pickup_settings() );
woocommerce_update_options( $this->get_shipperdata_settings() );
}
Expand Down Expand Up @@ -263,7 +266,7 @@ public function get_com_settings() {
'name' => __('Valor de coleta', 'jadlog'),
'type' => 'text',
'css' => 'width:200px;',
'desc' => __('Valor de coleta negociado com a Jadlog na modalidade Expresso (.COM)', 'jadlog'),
'desc' => __('Valor de coleta negociado com a Jadlog na modalidade Expresso (.COM). Formato: 1234.99', 'jadlog'),
'id' => 'wc_settings_tab_jadlog_valor_coleta_com'
),
'JADLOG_TIPO_ENTREGA_COM' => array(
Expand Down Expand Up @@ -301,6 +304,69 @@ public function get_com_settings() {
return $settings;
}

public function get_package_settings() {
include_once('classes/TipoEntrega.php');
include_once('classes/TipoSeguro.php');

$settings = array(
'JADLOG_MODALIDADE_PACKAGE' => array(
'name' => '',
'desc' => __('Ativar a modalidade de transporte Jadlog Package', 'jadlog'),
'desc_tip' => __('Marque esta opção se deseja utilizar a modalidade de transporte Jadlog Package', 'jadlog'),
'type' => 'checkbox',
'default' => 'no',
'id' => 'wc_settings_tab_jadlog_modalidade_package'
),
'JADLOG_FRAP_PACKAGE' => array(
'name' => '',
'desc' => __('FRAP', 'jadlog'),
'desc_tip' => __('Marque esta opção se deseja que a cobrança de frete seja feita no destino na modalidade Package', 'jadlog'),
'type' => 'checkbox',
'default' => 'no',
'id' => 'wc_settings_tab_jadlog_frap_package'
),
'JADLOG_VALOR_COLETA_PACKAGE' => array(
'name' => __('Valor de coleta', 'jadlog'),
'type' => 'text',
'css' => 'width:200px;',
'desc' => __('Valor de coleta negociado com a Jadlog na modalidade Package (formato: 1234.99)', 'jadlog'),
'id' => 'wc_settings_tab_jadlog_valor_coleta_package'
),
'JADLOG_TIPO_ENTREGA_PACKAGE' => array(
'name' => __('Tipo de entrega', 'jadlog'),
'type' => 'select',
'desc_tip' => 'Na modalidade Package',
'options' => TipoEntrega::TODOS,
'default' => TipoEntrega::COD_DOMICILIO,
'id' => 'wc_settings_tab_jadlog_tipo_entrega_package'
),
'JADLOG_TIPO_SEGURO_PACKAGE' => array(
'name' => __('Tipo do seguro', 'jadlog'),
'type' => 'select',
'desc_tip' => 'Na modalidade Package',
'options' => TipoSeguro::TODOS,
'default' => TipoSeguro::COD_NORMAL,
'id' => 'wc_settings_tab_jadlog_tipo_seguro_package'
),
'JADLOG_CALCULAR_PESOS_CUBADOS_PACKAGE' => array(
'name' => __('Calcular pesos cubados na modalidade Package', 'jadlog'),
'type' => 'select',
'options' => array(
'PADRAO' => __('Usar fator de cubagem padrão: ', 'jadlog').__(Modalidade::modal(Modalidade::COD_PACKAGE), 'jadlog'),
Modalidade::MODAL_AEREO => 'Usar fator de cubagem aéreo',
'NAO_CALCULAR' => 'Não calcular cubagem'
),
'default' => 'PADRAO',
'desc' =>
'<br/>'.__('Os pesos cubados são utilizados no cálculo do frete e dependem do modal contratado (aéreo ou rodoviário).', 'jadlog').
'<br/>'.__('Caso selecione um modal, cadastre os pesos reais dos produtos e suas dimensões.', 'jadlog').
'<br/>'.__('Caso selecione a opção para não calcular cubagem, no cadastro de produtos informe no campo peso o maior valor entre o peso real e o peso cubado do respectivo produto.', 'jadlog'),
'id' => 'wc_settings_tab_jadlog_calcular_pesos_cubados_package'
)
);
return $settings;
}

public function get_pickup_settings() {
include_once('classes/TipoSeguro.php');

Expand Down

0 comments on commit bc198d4

Please sign in to comment.