1
0
mirror of synced 2025-01-30 23:01:43 +03:00

Fix a critical bug when working with taxes

This commit is contained in:
Dima Uryvskiy 2022-09-02 18:36:06 +03:00 committed by GitHub
parent 91a7c02e25
commit fdbac7a2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 12 deletions

View File

@ -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

View File

@ -1 +1 @@
4.4.7
4.4.8

View File

@ -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 {

View File

@ -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
*

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -16,7 +16,7 @@
*
* @link https://wordpress.org/plugins/woo-retailcrm/
*
* @version 4.4.7
* @version 4.4.8
*
* @package RetailCRM
*/

View File

@ -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);
}