Skip to content

Commit

Permalink
Merge pull request #46 from luizbills/no-js
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbills authored Mar 2, 2023
2 parents 400380e + 34c80bf commit 40d7206
Show file tree
Hide file tree
Showing 21 changed files with 417 additions and 324 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 1.8.0 - 2023-03-02

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/1.7.0...1.8.0)

- The simulator now notifies when an error is preventing it from working correctly. An empty screen is no longer shown.

## 1.7.0 - 2023-01-16

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/1.6.0...1.7.0)
Expand Down
1 change: 1 addition & 0 deletions assets/css/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
text-align: right;
}
#wc-shipping-sim-results .no-results {
margin: 0.5em 0;
color: #c92a2a;
background-color: #fff5f5;
padding: 0.25em 0.5em;
Expand Down
17 changes: 11 additions & 6 deletions assets/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ window.addEventListener('DOMContentLoaded', () => {
const form = $('#wc-shipping-sim-form');
const input = $('.input-postcode', form);
const button = $('.button.submit', form);
const nonce = $('#nonce', form);
const nonce = $('#' + params.nonce_name, form);
const results = $('#wc-shipping-sim-results');
const I = (val) => val;
const hooks = {
Expand Down Expand Up @@ -46,21 +46,26 @@ window.addEventListener('DOMContentLoaded', () => {
}

const variation = product.variation_id
? '&variation=' + product.variation_id
? '&variation_id=' + product.variation_id
: '';
const qty = getQuantity();

const formData = config.hooks.filterFormData(
`action=${form.dataset.ajaxAction}&nonce=${
`action=${form.dataset.ajaxAction}&${params.nonce_name}=${
nonce.value
}&postcode=${input.value}&product=${product.id}&quantity=${
}&postcode=${input.value}&product_id=${product.id}&quantity=${
qty >= 1 ? qty : 1
}${variation}`
);

let xhr = new XMLHttpRequest();

xhr.open('GET', encodeURI(form.action + '?' + formData), true);
xhr.open('POST', params.ajax_url, true);

xhr.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded'
);

xhr.timeout = +config.timeout || 0;

Expand Down Expand Up @@ -93,7 +98,7 @@ window.addEventListener('DOMContentLoaded', () => {

config.hooks.beforeSubmit(xhr);

xhr.send();
xhr.send(formData);
},
inputMaskHandler: () => {
input.maxLength = config.hooks.filterPostcodeMaxLength();
Expand Down
143 changes: 0 additions & 143 deletions classes/Ajax.php

This file was deleted.

8 changes: 5 additions & 3 deletions classes/Integration/Brazil.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@

final class Brazil {
protected $state_list = null;
protected static $instace = null;
protected static $instance = null;

public static function instance () {
return self::$instace;
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}

public function __start () {
self::$instace = $this;
add_action( 'wc_shipping_simulator_load_integrations', [ $this, 'add_hooks' ] );
}

Expand Down
8 changes: 5 additions & 3 deletions classes/Integration/Correios.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
use WC_Correios_Autofill_Addresses;

final class Correios {
protected static $instace = null;
protected static $instance = null;
protected $address_cache = null;

public static function instance () {
return self::$instace;
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}

public function __start () {
self::$instace = $this;
add_action( 'wc_shipping_simulator_load_integrations', [ $this, 'add_hooks' ] );
}

Expand Down
8 changes: 5 additions & 3 deletions classes/Integration/Free_Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
use WC_Shipping_Free_Shipping;

final class Free_Shipping {
protected static $instace = null;
protected static $instance = null;

public static function instance () {
return self::$instace;
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}

public function __start () {
self::$instace = $this;
add_action( 'wc_shipping_simulator_load_integrations', [ $this, 'add_hooks' ], 10 );
}

Expand Down
8 changes: 4 additions & 4 deletions classes/Integration/Melhor_Envio.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Shipping_Simulator\Integration;

final class Melhor_Envio {
protected static $instace = null;
protected static $instance = null;

public static function instance () {
if ( null === self::$instace ) {
self::$instace = new self();
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instace;
return self::$instance;
}

public function __start () {
Expand Down
Loading

0 comments on commit 40d7206

Please sign in to comment.