Change processing history by sinceId
This commit is contained in:
parent
b5adba84be
commit
88ca4e9c11
@ -67,6 +67,10 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
*/
|
*/
|
||||||
public function getHistory()
|
public function getHistory()
|
||||||
{
|
{
|
||||||
|
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->customersHistory();
|
$this->customersHistory();
|
||||||
$this->ordersHistory();
|
$this->ordersHistory();
|
||||||
@ -74,7 +78,7 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
WC_Retailcrm_Logger::add(
|
WC_Retailcrm_Logger::add(
|
||||||
sprintf(
|
sprintf(
|
||||||
"[%s] - %s",
|
'[%s] - %s',
|
||||||
$exception->getMessage(),
|
$exception->getMessage(),
|
||||||
'Exception in file - ' . $exception->getFile() . ' on line ' . $exception->getLine()
|
'Exception in file - ' . $exception->getFile() . ' on line ' . $exception->getLine()
|
||||||
)
|
)
|
||||||
@ -91,9 +95,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
*/
|
*/
|
||||||
protected function customersHistory()
|
protected function customersHistory()
|
||||||
{
|
{
|
||||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sinceId = get_option('retailcrm_customers_history_since_id');
|
$sinceId = get_option('retailcrm_customers_history_since_id');
|
||||||
$pagination = 1;
|
$pagination = 1;
|
||||||
@ -108,12 +109,22 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
$history = $this->getHistoryData($historyResponse);
|
$history = $this->getHistoryData($historyResponse);
|
||||||
|
|
||||||
if (!empty($history)) {
|
if (!empty($history)) {
|
||||||
$builder = new WC_Retailcrm_WC_Customer_Builder();
|
|
||||||
$lastChange = end($history);
|
$lastChange = end($history);
|
||||||
$customers = WC_Retailcrm_History_Assembler::assemblyCustomer($history);
|
|
||||||
|
|
||||||
WC_Retailcrm_Plugin::$history_run = true;
|
update_option('retailcrm_customers_history_since_id', $lastChange['id']);
|
||||||
|
|
||||||
|
$filter['sinceId'] = $lastChange['id'];
|
||||||
|
|
||||||
|
WC_Retailcrm_Logger::debug(__METHOD__, [
|
||||||
|
'Processing customers history, ID:',
|
||||||
|
$filter['sinceId']
|
||||||
|
]);
|
||||||
|
|
||||||
|
$builder = new WC_Retailcrm_WC_Customer_Builder();
|
||||||
|
$customers = WC_Retailcrm_History_Assembler::assemblyCustomer($history);
|
||||||
|
|
||||||
WC_Retailcrm_Logger::debug(__METHOD__, ['Assembled customers history:', $customers]);
|
WC_Retailcrm_Logger::debug(__METHOD__, ['Assembled customers history:', $customers]);
|
||||||
|
WC_Retailcrm_Plugin::$history_run = true;
|
||||||
|
|
||||||
foreach ($customers as $crmCustomer) {
|
foreach ($customers as $crmCustomer) {
|
||||||
/*
|
/*
|
||||||
@ -177,10 +188,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
WC_Retailcrm_Logger::error($exception->getTraceAsString());
|
WC_Retailcrm_Logger::error($exception->getTraceAsString());
|
||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
|
|
||||||
update_option('retailcrm_customers_history_since_id', $lastChange['id']);
|
|
||||||
|
|
||||||
$filter['sinceId'] = $lastChange['id'];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -197,10 +204,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
*/
|
*/
|
||||||
protected function ordersHistory()
|
protected function ordersHistory()
|
||||||
{
|
{
|
||||||
if (!$this->retailcrm instanceof WC_Retailcrm_Proxy) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$options = array_flip(array_filter($this->retailcrmSettings));
|
$options = array_flip(array_filter($this->retailcrmSettings));
|
||||||
$sinceId = get_option('retailcrm_orders_history_since_id');
|
$sinceId = get_option('retailcrm_orders_history_since_id');
|
||||||
$pagination = 1;
|
$pagination = 1;
|
||||||
@ -215,7 +218,17 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
$history = $this->getHistoryData($historyResponse);
|
$history = $this->getHistoryData($historyResponse);
|
||||||
|
|
||||||
if (!empty($history)) {
|
if (!empty($history)) {
|
||||||
$lastChange = end($history);
|
$lastChange = end($history);
|
||||||
|
|
||||||
|
update_option('retailcrm_orders_history_since_id', $lastChange['id']);
|
||||||
|
|
||||||
|
$filter['sinceId'] = $lastChange['id'];
|
||||||
|
|
||||||
|
WC_Retailcrm_Logger::debug(__METHOD__, [
|
||||||
|
'Processing orders history, ID:',
|
||||||
|
$filter['sinceId']
|
||||||
|
]);
|
||||||
|
|
||||||
$historyAssembly = WC_Retailcrm_History_Assembler::assemblyOrder($history);
|
$historyAssembly = WC_Retailcrm_History_Assembler::assemblyOrder($history);
|
||||||
|
|
||||||
WC_Retailcrm_Logger::debug(__METHOD__, ['Assembled orders history:', $historyAssembly]);
|
WC_Retailcrm_Logger::debug(__METHOD__, ['Assembled orders history:', $historyAssembly]);
|
||||||
@ -281,10 +294,6 @@ if (!class_exists('WC_Retailcrm_History')) :
|
|||||||
}
|
}
|
||||||
// @codeCoverageIgnoreEnd
|
// @codeCoverageIgnoreEnd
|
||||||
}
|
}
|
||||||
|
|
||||||
update_option('retailcrm_orders_history_since_id', $lastChange['id']);
|
|
||||||
|
|
||||||
$filter['sinceId'] = $lastChange['id'];
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user