fix order history
This commit is contained in:
parent
eddf81659d
commit
59ed1b87cc
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -796,9 +809,9 @@ class ICrmOrderActions
|
||||
$p['DISCOUNT_PRICE'] = null;
|
||||
|
||||
$items[] = array(
|
||||
'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'],
|
||||
'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'],
|
||||
'purchasePrice' => $pr,
|
||||
'discount' => $p['DISCOUNT_PRICE'],
|
||||
'discount' => $p['DISCOUNT_PRICE'],
|
||||
'discountPercent' => $p['DISCOUNT_VALUE'],
|
||||
'quantity' => $p['QUANTITY'],
|
||||
'productId' => $p['PRODUCT_ID'],
|
||||
|
Loading…
Reference in New Issue
Block a user