1
0
mirror of synced 2024-11-25 14:56:09 +03:00

new orders create

This commit is contained in:
Grisha Pomadchin 2013-10-02 17:45:28 +04:00
parent 0d8d174980
commit 8508c6bebb

View File

@ -279,6 +279,11 @@ class ICrmOrderActions
return true;
}
$defaultSiteId = 0;
$rsSites = CSite::GetList($by, $sort, array('DEF' => 'Y'));
while ($ar = $rsSites->Fetch())
$defaultSiteId = $ar['LID'];
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
@ -297,21 +302,24 @@ class ICrmOrderActions
// pushing existing orders
foreach ($orderHistory as $order) {
var_dump($order);
// выбрасываем заказы от 'новых клиентов'
if(!isset($order['customer']) && !$order['customer'])
continue;
if(!isset($order['externalId']) && !$order['externalId']) {
continue;
// new order
/*array(
'LID' => SITE_ID, //<----!
'PERSON_TYPE_ID' => 1, // <------!
$newOrderFields = array(
'LID' => $defaultSiteId, //<----!
'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], // <------!
'PAYED' => 'N',
'CANCELED' => 'N',
'STATUS_ID' => 'N',
'PRICE' => 0,
'CURRENCY' => 'RUB',
'USER_ID' => IntVal($USER->GetID()), // <--------!
'USER_ID' => $order['customer'], // <--------!
'PAY_SYSTEM_ID' => 0,
'PRICE_DELIVERY' => 0,
'DELIVERY_ID' => 0,
@ -319,17 +327,18 @@ class ICrmOrderActions
'USER_DESCRIPTION' => ''
);
$order['externalId'] = CSaleOrder::Add(array());
if(isset($order['number']) && $order['number'])
$newOrderFields['ACCOUNT_NUMBER'] = $order['number'];
$api->orderFixExternalIds(array($order['id'], $order['externalId']));
$order['externalId'] = CSaleOrder::Add($newOrderFields);
$api->orderFixExternalIds(array(array('id' => $order['id'], 'externalId' => $order['externalId'])));
if ($api->getStatusCode() != 200) {
//handle err - write log & continue
self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds', $api->getLastError());
continue;
}
*/
}
if(isset($order['externalId']) && $order['externalId']) {
@ -347,6 +356,8 @@ class ICrmOrderActions
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) {
if($order['externalId'] == 45)
var_dump($ar);
if (isset($order['deliveryAddress']) && $order['deliveryAddress']) {
switch ($ar['CODE']) {
case 'CITY': if (isset($order['deliveryAddress']['city']))
@ -479,13 +490,24 @@ class ICrmOrderActions
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['fio'],
implode(" ", $contactName), $order['externalId']);
/*foreach($order['items'] as $item) {
foreach($order['items'] as $item) {
if(!isset($item['offer']) && !$item['offer']['externalId'])
continue;
$p = CSaleBasket::GetList(
array('PRODUCT_ID' => 'ASC'),
array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch();
if(!$p) // if not found
continue;
if(!$p)
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
var_dump($p);
var_dump(GetCatalogProductPrice($item['offer']['externalId'], 1));
//if(!$p) // if not found
// continue;
//echo 1;
// del from basket
if(isset($item['deleted']) && $item['deleted']) {
@ -494,18 +516,19 @@ class ICrmOrderActions
}
// change existing basket items
if(!isset($item['offer']) && !$item['offer']['externalId'])
continue;
$arProduct = array();
// create new
if(isset($item['created']) && $item['created']) {
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], 1);
$arProduct = array(
'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'],
'QUANTITY' => $item['quantity'],
'CURRENCY' => $p['CURRENCY'],
'CURRENCY' => $productPrice['CURRENCY'],
'LID' => $LID,
'PRODUCT_ID' => $item['offer']['externalId'],
'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'],
@ -536,10 +559,14 @@ class ICrmOrderActions
if (isset($item['offer']['name']) && $item['offer']['name'])
$arProduct['NAME'] = $item['offer']['name'];
CSaleBasket::Add($arProduct);
continue;
var_dump($arProduct);
var_dump(CSaleBasket::Add($arProduct));
//continue;
}
if ($p) {
// update old
if (isset($item['initialPrice']) && $item['initialPrice'])
$arProduct['PRICE'] = (double) $item['initialPrice'];
@ -558,7 +585,8 @@ class ICrmOrderActions
$arProduct['NAME'] = $item['offer']['name'];
CSaleBasket::Update($p['ID'], $arProduct);
}*/
}
}
// orderUpdate
$arFields = self::clearArr(array(
@ -806,6 +834,8 @@ class ICrmOrderActions
'managerComment' => $arFields['COMMENTS'],
'createdAt' => $createdAt,
'deliveryAddress' => $resOrderDeliveryAddress,
'discount' => $arFields['DISCOUNT_PRICE'],
'discountPercent' => $arFields['DISCOUNT_VALUE'],
'items' => $items
);