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