Change logic work with delivery cost
This commit is contained in:
parent
f287ce8aa1
commit
ebdc410fda
@ -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
|
||||
* Add product description to ICML
|
||||
* Fix fatal error using API without api_key
|
||||
|
@ -341,12 +341,12 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
$shipping->set_method_id($options[$order['delivery']['code']]);
|
||||
}
|
||||
|
||||
if (isset($order['delivery']['cost']) && !wc_tax_enabled()) {
|
||||
$shipping->set_total($order['delivery']['cost']);
|
||||
}
|
||||
if (wc_tax_enabled()) {
|
||||
$rate = getShippingRates();
|
||||
|
||||
if (!empty($order['delivery']['netCost']) && wc_tax_enabled()) {
|
||||
$shipping->set_total($order['delivery']['netCost']);
|
||||
$shipping->set_total($this->getDeliveryCost($order, $rate));
|
||||
} else {
|
||||
$shipping->set_total($this->getDeliveryCost($order));
|
||||
}
|
||||
|
||||
if (isset($order['delivery']['service']['code'])) {
|
||||
@ -881,15 +881,17 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($order['delivery']['cost']) && !wc_tax_enabled()) {
|
||||
$shipping->set_total($order['delivery']['cost']);
|
||||
} elseif (isset($order['delivery']['netCost'])) {
|
||||
$shipping->set_total($order['delivery']['netCost']);
|
||||
if (wc_tax_enabled()) {
|
||||
$rate = getShippingRates();
|
||||
|
||||
$shipping->set_total($this->getDeliveryCost($order, $rate));
|
||||
} else {
|
||||
$shipping->set_total($this->getDeliveryCost($order));
|
||||
}
|
||||
|
||||
$shipping->set_order_id($wcOrder->get_id());
|
||||
|
||||
$shipping->save();
|
||||
|
||||
$wcOrder->add_item($shipping);
|
||||
}
|
||||
}
|
||||
@ -1134,6 +1136,26 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
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.
|
||||
*
|
||||
|
@ -375,9 +375,14 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
|
||||
if (isset($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'])) {
|
||||
$orderData['delivery']['cost'] = $shipping['total'] + $shipping['total_tax'];
|
||||
$rate = getShippingRates();
|
||||
|
||||
if (!empty($rate)) {
|
||||
$orderData['delivery']['vatRate'] = $rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -150,3 +150,19 @@ function validateUrl(string $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;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ Tags: Интеграция, Simla.com, simla
|
||||
Requires PHP: 5.6
|
||||
Requires at least: 5.3
|
||||
Tested up to: 5.9
|
||||
Stable tag: 4.4.4
|
||||
Stable tag: 4.4.5
|
||||
License: GPLv1 or later
|
||||
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 ==
|
||||
= 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 =
|
||||
* Add product description to ICML
|
||||
* Fix fatal error using API without api_key
|
||||
|
@ -5,7 +5,7 @@
|
||||
* Description: Integration plugin for WooCommerce & Simla.com
|
||||
* Author: RetailDriver LLC
|
||||
* Author URI: http://retailcrm.pro/
|
||||
* Version: 4.4.4
|
||||
* Version: 4.4.5
|
||||
* Tested up to: 5.9
|
||||
* WC requires at least: 5.4
|
||||
* WC tested up to: 6.5
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.4.4
|
||||
* @version 4.4.5
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
@ -338,6 +338,21 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$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()
|
||||
{
|
||||
$this->assertEquals(
|
||||
|
Loading…
x
Reference in New Issue
Block a user