1
0
mirror of synced 2024-11-25 23:06:08 +03:00

ready for product statuses

This commit is contained in:
Ilyas Salikhov 2013-12-25 16:30:46 +04:00
parent be1041a38f
commit deac6e4cb4

View File

@ -16,6 +16,8 @@ class ICrmOrderActions
protected static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
protected static $CRM_ORDER_HISTORY_DATE = 'order_history_date';
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
/**
* Mass order uploading, without repeating; always returns true, but writes error log
* @param $failed -- flag to export failed orders
@ -248,6 +250,28 @@ class ICrmOrderActions
return true; //all ok!
}
protected static function updateCancelProp($arProduct, $value) {
$propUpdated = false;
foreach($arProduct['PROPS'] as $key => $item) {
if ($item['CODE'] == self::CANCEL_PROPERTY_CODE) {
$arProduct['PROPS'][$key]['VALUE'] = $value;
$propUpdated = true;
break;
}
}
if (!$propUpdated) {
$arProduct['PROPS'][] = array(
'NAME' => 'Товар в статусе отмены',
'CODE' => self::CANCEL_PROPERTY_CODE,
'VALUE' => $value,
'SORT' => 10,
);
}
return $arProduct;
}
/**
*
* History update
@ -556,10 +580,24 @@ class ICrmOrderActions
$p = CSaleBasket::GetList(
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 (!$p) {
$p = CIBlockElement::GetByID($item['offer']['externalId'])->Fetch();
$p[self::CANCEL_PROPERTY_CODE] = 0;
}
else {
//for basket props updating (in props we save cancel status)
$propResult = CSaleBasket::GetPropsList(
array(),
array('BASKET_ID' => $p['ID'])
);
while($r = $propResult->Fetch()) {
$p['PROPS'][] = $r;
}
}
// change existing basket items
$arProduct = array();
@ -608,10 +646,19 @@ class ICrmOrderActions
if (isset($item['offer']['name']) && $item['offer']['name'])
$arProduct['NAME'] = self::fromJSON($item['offer']['name']);
if (isset($item['isCanceled'])) {
//for product excluding from order
$arProduct['PRICE'] = 0;
self::updateCancelProp($arProduct, 1);
}
CSaleBasket::Add($arProduct);
continue;
}
$arProduct['PROPS'] = $p['PROPS'];
if (!isset($item['isCanceled']) {
// update old
if (isset($item['initialPrice']) && $item['initialPrice'])
$arProduct['PRICE'] = (double) $item['initialPrice'];
@ -629,6 +676,15 @@ class ICrmOrderActions
if(isset($item['discount']) || isset($item['discountPercent']))
$arProduct['PRICE'] -= $arProduct['DISCOUNT_PRICE'];
self::updateCancelProp($arProduct, 0);
}
else {
//for product excluding from order
$arProduct['PRICE'] = 0;
self::updateCancelProp($arProduct, 1);
}
if (isset($item['quantity']) && $item['quantity'])
$arProduct['QUANTITY'] = $item['quantity'];
@ -877,6 +933,15 @@ class ICrmOrderActions
$rsOrderBasket = CSaleBasket::GetList(array('PRODUCT_ID' => 'ASC'), array('ORDER_ID' => $arFields['ID']));
while ($p = $rsOrderBasket->Fetch()) {
//for basket props updating (in props we save cancel status)
$propCancel = CSaleBasket::GetPropsList(
array(),
array('BASKET_ID' => $p['ID'], 'CODE' => self::CANCEL_PROPERTY_CODE)
)->Fetch();
if ($propCancel) {
$propCancel = (int)$propCancel['VALUE'];
}
$pr = CCatalogProduct::GetList(array('ID' => $p['PRODUCT_ID']))->Fetch();
if ($pr)
$pr = $pr['PURCHASING_PRICE'];
@ -884,14 +949,17 @@ class ICrmOrderActions
$pr = '';
$items[] = array(
'initialPrice' => (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'],
//'purchasePrice' => $pr,
'discount' => $p['DISCOUNT_PRICE'],
'discountPercent' => 0,
'quantity' => $p['QUANTITY'],
'productId' => $p['PRODUCT_ID'],
'productName' => self::toJSON($p['NAME'])
);
//if it is canceled product don't send price
if (!$propCancel) {
$items['initialPrice'] = (double) $p['PRICE'] + (double) $p['DISCOUNT_PRICE'];
$items['discount'] => $p['DISCOUNT_PRICE']
}
}
if($arFields['CANCELED'] == 'Y')