Added support WooCommerce 8.2 (HPOS) (#319)
This commit is contained in:
parent
f49cc3870d
commit
a0d681509d
@ -1,3 +1,6 @@
|
||||
## 2023-12-07 4.7.0
|
||||
* Added support WooCommerce 8.2 (HPOS)
|
||||
|
||||
## 2023-11-20 4.6.14
|
||||
* Fix module activation/deactivation
|
||||
|
||||
|
@ -144,11 +144,10 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
|
||||
),
|
||||
];
|
||||
|
||||
foreach (get_post_statuses() as $status_key => $status_value) {
|
||||
$this->form_fields['p_' . $status_key] = [
|
||||
'title' => $status_value,
|
||||
foreach (get_post_statuses() as $statusKey => $statusValue) {
|
||||
$this->form_fields['p_' . $statusKey] = [
|
||||
'title' => $statusValue,
|
||||
'label' => ' ',
|
||||
'description' => '',
|
||||
'class' => 'checkbox',
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
|
@ -170,30 +170,32 @@ class WC_Retailcrm_Response implements \ArrayAccess
|
||||
return $this->response[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns error string. If there's multiple errors present - they will be squashed into single string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorString()
|
||||
{
|
||||
if ($this->offsetExists('error')) {
|
||||
return (string) $this->response['error'];
|
||||
} elseif ($this->offsetExists('errors') && is_array($this->response['errors'])) {
|
||||
$errorMessage = '';
|
||||
/**
|
||||
* Returns error string. If there's multiple errors present - they will be squashed into single string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getErrorString()
|
||||
{
|
||||
if ($this->offsetExists('errorMsg')) {
|
||||
return (string) $this->response['errorMsg'];
|
||||
}
|
||||
|
||||
foreach ($this->response['errors'] as $error) {
|
||||
$errorMessage .= $error . ' >';
|
||||
}
|
||||
if (is_array($this->response['errors']) && $this->offsetExists('errors')) {
|
||||
$errorMessage = '';
|
||||
|
||||
if (strlen($errorMessage) > 2) {
|
||||
return (string) substr($errorMessage, 0, strlen($errorMessage) - 2);
|
||||
}
|
||||
foreach ($this->response['errors'] as $error) {
|
||||
$errorMessage .= $error . ' >';
|
||||
}
|
||||
|
||||
return $errorMessage;
|
||||
}
|
||||
if (strlen($errorMessage) > 2) {
|
||||
return (string) substr($errorMessage, 0, strlen($errorMessage) - 2);
|
||||
}
|
||||
|
||||
return '';
|
||||
return $errorMessage;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -821,7 +821,11 @@ if (!class_exists('WC_Retailcrm_Base')) {
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$table = $entity === 'order' ? $wpdb->postmeta : $wpdb->usermeta;
|
||||
if ('user' === $entity) {
|
||||
$table = $wpdb->usermeta;
|
||||
} else {
|
||||
$table = useHpos() ? $wpdb->prefix . 'wc_orders_meta' : $wpdb->postmeta;
|
||||
}
|
||||
|
||||
$metaData = ['default_retailcrm' => __('Select value', 'retailcrm')];
|
||||
$sqlQuery = "SELECT DISTINCT `meta_key` FROM $table ORDER BY `meta_key`";
|
||||
|
@ -1354,7 +1354,8 @@ if (!class_exists('WC_Retailcrm_History')) :
|
||||
}
|
||||
|
||||
if ($wcObject instanceof WC_Order) {
|
||||
update_post_meta($wcObject->get_id(), $metaKey, $crmData['customFields'][$customKey]);
|
||||
$wcObject->update_meta_data($metaKey, $crmData['customFields'][$customKey]);
|
||||
$wcObject->save_meta_data();
|
||||
} else {
|
||||
update_user_meta($wcObject->get_id(), $metaKey, $crmData['customFields'][$customKey]);
|
||||
}
|
||||
|
@ -72,34 +72,40 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
/**
|
||||
* Create order. Returns wc_get_order data or error string.
|
||||
*
|
||||
* @param $order_id
|
||||
* @param $orderId
|
||||
*
|
||||
* @return bool|WC_Order|WC_Order_Refund|string
|
||||
* @return bool|WC_Order|string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function orderCreate($order_id)
|
||||
public function orderCreate($orderId)
|
||||
{
|
||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->order_payment->resetData();
|
||||
|
||||
$wcOrder = wc_get_order($order_id);
|
||||
$this->processOrder($wcOrder);
|
||||
|
||||
try {
|
||||
$this->order_payment->resetData();
|
||||
|
||||
$wcOrder = wc_get_order($orderId);
|
||||
|
||||
$this->processOrder($wcOrder);
|
||||
|
||||
$response = $this->retailcrm->ordersCreate($this->order);
|
||||
|
||||
if ($response instanceof WC_Retailcrm_Proxy) {
|
||||
if ($response->isSuccessful()) {
|
||||
return $wcOrder;
|
||||
}
|
||||
|
||||
if (!$response instanceof WC_Retailcrm_Response || !$response->isSuccessful()) {
|
||||
return $response->getErrorString();
|
||||
}
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
return $exception->getMessage();
|
||||
} catch (Throwable $exception) {
|
||||
writeBaseLogs(
|
||||
sprintf(
|
||||
'Error message: %s, file: %s on line: %s',
|
||||
$exception->getMessage(),
|
||||
$exception->getFile(),
|
||||
$exception->getLine()
|
||||
)
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $wcOrder;
|
||||
@ -252,25 +258,38 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
/**
|
||||
* Edit order in CRM
|
||||
*
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @return WC_Order $order | null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateOrder($order_id)
|
||||
public function updateOrder($orderId)
|
||||
{
|
||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$wcOrder = wc_get_order($order_id);
|
||||
try {
|
||||
$wcOrder = wc_get_order($orderId);
|
||||
|
||||
$this->processOrder($wcOrder, true);
|
||||
$this->processOrder($wcOrder, true);
|
||||
|
||||
$response = $this->retailcrm->ordersEdit($this->order);
|
||||
$response = $this->retailcrm->ordersEdit($this->order);
|
||||
|
||||
if (!empty($response) && $response->isSuccessful()) {
|
||||
$this->payment = $this->orderUpdatePaymentType($wcOrder);
|
||||
if ($response instanceof WC_Retailcrm_Response && $response->isSuccessful()) {
|
||||
$this->payment = $this->orderUpdatePaymentType($wcOrder);
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
writeBaseLogs(
|
||||
sprintf(
|
||||
'Error message: %s, file: %s on line: %s',
|
||||
$exception->getMessage(),
|
||||
$exception->getFile(),
|
||||
$exception->getLine()
|
||||
)
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $wcOrder;
|
||||
@ -337,11 +356,11 @@ if (!class_exists('WC_Retailcrm_Orders')) :
|
||||
return;
|
||||
}
|
||||
|
||||
if ($order->get_status() == 'auto-draft') {
|
||||
if ('auto-draft' === $order->get_status()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($update === true) {
|
||||
if ($update) {
|
||||
$this->orders->is_new = false;
|
||||
}
|
||||
|
||||
|
@ -59,11 +59,13 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
*/
|
||||
public function uploadSelectedOrders()
|
||||
{
|
||||
if (!empty($_GET['order_ids_retailcrm'])) {
|
||||
$ids = array_unique(explode(',', $_GET['order_ids_retailcrm']));
|
||||
|
||||
if (!empty($ids)) {
|
||||
$this->uploadArchiveOrders(0, $ids);
|
||||
$ids = $_GET['order_ids_retailcrm'];
|
||||
|
||||
if (!empty($ids)) {
|
||||
preg_match_all('/\d+/', $ids, $matches);
|
||||
|
||||
if (!empty($matches[0])) {
|
||||
$this->uploadArchiveOrders(null, $matches[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -71,29 +73,31 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
/**
|
||||
* Uploads archive order in CRM
|
||||
*
|
||||
* @param int $page Number page uploads.
|
||||
* @param array $ids Ids orders upload.
|
||||
* @param null|int $page Number page uploads.
|
||||
* @param array $ids Ids orders upload.
|
||||
*
|
||||
* @return void|null
|
||||
* @throws Exception Invalid argument exception.
|
||||
*/
|
||||
public function uploadArchiveOrders($page, $ids = array())
|
||||
public function uploadArchiveOrders($page, $ids = [])
|
||||
{
|
||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$uploadErrors = array();
|
||||
$ordersCms = $this->getCmsOrders($page, $ids);
|
||||
$orderIds = [];
|
||||
$uploadErrors = [];
|
||||
|
||||
foreach ($ordersCms as $dataOrder) {
|
||||
$orderId = $dataOrder->ID;
|
||||
if (null !== $page) {
|
||||
$orderIds = $this->getCmsOrders($page);
|
||||
} elseif ([] !== $ids) {
|
||||
$orderIds = $ids;
|
||||
}
|
||||
|
||||
foreach ($orderIds as $orderId) {
|
||||
$errorMessage = $this->orders->orderCreate($orderId);
|
||||
|
||||
if (true === is_string($errorMessage)) {
|
||||
$errorMessage = empty($errorMessage) === true
|
||||
? 'Order exist. External id: ' . $orderId
|
||||
: $errorMessage;
|
||||
if (is_string($errorMessage)) {
|
||||
$uploadErrors[$orderId] = $errorMessage;
|
||||
}
|
||||
}
|
||||
@ -118,7 +122,7 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
$users = $this->getCmsUsers($page);
|
||||
|
||||
if (false === empty($users)) {
|
||||
$dataCustomers = array();
|
||||
$dataCustomers = [];
|
||||
|
||||
foreach ($users as $user) {
|
||||
if ($this->customers->isCustomer($user) === false) {
|
||||
@ -140,20 +144,19 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
* Return orders ids
|
||||
*
|
||||
* @param integer $page Number page uploads.
|
||||
* @param array $ids Ids orders upload.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCmsOrders($page, $ids = array())
|
||||
private function getCmsOrders($page)
|
||||
{
|
||||
return get_posts(
|
||||
array(
|
||||
'numberposts' => self::RETAILCRM_COUNT_OBJECT_UPLOAD,
|
||||
'offset' => self::RETAILCRM_COUNT_OBJECT_UPLOAD * $page,
|
||||
'post_type' => wc_get_order_types('view-orders'),
|
||||
'post_status' => array_keys(wc_get_order_statuses()),
|
||||
'include' => $ids,
|
||||
)
|
||||
return wc_get_orders(
|
||||
[
|
||||
'type' => wc_get_order_types('view-orders'),
|
||||
'limit' => self::RETAILCRM_COUNT_OBJECT_UPLOAD,
|
||||
'status' => array_keys(wc_get_order_statuses()),
|
||||
'offset' => self::RETAILCRM_COUNT_OBJECT_UPLOAD * $page,
|
||||
'return' => 'ids',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -166,12 +169,16 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
{
|
||||
global $wpdb;
|
||||
|
||||
$result = $wpdb->get_results("SELECT COUNT(ID) as `count` FROM $wpdb->posts WHERE post_type = 'shop_order'");
|
||||
if (useHpos()) {
|
||||
// Use {$wpdb->prefix}, because wp_wc_orders not standard WP table
|
||||
$result = $wpdb->get_results("SELECT COUNT(ID) as `count` FROM {$wpdb->prefix}wc_orders");
|
||||
} else {
|
||||
$result = $wpdb->get_results("SELECT COUNT(ID) as `count` FROM $wpdb->posts WHERE post_type = 'shop_order'");
|
||||
}
|
||||
|
||||
return empty($result[0]->count) === false ? (int) $result[0]->count : 0;
|
||||
return $result[0]->count ? (int) $result[0]->count : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return users ids
|
||||
*
|
||||
@ -179,17 +186,16 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function getCmsUsers($page)
|
||||
private function getCmsUsers(int $page)
|
||||
{
|
||||
return get_users(
|
||||
array(
|
||||
[
|
||||
'number' => self::RETAILCRM_COUNT_OBJECT_UPLOAD,
|
||||
'offset' => self::RETAILCRM_COUNT_OBJECT_UPLOAD * $page,
|
||||
)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return count users
|
||||
*
|
||||
@ -199,10 +205,9 @@ if (class_exists('WC_Retailcrm_Uploader') === false) {
|
||||
{
|
||||
$userCount = count_users();
|
||||
|
||||
return empty($userCount['total_users']) === false ? $userCount['total_users'] : 0;
|
||||
return $userCount['total_users'] ? (int) $userCount['total_users'] : 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Array keys must be orders ID's in WooCommerce, values must be strings (error messages).
|
||||
*
|
||||
|
@ -191,3 +191,14 @@ function writeBaseLogs($message)
|
||||
{
|
||||
WC_Retailcrm_Logger::addCaller(__METHOD__, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking the use of HPOS.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
function useHpos()
|
||||
{
|
||||
return class_exists(Automattic\WooCommerce\Utilities\OrderUtil::class)
|
||||
&& Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ Donate link: https://www.simla.com
|
||||
Tags: Интеграция, Simla.com, simla
|
||||
Requires PHP: 7.0
|
||||
Requires at least: 5.3
|
||||
Tested up to: 6.2
|
||||
Stable tag: 4.6.14
|
||||
Tested up to: 6.4
|
||||
Stable tag: 4.7.0
|
||||
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.7.0 =
|
||||
* Added support WooCommerce 8.2 (HPOS)
|
||||
|
||||
= 4.6.14 =
|
||||
* Fix module activation/deactivation
|
||||
|
||||
|
@ -5,10 +5,10 @@
|
||||
* Description: Integration plugin for WooCommerce & Simla.com
|
||||
* Author: RetailDriver LLC
|
||||
* Author URI: http://retailcrm.pro/
|
||||
* Version: 4.6.14
|
||||
* Tested up to: 6.2
|
||||
* Version: 4.7.0
|
||||
* Tested up to: 6.4
|
||||
* WC requires at least: 5.4
|
||||
* WC tested up to: 7.8
|
||||
* WC tested up to: 8.3
|
||||
* Text Domain: retailcrm
|
||||
*/
|
||||
|
||||
@ -211,4 +211,10 @@ if (!class_exists( 'WC_Integration_Retailcrm')) :
|
||||
$plugin->register_deactivation_hook();
|
||||
|
||||
add_action('plugins_loaded', ['WC_Integration_Retailcrm', 'get_instance'], 0);
|
||||
|
||||
add_action('before_woocommerce_init', function() {
|
||||
if (class_exists( Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
|
||||
Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
|
||||
}
|
||||
});
|
||||
endif;
|
||||
|
@ -16,14 +16,14 @@
|
||||
*
|
||||
* @link https://wordpress.org/plugins/woo-retailcrm/
|
||||
*
|
||||
* @version 4.6.14
|
||||
* @version 4.7.0
|
||||
*
|
||||
* @package RetailCRM
|
||||
*/
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (!defined('ABSPATH')) {
|
||||
exit; // Exit if accessed directly
|
||||
exit;
|
||||
}
|
||||
|
||||
// If uninstall not called from WordPress, then exit.
|
||||
@ -31,18 +31,23 @@ if (!defined('WP_UNINSTALL_PLUGIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
wp_clear_scheduled_hook('retailcrm_icml');
|
||||
wp_clear_scheduled_hook('retailcrm_history');
|
||||
wp_clear_scheduled_hook('retailcrm_inventories');
|
||||
|
||||
// Delete options.
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'woocommerce_integration-retailcrm_settings';");
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_customers_history_since_id';");
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_orders_history_since_id';");
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_active_in_crm';");
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'retailcrm_client_id';");
|
||||
global $wpdb;
|
||||
|
||||
$options = [
|
||||
'retailcrm_client_id',
|
||||
'retailcrm_active_in_crm',
|
||||
'retailcrm_orders_history_since_id',
|
||||
'retailcrm_customers_history_since_id',
|
||||
'woocommerce_integration-retailcrm_settings',
|
||||
];
|
||||
|
||||
foreach ($options as $option) {
|
||||
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = {$option}");
|
||||
}
|
||||
|
||||
// Clear any cached data that has been removed
|
||||
wp_cache_flush();
|
||||
|
@ -100,27 +100,30 @@ class WC_Retailcrm_Test_Case_Helper extends WC_Unit_Test_Case
|
||||
} else {
|
||||
global $wpdb;
|
||||
|
||||
foreach (
|
||||
[
|
||||
$tables = [
|
||||
useHpos() ? $wpdb->prefix . 'wc_orders' : '',
|
||||
useHpos() ? $wpdb->prefix . 'wc_orders_meta' : '',
|
||||
$wpdb->posts,
|
||||
$wpdb->postmeta,
|
||||
$wpdb->comments,
|
||||
$wpdb->commentmeta,
|
||||
$wpdb->term_relationships,
|
||||
$wpdb->termmeta,
|
||||
] as $table
|
||||
) {
|
||||
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
];
|
||||
|
||||
foreach ($tables as $table) {
|
||||
if ('' === $table) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wpdb->query("DELETE FROM {$table}");
|
||||
}
|
||||
|
||||
foreach ([$wpdb->terms, $wpdb->term_taxonomy] as $table) {
|
||||
//phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
$wpdb->query("DELETE FROM {$table} WHERE term_id != 1");
|
||||
}
|
||||
|
||||
$wpdb->query("UPDATE {$wpdb->term_taxonomy} SET count = 0");
|
||||
|
||||
$wpdb->query("DELETE FROM {$wpdb->users} WHERE ID != 1");
|
||||
$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE user_id != 1");
|
||||
}
|
||||
|
@ -327,26 +327,28 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
{
|
||||
$this->deleteAllData();
|
||||
$this->regenerateMocks();
|
||||
$order_id = $this->history_order_create_for_changing_customer();
|
||||
$this->assertNotEmpty($order_id);
|
||||
|
||||
$orderId = $this->history_order_create_for_changing_customer();
|
||||
|
||||
$this->assertNotEmpty($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_customer($order_id);
|
||||
$this->history_order_switch_customer($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_customer_to_corporate($order_id);
|
||||
$this->history_order_switch_customer_to_corporate($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_customer_to_another_corporate($order_id);
|
||||
$this->history_order_switch_customer_to_another_corporate($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_only_company($order_id);
|
||||
$this->history_order_switch_only_company($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_only_contact($order_id);
|
||||
$this->history_order_switch_only_contact($orderId);
|
||||
|
||||
$this->regenerateMocks();
|
||||
$this->history_order_switch_back_to_individual($order_id);
|
||||
$this->history_order_switch_back_to_individual($orderId);
|
||||
}
|
||||
|
||||
public function history_order_create_for_changing_customer()
|
||||
@ -376,16 +378,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_customer($order_id)
|
||||
public function history_order_switch_customer(int $orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_to_another_individual($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_to_another_individual($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -396,31 +398,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('tester002', $order->get_billing_first_name());
|
||||
$this->assertEquals('tester002', $order->get_billing_last_name());
|
||||
@ -437,16 +415,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_customer_to_corporate($order_id)
|
||||
public function history_order_switch_customer_to_corporate(int $orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_to_corporate($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_to_corporate($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -462,31 +440,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('psycho913', $order->get_billing_first_name());
|
||||
$this->assertEquals('psycho913', $order->get_billing_last_name());
|
||||
@ -500,16 +454,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_customer_to_another_corporate($order_id)
|
||||
public function history_order_switch_customer_to_another_corporate($orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_to_another_corporate($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_to_another_corporate($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -525,31 +479,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('Tester4867', $order->get_billing_first_name());
|
||||
$this->assertEquals('Tester4867', $order->get_billing_last_name());
|
||||
@ -564,16 +494,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_only_company($order_id)
|
||||
public function history_order_switch_only_company(int $orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_only_company($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_only_company($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -589,31 +519,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('Tester4867', $order->get_billing_first_name());
|
||||
$this->assertEquals('Tester4867', $order->get_billing_last_name());
|
||||
@ -628,16 +534,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_only_contact($order_id)
|
||||
public function history_order_switch_only_contact(int $orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_only_contact($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_only_contact($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -653,31 +559,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('Tester2890', $order->get_billing_first_name());
|
||||
$this->assertEquals('Tester2890', $order->get_billing_last_name());
|
||||
@ -692,16 +574,16 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $orderId
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history_order_switch_back_to_individual($order_id)
|
||||
public function history_order_switch_back_to_individual(int $orderId)
|
||||
{
|
||||
$this->mockHistory(
|
||||
true,
|
||||
DataHistoryRetailCrm::empty_history(),
|
||||
DataHistoryRetailCrm::get_history_change_from_corporate_to_individual($order_id)
|
||||
DataHistoryRetailCrm::get_history_change_from_corporate_to_individual($orderId)
|
||||
);
|
||||
|
||||
$this->ordersGetMock(
|
||||
@ -712,31 +594,7 @@ class WC_Retailcrm_History_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$retailcrm_history = new \WC_Retailcrm_History($this->apiMock);
|
||||
$retailcrm_history->getHistory();
|
||||
|
||||
try {
|
||||
$order = new WC_Order($order_id);
|
||||
} catch (\Exception $exception) {
|
||||
$post = get_post($order_id);
|
||||
|
||||
if (!$post instanceof WP_Post) {
|
||||
$this->fail(sprintf('Cannot find order with id=%d', $order_id));
|
||||
}
|
||||
|
||||
if (!in_array($post->post_type, wc_get_order_types())) {
|
||||
$this->fail(sprintf(
|
||||
'Invalid order post type `%s`. Should be one of these: %s',
|
||||
$post->post_type,
|
||||
implode(', ', wc_get_order_types())
|
||||
));
|
||||
} else {
|
||||
$this->fail(sprintf(
|
||||
'Cannot determine what\'s wrong with order id=%d. Message from WooCommerce: %s',
|
||||
$order_id,
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
$order = new WC_Order($orderId);
|
||||
|
||||
$this->assertEquals('tester001', $order->get_billing_first_name());
|
||||
$this->assertEquals('tester001', $order->get_billing_last_name());
|
||||
|
@ -55,6 +55,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
*/
|
||||
public function test_order_create($retailcrm)
|
||||
{
|
||||
$this->createTestOrder();
|
||||
|
||||
if ($retailcrm) {
|
||||
$responseMock = $this->createResponseMock();
|
||||
$responseMockCustomers = $this->createResponseMock();
|
||||
@ -68,13 +70,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
]
|
||||
);
|
||||
|
||||
$this->setMockResponse($responseMock, 'isSuccessful', true);
|
||||
$this->setMockResponse($retailcrm, 'ordersCreate', $responseMock);
|
||||
$this->setMockResponse($retailcrm, 'customersCreate', $responseMock);
|
||||
$this->setMockResponse($retailcrm, 'customersList', $responseMockCustomers);
|
||||
}
|
||||
|
||||
$this->createTestOrder();
|
||||
|
||||
$retailcrmOrders = $this->getRetailcrmOrders($retailcrm);
|
||||
$order = $retailcrmOrders->orderCreate($this->order->get_id());
|
||||
$orderData = $retailcrmOrders->getOrder();
|
||||
@ -132,6 +133,8 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
*/
|
||||
public function test_order_create_with_corporate_customer($retailcrm)
|
||||
{
|
||||
$this->createTestOrder();
|
||||
|
||||
if ($retailcrm) {
|
||||
$responseMock = $this->createResponseMock();
|
||||
|
||||
@ -170,6 +173,7 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
]
|
||||
);
|
||||
|
||||
$this->setMockResponse($responseMock, 'isSuccessful', true);
|
||||
$this->setMockResponse($retailcrm, 'ordersCreate', $responseMock);
|
||||
$this->setMockResponse($retailcrm, 'getSingleSiteForKey', 'woo');
|
||||
$this->setMockResponse($retailcrm, 'customersCorporateCreate', $responseMockCustomerCorporate);
|
||||
@ -180,8 +184,6 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
$this->setMockResponse($retailcrm, 'customersCorporateCompanies', $responseMockCompany);
|
||||
}
|
||||
|
||||
$this->createTestOrder();
|
||||
|
||||
$retailcrmOrders = $this->getRetailcrmOrders($retailcrm);
|
||||
$order = $retailcrmOrders->orderCreate($this->order->get_id());
|
||||
$orderData = $retailcrmOrders->getOrder();
|
||||
@ -609,14 +611,12 @@ class WC_Retailcrm_Orders_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
}
|
||||
}
|
||||
|
||||
$this->order->add_meta_data('woo_order', 'test_custom_fields');
|
||||
$this->order->add_meta_data('crm_phone', '1111122222');
|
||||
$this->order->add_meta_data('crm_address_text', 'crm_address_text_test');
|
||||
$this->order->add_meta_data('crm_customer_comment', 'crm_customer_comment_test');
|
||||
|
||||
$this->order->save();
|
||||
|
||||
$orderId = $this->order->get_id();
|
||||
|
||||
update_post_meta($orderId, 'woo_order', 'test_custom_fields');
|
||||
update_post_meta($orderId, 'crm_phone', '1111122222');
|
||||
update_post_meta($orderId, 'crm_address_text', 'crm_address_text_test');
|
||||
update_post_meta($orderId, 'crm_customer_comment', 'crm_customer_comment_test');
|
||||
}
|
||||
|
||||
private function getResponseData($externalId)
|
||||
|
@ -87,7 +87,7 @@ class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
public function test_order_upload($retailcrm)
|
||||
{
|
||||
$retailcrm_uploader = $this->getRetailcrmUploader($retailcrm);
|
||||
$data = $retailcrm_uploader->uploadArchiveOrders(0);
|
||||
$data = $retailcrm_uploader->uploadArchiveOrders(null);
|
||||
|
||||
$this->assertEquals(null, $data);
|
||||
}
|
||||
@ -109,7 +109,6 @@ class WC_Retailcrm_Uploader_Test extends WC_Retailcrm_Test_Case_Helper
|
||||
{
|
||||
$retailcrm_uploader = $this->getRetailcrmUploader($this->apiMock);
|
||||
$count_orders = $retailcrm_uploader->getCountOrders();
|
||||
|
||||
$this->assertInternalType('int', $count_orders);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user