1
0
mirror of synced 2024-11-22 05:16:09 +03:00

fix order history

This commit is contained in:
Grisha Pomadchin 2013-10-09 19:24:28 +04:00
parent eddf81659d
commit 59ed1b87cc

View File

@ -301,20 +301,25 @@ class ICrmOrderActions
$dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null);
var_dump($dateStart);
$orderHistory = $api->orderHistory($dateStart);
var_dump($orderHistory);
if($dateStart)
$dateStart = new \DateTime($dateStart);
// pushing existing orders
foreach ($orderHistory as $order) {
// выбрасываем заказы от 'новых клиентов'
if(!isset($order['customer']) && !$order['customer'])
continue;
var_dump($order['externalId']);
if(!isset($order['externalId']) && !$order['externalId']) {
// we dont need new orders without any customers
if(!isset($order['customer']) && !$order['customer'])
continue;
// new order
$newOrderFields = array(
'LID' => $defaultSiteId, //<----!
@ -493,6 +498,19 @@ class ICrmOrderActions
implode(" ", $contactName), $order['externalId']);
foreach($order['items'] as $item) {
var_dump($item);
// del from basket
if(isset($item['deleted']) && $item['deleted']) {
$p = CSaleBasket::GetList(
array('PRODUCT_ID' => 'ASC'),
array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['id']))->Fetch();
if($p)
CSaleBasket::Delete($p['ID']);
continue;
}
if(!isset($item['offer']) && !$item['offer']['externalId'])
continue;
@ -503,12 +521,6 @@ class ICrmOrderActions
if(!$p)
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
// del from basket
if(isset($item['deleted']) && $item['deleted']) {
CSaleBasket::Delete($p['ID']);
continue;
}
// change existing basket items
$arProduct = array();
@ -552,7 +564,8 @@ class ICrmOrderActions
if (isset($item['offer']['name']) && $item['offer']['name'])
$arProduct['NAME'] = $item['offer']['name'];
//CSaleBasket::Add($arProduct);
CSaleBasket::Add($arProduct);
continue;
}
@ -561,7 +574,7 @@ class ICrmOrderActions
$arProduct['PRICE'] = (double) $item['initialPrice'];
if (isset($item['dicount']) && $item['discount']) {
$arProduct['PRICE'] = $arProducts['PRICE'] - (double) $item['disount'];
$arProduct['PRICE'] = $arProduct['PRICE'] - (double) $item['disount'];
$arProduct['DISCOUNT_PRICE'] = $item['discount'];
}
@ -570,6 +583,9 @@ class ICrmOrderActions
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
}
if (isset($item['quantity']) && $item['quantity'])
$arProduct['QUANTITY'] = $item['quantity'];
if (isset($item['offer']['name']) && $item['offer']['name'])
$arProduct['NAME'] = $item['offer']['name'];
@ -577,11 +593,6 @@ class ICrmOrderActions
CSaleBasket::DeleteAll($userId);
}
$dateInsert = new \DateTime($arFields['DATE_INSERT']);
if(!$dateStart || ($dateInsert > $dateStart))
$dateStart = $dateInsert;
// orderUpdate
$arFields = self::clearArr(array(
'PRICE_DELIVERY' => $order['deliveryCost'],
@ -601,6 +612,8 @@ class ICrmOrderActions
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
CSaleOrder::Update($order['externalId'], $arFields);
$dateStart = new \DateTime();
}
}