1
0
mirror of synced 2024-11-22 13:26:10 +03:00
This commit is contained in:
Grisha Pomadchin 2014-05-19 13:41:10 +04:00
parent e04486e6db
commit 562d60bd5a
2 changed files with 65 additions and 64 deletions

View File

@ -461,6 +461,9 @@ class ICrmOrderActions
$dateFinish = $api->getGeneratedAt();
// apiv3 !
if(!$dateFinish) $dateFinish = new \DateTime();
$GLOBALS['INTARO_CRM_FROM_HISTORY'] = true;
// pushing existing orders
@ -640,16 +643,16 @@ class ICrmOrderActions
$rsOrderProps = CSaleOrderPropsValue::GetList(array(), array('ORDER_ID' => $arFields['ID']));
while ($ar = $rsOrderProps->Fetch()) {
if (isset($order['deliveryAddress']) && $order['deliveryAddress']) {
if (isset($order['delivery']) && isset($order['delivery']['address']) && $order['delivery']['address']) {
switch ($ar['CODE']) {
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['index']: if (isset($order['deliveryAddress']['index']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['index'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['index']: if (isset($order['delivery']['address']['index']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['index'])));
break;
case ($ar['CODE'] == 'CITY') or ($ar['CODE'] == 'LOCATION'): if (isset($order['deliveryAddress']['city'])) {
case ($ar['CODE'] == 'CITY') or ($ar['CODE'] == 'LOCATION'): if (isset($order['delivery']['address']['city'])) {
$prop = CSaleOrderProps::GetByID($ar['ORDER_PROPS_ID']);
if($prop['TYPE'] == 'LOCATION') {
$cityId = self::getLocationCityId(self::fromJSON($order['deliveryAddress']['city']));
$cityId = self::getLocationCityId(self::fromJSON($order['delivery']['address']['city']));
if (!$cityId)
break;
@ -657,11 +660,11 @@ class ICrmOrderActions
break;
}
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['city'])));
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['city'])));
}
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text']: if (isset($order['deliveryAddress']['text']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['text'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text']: if (isset($order['delivery']['address']['text']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['text'])));
break;
}
@ -673,26 +676,26 @@ class ICrmOrderActions
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['city']: $resOrderDeliveryAddress['city'] = self::toJSON($ar['VALUE']);
break; */
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street']: if (isset($order['deliveryAddress']['street']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['street'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street']: if (isset($order['delivery']['address']['street']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['street'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['building']: if (isset($order['deliveryAddress']['building']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['building'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['building']: if (isset($order['delivery']['address']['building']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['building'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['flat']: if (isset($order['deliveryAddress']['flat']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['flat'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['flat']: if (isset($order['delivery']['address']['flat']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['flat'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['intercomcode']: if (isset($order['deliveryAddress']['intercomcode']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['intercomcode'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['intercomcode']: if (isset($order['delivery']['address']['intercomcode']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['intercomcode'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['floor']: if (isset($order['deliveryAddress']['floor']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['floor'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['floor']: if (isset($order['delivery']['address']['floor']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['floor'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['block']: if (isset($order['deliveryAddress']['block']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['block'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['block']: if (isset($order['delivery']['address']['block']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['block'])));
break;
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['house']: if (isset($order['deliveryAddress']['house']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['deliveryAddress']['house'])));
case $optionsOrderProps[$arFields['PERSON_TYPE_ID']]['house']: if (isset($order['delivery']['address']['house']))
CSaleOrderPropsValue::Update($ar['ID'], array('VALUE' => self::fromJSON($order['delivery']['address']['house'])));
break;
}
}
@ -723,53 +726,53 @@ class ICrmOrderActions
}
// here check if smth wasnt added or new propetties
if (isset($order['deliveryAddress']) && $order['deliveryAddress']) {
if (isset($order['deliveryAddress']['index']))
if (isset($order['delivery']) && isset($order['delivery']['address']) && $order['delivery']['address']) {
if (isset($order['delivery']['address']['index']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['index'],
self::fromJSON($order['deliveryAddress']['index']), $order['externalId']);
self::fromJSON($order['delivery']['address']['index']), $order['externalId']);
if (isset($order['deliveryAddress']['city'])) {
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['city'], self::fromJSON($order['deliveryAddress']['city']), $order['externalId']);
self::addOrderProperty('CITY', self::fromJSON($order['deliveryAddress']['city']), $order['externalId']);
if (isset($order['delivery']['address']['city'])) {
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['city'], self::fromJSON($order['delivery']['address']['city']), $order['externalId']);
self::addOrderProperty('CITY', self::fromJSON($order['delivery']['address']['city']), $order['externalId']);
$cityId = self::getLocationCityId(self::fromJSON($order['deliveryAddress']['city']));
$cityId = self::getLocationCityId(self::fromJSON($order['delivery']['address']['city']));
if ($cityId)
self::addOrderProperty('LOCATION', $cityId, $order['externalId']);
else
self::addOrderProperty('LOCATION', 0, $order['externalId']);
}
if (isset($order['deliveryAddress']['text']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text'], self::fromJSON($order['deliveryAddress']['text']), $order['externalId']);
if (isset($order['delivery']['address']['text']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['text'], self::fromJSON($order['delivery']['address']['text']), $order['externalId']);
if (count($optionsOrderProps[$arFields['PERSON_TYPE_ID']]) > 4) {
if (isset($order['deliveryAddress']['street']))
if (isset($order['delivery']['address']['street']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['street'],
self::fromJSON($order['deliveryAddress']['street']), $order['externalId']);
self::fromJSON($order['delivery']['address']['street']), $order['externalId']);
if (isset($order['deliveryAddress']['building']))
if (isset($order['delivery']['address']['building']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['building'],
self::fromJSON($order['deliveryAddress']['bulding']), $order['externalId']);
self::fromJSON($order['delivery']['address']['bulding']), $order['externalId']);
if (isset($order['deliveryAddress']['flat']))
if (isset($order['delivery']['address']['flat']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['flat'],
self::fromJSON($order['deliveryAddress']['flat']), $order['externalId']);
self::fromJSON($order['delivery']['address']['flat']), $order['externalId']);
if (isset($order['deliveryAddress']['intercomcode']))
if (isset($order['delivery']['address']['intercomcode']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['intercomcode'],
self::fromJSON($order['deliveryAddress']['intercomcode']), $order['externalId']);
self::fromJSON($order['delivery']['address']['intercomcode']), $order['externalId']);
if (isset($order['deliveryAddress']['floor']))
if (isset($order['delivery']['address']['floor']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['floor'],
self::fromJSON($order['deliveryAddress']['floor']), $order['externalId']);
self::fromJSON($order['delivery']['address']['floor']), $order['externalId']);
if (isset($order['deliveryAddress']['block']))
if (isset($order['delivery']['address']['block']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['block'],
self::fromJSON($order['deliveryAddress']['block']), $order['externalId']);
self::fromJSON($order['delivery']['address']['block']), $order['externalId']);
if (isset($order['deliveryAddress']['house']))
if (isset($order['delivery']['address']['house']))
self::addOrderProperty($optionsOrderProps[$arFields['PERSON_TYPE_ID']]['house'],
self::fromJSON($order['deliveryAddress']['house']), $order['externalId']);
self::fromJSON($order['delivery']['address']['house']), $order['externalId']);
}
}
@ -937,11 +940,11 @@ class ICrmOrderActions
if($arFields['CANCELED'] == 'Y')
$wasCanaceled = true;
$resultDeliveryTypeId = $optionsDelivTypes[$order['deliveryType']];
$resultDeliveryTypeId = $optionsDelivTypes[$order['delivery']['code']];
if(isset($order['deliveryService']) && !empty($order['deliveryService'])) {
if (strpos($order['deliveryService']['code'], "-") !== false)
$deliveryServiceCode = explode("-", $order['deliveryService']['code'], 2);
if(isset($order['delivery']['service']) && !empty($order['delivery']['service'])) {
if (strpos($order['delivery']['service']['code'], "-") !== false)
$deliveryServiceCode = explode("-", $order['delivery']['service']['code'], 2);
if ($deliveryServiceCode)
$resultDeliveryTypeId = $resultDeliveryTypeId . ':' . $deliveryServiceCode[1];
@ -950,7 +953,7 @@ class ICrmOrderActions
// orderUpdate
$arFields = self::clearArr(array(
'PRICE_DELIVERY' => $order['deliveryCost'],
'PRICE' => $order['summ'] + (double) $order['deliveryCost'],
'PRICE' => $order['summ'] + (double) $order['delivery']['cost'],
'DATE_MARKED' => $order['markDatetime'],
'USER_ID' => $userId, //$order['customer']
'PAY_SYSTEM_ID' => $optionsPayTypes[$order['paymentType']],
@ -1225,13 +1228,7 @@ class ICrmOrderActions
$propCancel = (int)$propCancel['VALUE'];
}
$pr = CCatalogProduct::GetList(
array(),
array('ID' => $p['PRODUCT_ID']),
false,
array('nTopCount' => 1)
)->Fetch();
$pr = CCatalogProduct::GetList(array('ID' => $p['PRODUCT_ID']))->Fetch();
if ($pr)
$pr = $pr['PURCHASING_PRICE'];
else
@ -1249,9 +1246,6 @@ class ICrmOrderActions
if (!$propCancel) {
$item['initialPrice'] = (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'];
$item['discount'] = $p['DISCOUNT_PRICE'];
if ($pr) {
$item['purchasePrice'] = $pr;
}
}
$items[] = $item;
@ -1263,6 +1257,12 @@ class ICrmOrderActions
$createdAt = new \DateTime($arFields['DATE_INSERT']);
$createdAt = $createdAt->format('Y-m-d H:i:s');
$delivery = array(
'code' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId],
'service' => ($arParams['optionsDelivTypes'][$resultDeliveryTypeId]) ? $deliveryService : '',
'address' => $resOrderDeliveryAddress
);
$resOrder = array(
'number' => $arFields['ACCOUNT_NUMBER'],
'phone' => $resOrder['phone'],
@ -1275,14 +1275,15 @@ class ICrmOrderActions
'paymentType' => $arParams['optionsPayTypes'][$arFields['PAY_SYSTEM_ID']],
'paymentStatus' => $arParams['optionsPayment'][$arFields['PAYED']],
'orderType' => $arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']],
'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId],
'deliveryService' => ($arParams['optionsDelivTypes'][$resultDeliveryTypeId]) ? $deliveryService : '',
/*'deliveryType' => $arParams['optionsDelivTypes'][$resultDeliveryTypeId],
'deliveryService' => ($arParams['optionsDelivTypes'][$resultDeliveryTypeId]) ? $deliveryService : '',*/
'status' => $arParams['optionsPayStatuses'][$arFields['STATUS_ID']],
'statusComment' => $arFields['REASON_CANCELED'],
'customerComment' => $arFields['USER_DESCRIPTION'],
'managerComment' => $arFields['COMMENTS'],
'createdAt' => $createdAt,
'deliveryAddress' => $resOrderDeliveryAddress,
//'deliveryAddress' => $resOrderDeliveryAddress,
'delivery' => $delivery,
'discount' => $arFields['DISCOUNT_VALUE'],
'items' => $items
);

View File

@ -5,7 +5,7 @@ class RestApi
{
protected $apiUrl;
protected $apiKey;
protected $apiVersion = '2';
protected $apiVersion = '3';
protected $generatedAt;
protected $parameters;