1
0
mirror of synced 2024-11-22 13:26:10 +03:00

Merge branch 'history' of github.com:intarocrm/bitrix-module

This commit is contained in:
Grisha Pomadchin 2013-10-29 14:41:46 +04:00
commit b79577105a
2 changed files with 85 additions and 49 deletions

View File

@ -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
@ -279,6 +280,11 @@ class ICrmOrderActions
return true; 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_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); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);
@ -293,25 +299,32 @@ 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) {
if(!isset($order['externalId']) && !$order['externalId']) { if(!isset($order['externalId']) && !$order['externalId']) {
continue; // we dont need new orders without any customers
if(!isset($order['customer']) && !$order['customer'])
continue;
// new order // new order
/*array( $newOrderFields = array(
'LID' => SITE_ID, //<----! 'LID' => $defaultSiteId, //<----!
'PERSON_TYPE_ID' => 1, // <------! 'PERSON_TYPE_ID' => $optionsOrderTypes[$order['orderType']], // <------!
'PAYED' => 'N', 'PAYED' => 'N',
'CANCELED' => 'N', 'CANCELED' => 'N',
'STATUS_ID' => 'N', 'STATUS_ID' => 'N',
'PRICE' => 0, 'PRICE' => 0,
'CURRENCY' => 'RUB', 'CURRENCY' => 'RUB',
'USER_ID' => IntVal($USER->GetID()), // <--------! 'USER_ID' => $order['customer'], // <--------!
'PAY_SYSTEM_ID' => 0, 'PAY_SYSTEM_ID' => 0,
'PRICE_DELIVERY' => 0, 'PRICE_DELIVERY' => 0,
'DELIVERY_ID' => 0, 'DELIVERY_ID' => 0,
@ -319,17 +332,18 @@ class ICrmOrderActions
'USER_DESCRIPTION' => '' '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) { if ($api->getStatusCode() != 200) {
//handle err - write log & continue //handle err - write log & continue
self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds', $api->getLastError()); self::eventLog('ICrmOrderActions::orderHistory', 'IntaroCrm\RestApi::orderFixExternalIds', $api->getLastError());
continue; continue;
} }
*/
} }
if(isset($order['externalId']) && $order['externalId']) { if(isset($order['externalId']) && $order['externalId']) {
@ -343,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()) {
@ -479,33 +492,42 @@ class ICrmOrderActions
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['fio'], self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['fio'],
implode(" ", $contactName), $order['externalId']); implode(" ", $contactName), $order['externalId']);
/*foreach($order['items'] as $item) { foreach($order['items'] as $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;
$p = CSaleBasket::GetList( $p = CSaleBasket::GetList(
array('PRODUCT_ID' => 'ASC'), array('PRODUCT_ID' => 'ASC'),
array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch(); array('ORDER_ID' => $order['externalId'], 'PRODUCT_ID' => $item['offer']['externalId']))->Fetch();
if(!$p) // if not found if(!$p)
continue; $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
if(!isset($item['offer']) && !$item['offer']['externalId'])
continue;
$arProduct = array(); $arProduct = array();
// create new // create new
if(isset($item['created']) && $item['created']) { if(isset($item['created']) && $item['created']) {
$productPrice = GetCatalogProductPrice($item['offer']['externalId'], 1);
$arProduct = array( $arProduct = array(
'FUSER_ID' => $userId, 'FUSER_ID' => $userId,
'ORDER_ID' => $order['externalId'], 'ORDER_ID' => $order['externalId'],
'QUANTITY' => $item['quantity'], 'QUANTITY' => $item['quantity'],
'CURRENCY' => $p['CURRENCY'], 'CURRENCY' => $productPrice['CURRENCY'],
'LID' => $LID, 'LID' => $LID,
'PRODUCT_ID' => $item['offer']['externalId'], 'PRODUCT_ID' => $item['offer']['externalId'],
'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'], 'PRODUCT_PRICE_ID' => $p['PRODUCT_PRICE_ID'],
@ -538,27 +560,32 @@ class ICrmOrderActions
CSaleBasket::Add($arProduct); CSaleBasket::Add($arProduct);
continue; continue;
} }
// update old // update old
if(isset($item['initialPrice']) && $item['initialPrice']) if (isset($item['initialPrice']) && $item['initialPrice'])
$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'];
} }
if(isset($item['discountPercent']) && $item['discountPercent']) { if (isset($item['discountPercent']) && $item['discountPercent']) {
//$arProducts['PRICE'] -- how ? //$arProducts['PRICE'] -- how ?
$arProduct['DISCOUNT_VALUE'] = $item['discountPercent']; $arProduct['DISCOUNT_VALUE'] = $item['discountPercent'];
} }
if(isset($item['offer']['name']) && $item['offer']['name']) if (isset($item['quantity']) && $item['quantity'])
$arProduct['QUANTITY'] = $item['quantity'];
if (isset($item['offer']['name']) && $item['offer']['name'])
$arProduct['NAME'] = $item['offer']['name']; $arProduct['NAME'] = $item['offer']['name'];
CSaleBasket::Update($p['ID'], $arProduct); CSaleBasket::Update($p['ID'], $arProduct);
}*/ CSaleBasket::DeleteAll($userId);
}
// orderUpdate // orderUpdate
$arFields = self::clearArr(array( $arFields = self::clearArr(array(
@ -579,9 +606,14 @@ 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();
} }
} }
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;
} }
@ -771,9 +803,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'],
@ -806,6 +838,8 @@ class ICrmOrderActions
'managerComment' => $arFields['COMMENTS'], 'managerComment' => $arFields['COMMENTS'],
'createdAt' => $createdAt, 'createdAt' => $createdAt,
'deliveryAddress' => $resOrderDeliveryAddress, 'deliveryAddress' => $resOrderDeliveryAddress,
'discount' => $arFields['DISCOUNT_PRICE'],
'discountPercent' => $arFields['DISCOUNT_VALUE'],
'items' => $items 'items' => $items
); );

View File

@ -505,9 +505,11 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) {
<?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?> <?php foreach($arResult['paymentGroupList'] as $orderStatusGroup): if(!empty($orderStatusGroup['statuses'])) : ?>
<optgroup label="<?php echo $orderStatusGroup['name']; ?>"> <optgroup label="<?php echo $orderStatusGroup['name']; ?>">
<?php foreach($orderStatusGroup['statuses'] as $payment): ?> <?php foreach($orderStatusGroup['statuses'] as $payment): ?>
<option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>> <?php if(isset($arResult['paymentList'][$payment])): ?>
<?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?> <option value="<?php echo $arResult['paymentList'][$payment]['code']; ?>" <?php if ($optionsPayStatuses[$bitrixPaymentStatus['ID']] == $arResult['paymentList'][$payment]['code']) echo 'selected'; ?>>
</option> <?php echo $APPLICATION->ConvertCharset($arResult['paymentList'][$payment]['name'], 'utf-8', SITE_CHARSET); ?>
</option>
<?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
</optgroup> </optgroup>
<?php endif; endforeach; ?> <?php endif; endforeach; ?>