1
0
mirror of synced 2025-03-28 02:53:54 +03:00

Change logic work with delivery cost

This commit is contained in:
Dima Uryvskiy 2022-07-20 14:50:15 +03:00 committed by GitHub
parent f287ce8aa1
commit ebdc410fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 92 additions and 16 deletions

View File

@ -1,3 +1,12 @@
## 2022-07-18 4.4.5
* Change logic work with delivery cost
* Add price rounding from WC settings
* Add functionality for changing the time interval for cron tasks
* Fix error with empty 'paidAt'
* Change processing history by sinceId
* Fix spanish accents processing in ICML
* Fix WA icon positioning
## 2022-05-26 4.4.4 ## 2022-05-26 4.4.4
* Add product description to ICML * Add product description to ICML
* Fix fatal error using API without api_key * Fix fatal error using API without api_key

View File

@ -1 +1 @@
4.4.4 4.4.5

View File

@ -341,12 +341,12 @@ if (!class_exists('WC_Retailcrm_History')) :
$shipping->set_method_id($options[$order['delivery']['code']]); $shipping->set_method_id($options[$order['delivery']['code']]);
} }
if (isset($order['delivery']['cost']) && !wc_tax_enabled()) { if (wc_tax_enabled()) {
$shipping->set_total($order['delivery']['cost']); $rate = getShippingRates();
}
if (!empty($order['delivery']['netCost']) && wc_tax_enabled()) { $shipping->set_total($this->getDeliveryCost($order, $rate));
$shipping->set_total($order['delivery']['netCost']); } else {
$shipping->set_total($this->getDeliveryCost($order));
} }
if (isset($order['delivery']['service']['code'])) { if (isset($order['delivery']['service']['code'])) {
@ -881,15 +881,17 @@ if (!class_exists('WC_Retailcrm_History')) :
} }
} }
if (isset($order['delivery']['cost']) && !wc_tax_enabled()) { if (wc_tax_enabled()) {
$shipping->set_total($order['delivery']['cost']); $rate = getShippingRates();
} elseif (isset($order['delivery']['netCost'])) {
$shipping->set_total($order['delivery']['netCost']); $shipping->set_total($this->getDeliveryCost($order, $rate));
} else {
$shipping->set_total($this->getDeliveryCost($order));
} }
$shipping->set_order_id($wcOrder->get_id()); $shipping->set_order_id($wcOrder->get_id());
$shipping->save(); $shipping->save();
$wcOrder->add_item($shipping); $wcOrder->add_item($shipping);
} }
} }
@ -1134,6 +1136,26 @@ if (!class_exists('WC_Retailcrm_History')) :
return $handled; return $handled;
} }
/**
* Get delivery cost for WC order
*
* @param array $order
*
* @return double
*/
private function getDeliveryCost($order, $rate = null)
{
$deliveryCost = $order['delivery']['cost'] ?? 0.0;
if (empty($rate) || empty($deliveryCost)) {
return $deliveryCost;
}
$decimalPlaces = wc_get_price_decimals();
return round($deliveryCost / (1 + $rate / 100), $decimalPlaces);
}
/** /**
* Get custom fields mapping with settings. * Get custom fields mapping with settings.
* *

View File

@ -375,9 +375,14 @@ if (!class_exists('WC_Retailcrm_Orders')) :
if (isset($shipping['total'])) { if (isset($shipping['total'])) {
$orderData['delivery']['netCost'] = $shipping['total']; $orderData['delivery']['netCost'] = $shipping['total'];
$orderData['delivery']['cost'] = isset($shipping['total_tax'])
? $shipping['total'] + $shipping['total_tax']
: $shipping['total'];
if (isset($shipping['total_tax'])) { $rate = getShippingRates();
$orderData['delivery']['cost'] = $shipping['total'] + $shipping['total_tax'];
if (!empty($rate)) {
$orderData['delivery']['vatRate'] = $rate;
} }
} }
} }

View File

@ -150,3 +150,19 @@ function validateUrl(string $url)
return (preg_match("/https:\/\/(.*).(retailcrm.(pro|ru|es)|simla.com)/", $url)) ? $url : ''; return (preg_match("/https:\/\/(.*).(retailcrm.(pro|ru|es)|simla.com)/", $url)) ? $url : '';
} }
/**
* Get shipping rate.
*
* @return mixed
*/
function getShippingRates()
{
$shippingRates = WC_Tax::get_shipping_tax_rates();
// Only one tax can be selected for shipping
if (is_array($shippingRates)) {
$shippingRates = array_shift($shippingRates);
}
return $shippingRates['rate'] ?? $shippingRates;
}

View File

@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
Requires PHP: 5.6 Requires PHP: 5.6
Requires at least: 5.3 Requires at least: 5.3
Tested up to: 5.9 Tested up to: 5.9
Stable tag: 4.4.4 Stable tag: 4.4.5
License: GPLv1 or later License: GPLv1 or later
License URI: http://www.gnu.org/licenses/gpl-1.0.html License URI: http://www.gnu.org/licenses/gpl-1.0.html
@ -82,6 +82,15 @@ Asegúrate de tener una clave API específica para cada tienda. Las siguientes i
== Changelog == == Changelog ==
= 4.4.5 =
* Change logic work with delivery cost
* Add price rounding from WC settings
* Add functionality for changing the time interval for cron tasks
* Fix error with empty 'paidAt'
* Change processing history by sinceId
* Fix spanish accents processing in ICML
* Fix WA icon positioning
= 4.4.4 = = 4.4.4 =
* Add product description to ICML * Add product description to ICML
* Fix fatal error using API without api_key * Fix fatal error using API without api_key

View File

@ -5,7 +5,7 @@
* Description: Integration plugin for WooCommerce & Simla.com * Description: Integration plugin for WooCommerce & Simla.com
* Author: RetailDriver LLC * Author: RetailDriver LLC
* Author URI: http://retailcrm.pro/ * Author URI: http://retailcrm.pro/
* Version: 4.4.4 * Version: 4.4.5
* Tested up to: 5.9 * Tested up to: 5.9
* WC requires at least: 5.4 * WC requires at least: 5.4
* WC tested up to: 6.5 * WC tested up to: 6.5

View File

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

View File

@ -338,6 +338,21 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
$this->assertEquals(false, WC_Retailcrm_Orders::isCorporateOrder($this->order)); $this->assertEquals(false, WC_Retailcrm_Orders::isCorporateOrder($this->order));
} }
public function test_get_shipping_rates()
{
$rate = getShippingRates();
$this->assertEquals(null, $rate);
}
public function test_validate_url()
{
$this->assertEquals('https://test.simla.com', validateUrl('https://test.simla.com'));
// Not valid url
$this->assertEquals('', validateUrl('https://test.com'));
}
public function test_is_corporate_crm_order() public function test_is_corporate_crm_order()
{ {
$this->assertEquals( $this->assertEquals(