history fix duplicate products
This commit is contained in:
parent
3644c385b3
commit
323b67d400
@ -14,6 +14,7 @@ class ICrmOrderActions
|
|||||||
protected static $CRM_ORDER_SITES = 'sites_ids';
|
protected static $CRM_ORDER_SITES = 'sites_ids';
|
||||||
protected static $CRM_ORDER_PROPS = 'order_props';
|
protected static $CRM_ORDER_PROPS = 'order_props';
|
||||||
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
|
||||||
|
protected static $CRM_ORDER_HISTORY_DATE = 'order_history_date';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mass order uploading, without repeating; always returns true, but writes error log
|
* Mass order uploading, without repeating; always returns true, but writes error log
|
||||||
@ -298,7 +299,12 @@ class ICrmOrderActions
|
|||||||
|
|
||||||
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
$api = new IntaroCrm\RestApi($api_host, $api_key);
|
||||||
|
|
||||||
$orderHistory = $api->orderHistory();
|
$dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null);
|
||||||
|
|
||||||
|
$orderHistory = $api->orderHistory($dateStart);
|
||||||
|
|
||||||
|
if($dateStart)
|
||||||
|
$dateStart = new \DateTime($dateStart);
|
||||||
|
|
||||||
// pushing existing orders
|
// pushing existing orders
|
||||||
foreach ($orderHistory as $order) {
|
foreach ($orderHistory as $order) {
|
||||||
@ -351,7 +357,6 @@ class ICrmOrderActions
|
|||||||
if(isset($order['customer']) && $order['customer']) $userId = $order['customer'];
|
if(isset($order['customer']) && $order['customer']) $userId = $order['customer'];
|
||||||
$LID = $arFields['LID'];
|
$LID = $arFields['LID'];
|
||||||
|
|
||||||
|
|
||||||
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
|
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
|
||||||
|
|
||||||
while ($ar = $rsOrderProps->Fetch()) {
|
while ($ar = $rsOrderProps->Fetch()) {
|
||||||
@ -509,6 +514,7 @@ class ICrmOrderActions
|
|||||||
|
|
||||||
// create new
|
// create new
|
||||||
if(isset($item['created']) && $item['created']) {
|
if(isset($item['created']) && $item['created']) {
|
||||||
|
|
||||||
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], 1);
|
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], 1);
|
||||||
|
|
||||||
$arProduct = array(
|
$arProduct = array(
|
||||||
@ -546,7 +552,8 @@ class ICrmOrderActions
|
|||||||
if (isset($item['offer']['name']) && $item['offer']['name'])
|
if (isset($item['offer']['name']) && $item['offer']['name'])
|
||||||
$arProduct['NAME'] = $item['offer']['name'];
|
$arProduct['NAME'] = $item['offer']['name'];
|
||||||
|
|
||||||
CSaleBasket::Add($arProduct);
|
//CSaleBasket::Add($arProduct);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update old
|
// update old
|
||||||
@ -567,8 +574,14 @@ class ICrmOrderActions
|
|||||||
$arProduct['NAME'] = $item['offer']['name'];
|
$arProduct['NAME'] = $item['offer']['name'];
|
||||||
|
|
||||||
CSaleBasket::Update($p['ID'], $arProduct);
|
CSaleBasket::Update($p['ID'], $arProduct);
|
||||||
|
CSaleBasket::DeleteAll($userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$dateInsert = new \DateTime($arFields['DATE_INSERT']);
|
||||||
|
|
||||||
|
if(!$dateStart || ($dateInsert > $dateStart))
|
||||||
|
$dateStart = $dateInsert;
|
||||||
|
|
||||||
// orderUpdate
|
// orderUpdate
|
||||||
$arFields = self::clearArr(array(
|
$arFields = self::clearArr(array(
|
||||||
'PRICE_DELIVERY' => $order['deliveryCost'],
|
'PRICE_DELIVERY' => $order['deliveryCost'],
|
||||||
@ -591,6 +604,9 @@ class ICrmOrderActions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(count($orderHistory))
|
||||||
|
COption::SetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, $dateStart->format('Y-m-d H:i:s'));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user