diff --git a/CHANGELOG.md b/CHANGELOG.md index f80518c..459a697 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2022-09-02 4.4.8 +* Fix a critical bug when working with taxes + ## 2022-08-10 4.4.7 * Add support for payment method on delivery diff --git a/VERSION b/VERSION index 3401474..bc30b06 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.4.7 \ No newline at end of file +4.4.8 \ No newline at end of file diff --git a/src/include/class-wc-retailcrm-history.php b/src/include/class-wc-retailcrm-history.php index 77c4318..34bb4a2 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -342,7 +342,7 @@ if (!class_exists('WC_Retailcrm_History')) : } if (wc_tax_enabled()) { - $rate = getShippingRates(); + $rate = getShippingRate(); $shipping->set_total($this->getDeliveryCost($order, $rate)); } else { @@ -882,7 +882,7 @@ if (!class_exists('WC_Retailcrm_History')) : } if (wc_tax_enabled()) { - $rate = getShippingRates(); + $rate = getShippingRate(); $shipping->set_total($this->getDeliveryCost($order, $rate)); } else { diff --git a/src/include/class-wc-retailcrm-orders.php b/src/include/class-wc-retailcrm-orders.php index 66f516b..e786137 100644 --- a/src/include/class-wc-retailcrm-orders.php +++ b/src/include/class-wc-retailcrm-orders.php @@ -380,9 +380,13 @@ if (!class_exists('WC_Retailcrm_Orders')) : : $shipping['total']; if (wc_tax_enabled()) { - $rate = getShippingRates(); + $shippingTaxClass = get_option('woocommerce_shipping_tax_class'); - if (!empty($rate)) { + $rate = $shippingTaxClass == 'inherit' + ? $this->getOrderItemRate($order) + : getShippingRate(); + + if ($rate !== null) { $orderData['delivery']['vatRate'] = $rate; } } @@ -502,6 +506,20 @@ if (!class_exists('WC_Retailcrm_Orders')) : return $this->payment; } + /** + * @return mixed + */ + private function getOrderItemRate($order) + { + $orderItemTax = $order->get_taxes(); + + if (is_array($orderItemTax)) { + $orderItemTax = array_shift($orderItemTax); + } + + return $orderItemTax instanceof WC_Order_Item_Tax ? $orderItemTax->get_rate_percent() : null; + } + /** * Returns true if provided order is for corporate customer * diff --git a/src/include/functions.php b/src/include/functions.php index e8f4cf3..8b6b5fe 100644 --- a/src/include/functions.php +++ b/src/include/functions.php @@ -155,8 +155,12 @@ function validateUrl(string $url) * * @return mixed */ -function getShippingRates() +function getShippingRate() { + if (!isset(WC()->cart)) { + return null; + } + $shippingRates = WC_Tax::get_shipping_tax_rates(); // Only one tax can be selected for shipping diff --git a/src/readme.txt b/src/readme.txt index 36a948d..37d0779 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -4,8 +4,8 @@ Donate link: https://www.simla.com Tags: Интеграция, Simla.com, simla Requires PHP: 5.6 Requires at least: 5.3 -Tested up to: 5.9 -Stable tag: 4.4.7 +Tested up to: 6.0 +Stable tag: 4.4.8 License: GPLv1 or later License URI: http://www.gnu.org/licenses/gpl-1.0.html @@ -82,6 +82,9 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i == Changelog == += 4.4.8 = +* Fix a critical bug when working with taxes + = 4.4.7 = * Add support for payment method on delivery diff --git a/src/retailcrm.php b/src/retailcrm.php index 01feee3..92fd4bc 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,8 +5,8 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.4.7 - * Tested up to: 5.9 + * Version: 4.4.8 + * Tested up to: 6.0 * WC requires at least: 5.4 * WC tested up to: 6.7 * Text Domain: retailcrm diff --git a/src/uninstall.php b/src/uninstall.php index 22594ad..743315e 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.4.7 + * @version 4.4.8 * * @package RetailCRM */ diff --git a/tests/test-wc-retailcrm-orders.php b/tests/test-wc-retailcrm-orders.php index d5d9ab5..04a8bc5 100644 --- a/tests/test-wc-retailcrm-orders.php +++ b/tests/test-wc-retailcrm-orders.php @@ -423,7 +423,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper public function test_get_shipping_rates() { - $rate = getShippingRates(); + $rate = getShippingRate(); $this->assertEquals(null, $rate); }