From d929a1fd5f5f0fa180bde4e25b46a1832b26d4e4 Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Wed, 28 Dec 2022 10:36:03 +0300 Subject: [PATCH] ref #87089 Fix bug with products tax (#295) --- CHANGELOG.md | 3 +++ VERSION | 2 +- src/include/class-wc-retailcrm-history.php | 14 ++++++-------- src/include/functions.php | 9 +++++---- src/readme.txt | 5 ++++- src/retailcrm.php | 2 +- src/uninstall.php | 2 +- 7 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 115a63b..4932db5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2022-12-26 4.5.3 +* Fix bug with products tax + ## 2022-11-09 4.5.2 * Add validator for CRM URL diff --git a/VERSION b/VERSION index 689f7fb..ae6e65b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.5.2 \ No newline at end of file +4.5.3 \ 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 e25eecc..767dfcb 100644 --- a/src/include/class-wc-retailcrm-history.php +++ b/src/include/class-wc-retailcrm-history.php @@ -1066,18 +1066,16 @@ if (!class_exists('WC_Retailcrm_History')) : $wcOrderItem->save(); } - // Be aware that discounts may be added. if (!empty($crmProduct['summ'])) { if (wc_tax_enabled()) { - $shippingTaxClass = get_option('woocommerce_shipping_tax_class'); + $wcOrder = wc_get_order($wcOrderItem->get_order_id()); + $itemRate = getOrderItemRate($wcOrder); - $wcOrder = wc_get_order($wcOrderItem->get_order_id()); - $itemRate = $shippingTaxClass == 'inherit' - ? getOrderItemRate($wcOrder) - : getShippingRate(); - $itemPrice = calculatePriceExcludingTax($crmProduct['summ'], $itemRate); + if ($itemRate === null) { + $itemRate = getShippingRate(); + } - $wcOrderItem->set_total($itemPrice); + $wcOrderItem->set_total(calculatePriceExcludingTax($crmProduct['summ'], $itemRate)); } else { $wcOrderItem->set_total($crmProduct['summ']); } diff --git a/src/include/functions.php b/src/include/functions.php index 663d273..893e2d7 100644 --- a/src/include/functions.php +++ b/src/include/functions.php @@ -138,7 +138,10 @@ function is_wplogin() } /** - * Get shipping rate. + * If a tax class with a standart rate is selected, woocommerce_shipping_tax_class = '' + * If a tax class with a zero rate is selected, woocommerce_shipping_tax_class = zero-rate + * If a tax class with a reduced rate is selected, woocommerce_shipping_tax_class = reduced-rate + * If the tax is calculated based on the items in the cart, woocommerce_shipping_tax_class = inherit * * @return mixed */ @@ -176,9 +179,7 @@ function getOrderItemRate($wcOrder) function calculatePriceExcludingTax($priceIncludingTax, $rate) { - $decimalPlaces = wc_get_price_decimals(); - - return round($priceIncludingTax / (1 + $rate / 100), $decimalPlaces); + return round($priceIncludingTax / (1 + $rate / 100), wc_get_price_decimals()); } /** diff --git a/src/readme.txt b/src/readme.txt index 4aef4a0..8ab01a3 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla Requires PHP: 7.0 Requires at least: 5.3 Tested up to: 6.0 -Stable tag: 4.5.2 +Stable tag: 4.5.3 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.5.3 = +* Fix bug with products tax + = 4.5.2 = * Add validator for CRM URL diff --git a/src/retailcrm.php b/src/retailcrm.php index 62799a0..adcd1fc 100644 --- a/src/retailcrm.php +++ b/src/retailcrm.php @@ -5,7 +5,7 @@ * Description: Integration plugin for WooCommerce & Simla.com * Author: RetailDriver LLC * Author URI: http://retailcrm.pro/ - * Version: 4.5.2 + * Version: 4.5.3 * Tested up to: 6.0 * WC requires at least: 5.4 * WC tested up to: 6.9 diff --git a/src/uninstall.php b/src/uninstall.php index d24f6ea..585f4cb 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -16,7 +16,7 @@ * * @link https://wordpress.org/plugins/woo-retailcrm/ * - * @version 4.5.2 + * @version 4.5.3 * * @package RetailCRM */