1
0
mirror of synced 2024-11-22 13:26:10 +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); $dateStart = COption::GetOptionString(self::$MODULE_ID, self::$CRM_ORDER_HISTORY_DATE, null);
var_dump($dateStart);
$orderHistory = $api->orderHistory($dateStart); $orderHistory = $api->orderHistory($dateStart);
var_dump($orderHistory);
if($dateStart) if($dateStart)
$dateStart = new \DateTime($dateStart); $dateStart = new \DateTime($dateStart);
// pushing existing orders // pushing existing orders
foreach ($orderHistory as $order) { foreach ($orderHistory as $order) {
var_dump($order['externalId']);
// выбрасываем заказы от 'новых клиентов'
if(!isset($order['customer']) && !$order['customer'])
continue;
if(!isset($order['externalId']) && !$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 // new order
$newOrderFields = array( $newOrderFields = array(
'LID' => $defaultSiteId, //<----! 'LID' => $defaultSiteId, //<----!
@ -493,6 +498,19 @@ class ICrmOrderActions
implode(" ", $contactName), $order['externalId']); implode(" ", $contactName), $order['externalId']);
foreach($order['items'] as $item) { 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']) if(!isset($item['offer']) && !$item['offer']['externalId'])
continue; continue;
@ -503,12 +521,6 @@ class ICrmOrderActions
if(!$p) if(!$p)
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch(); $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 // change existing basket items
$arProduct = array(); $arProduct = array();
@ -552,7 +564,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);
continue;
} }
@ -561,7 +574,7 @@ class ICrmOrderActions
$arProduct['PRICE'] = (double) $item['initialPrice']; $arProduct['PRICE'] = (double) $item['initialPrice'];
if (isset($item['dicount']) && $item['discount']) { 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']; $arProduct['DISCOUNT_PRICE'] = $item['discount'];
} }
@ -570,6 +583,9 @@ class ICrmOrderActions
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent']; $arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
} }
if (isset($item['quantity']) && $item['quantity'])
$arProduct['QUANTITY'] = $item['quantity'];
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'];
@ -577,11 +593,6 @@ class ICrmOrderActions
CSaleBasket::DeleteAll($userId); 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'],
@ -601,6 +612,8 @@ class ICrmOrderActions
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true; $GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
CSaleOrder::Update($order['externalId'], $arFields); CSaleOrder::Update($order['externalId'], $arFields);
$dateStart = new \DateTime();
} }
} }
@ -796,9 +809,9 @@ class ICrmOrderActions
$p['DISCOUNT_PRICE'] = null; $p['DISCOUNT_PRICE'] = null;
$items[] = array( $items[] = array(
'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'], 'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'],
'purchasePrice' => $pr, 'purchasePrice' => $pr,
'discount' => $p['DISCOUNT_PRICE'], 'discount' => $p['DISCOUNT_PRICE'],
'discountPercent' => $p['DISCOUNT_VALUE'], 'discountPercent' => $p['DISCOUNT_VALUE'],
'quantity' => $p['QUANTITY'], 'quantity' => $p['QUANTITY'],
'productId' => $p['PRODUCT_ID'], 'productId' => $p['PRODUCT_ID'],