Example #1
0
 public static function prepareData(Order $order)
 {
     $currencyBudget = 0;
     if ($order->getUserId() > 0) {
         $res = \CSaleUserAccount::getList(array(), array('USER_ID' => $order->getUserId(), 'CURRENCY' => $order->getCurrency(), 'LOCKED' => 'N'), false, false, array('CURRENT_BUDGET'));
         $userAccount = $res->Fetch();
         $currencyBudget = $userAccount['CURRENT_BUDGET'];
     }
     $payable = $order->getPrice() - $order->getSumPaid();
     $price = $order->getPrice();
     $sumPaid = $order->getSumPaid();
     $data = array('PRICE' => $price ? $price : 0, 'SUM_PAID' => $sumPaid ? $sumPaid : 0, 'PAYABLE' => $payable >= 0 ? $payable : 0, 'CURRENCY' => $order->getCurrency(), 'BUYER_BUDGET' => $currencyBudget, 'STATUS_ID' => $order->getField('STATUS_ID'));
     return $data;
 }
Example #2
0
 /**
  * @param null $order
  * @return array
  */
 public static function getPaySystemList($order = null)
 {
     $result = array();
     $result[] = array('ID' => '0', 'NAME' => Loc::getMessage('SALE_ORDER_PAYMENT_NO_PAYSYSTEM'));
     if ($order) {
         self::$order = $order;
     } else {
         if (!self::$order) {
             return $result;
         }
     }
     $res = \CSaleUserAccount::getList(array(), array('USER_ID' => self::$order->getUserId(), 'CURRENCY' => self::$order->getCurrency(), 'LOCKED' => 'N'), false, false, array('CURRENT_BUDGET'));
     $userAccount = $res->Fetch();
     $dbRes = PaySystemServiceTable::getListWithInner(array('select' => array('ID', 'NAME'), 'filter' => array('=ACTION.PERSON_TYPE_ID' => self::$order->getPersonTypeId(), '=ACTION.HAVE_PAYMENT' => 'Y', '=ACTIVE' => 'Y'), 'order' => array('SORT' => 'ASC')));
     while ($paySystem = $dbRes->fetch()) {
         if ($userAccount['CURRENT_BUDGET'] <= 0 && $paySystem["ID"] == PaySystemInner::getId()) {
             continue;
         }
         $result[] = array('ID' => $paySystem['ID'], 'NAME' => $paySystem["NAME"] . " [" . $paySystem["ID"] . "]");
     }
     return $result;
 }
Example #3
0
 protected function getDemandedFields(array $demandedFields, array $incomingFields, \Bitrix\Sale\Order $order = null)
 {
     $result = array();
     $userId = isset($incomingFields["USER_ID"]) && intval($incomingFields["USER_ID"]) > 0 ? intval($incomingFields["USER_ID"]) : 0;
     $currency = isset($incomingFields["CURRENCY"]) ? trim($incomingFields["CURRENCY"]) : "";
     $personTypeId = isset($incomingFields['PERSON_TYPE_ID']) ? intval($incomingFields['PERSON_TYPE_ID']) : 0;
     $orderId = isset($incomingFields["ID"]) ? intval($incomingFields["ID"]) : 0;
     if ($order === null && intval($orderId) > 0) {
         $order = \Bitrix\Sale\Order::load($orderId);
     }
     foreach ($demandedFields as $demandedField) {
         switch ($demandedField) {
             case "BUYER_USER_NAME":
                 $result["BUYER_USER_NAME"] = intval($userId) > 0 ? \Bitrix\Sale\Helpers\Admin\OrderEdit::getUserName(intval($userId)) : "";
                 break;
             case "PROPERTIES":
                 $profileId = isset($incomingFields["BUYER_PROFILE_ID"]) ? intval($incomingFields["BUYER_PROFILE_ID"]) : 0;
                 $result["PROPERTIES"] = \Bitrix\Sale\Helpers\Admin\Blocks\OrderBuyer::getProfileParams($userId, $profileId);
                 break;
             case "BUYER_PROFILES_LIST":
                 if (intval($personTypeId) <= 0) {
                     throw new \Bitrix\Main\ArgumentNullException("personTypeId");
                 }
                 $result["BUYER_PROFILES_LIST"] = \Bitrix\Sale\Helpers\Admin\Blocks\OrderBuyer::getBuyerProfilesList($userId, $personTypeId);
                 break;
             case "BUYER_PROFILES_DATA":
                 $result["BUYER_PROFILES_DATA"] = \Bitrix\Sale\Helpers\Admin\Blocks\OrderBuyer::getUserProfiles($userId);
                 break;
             case "BUYER_BUDGET":
                 $res = \CSaleUserAccount::getList(array(), array('USER_ID' => $userId, 'CURRENCY' => $currency, 'LOCKED' => 'N'), false, false, array('CURRENT_BUDGET'));
                 if ($userAccount = $res->Fetch()) {
                     $result["BUYER_BUDGET"] = $userAccount['CURRENT_BUDGET'];
                 } else {
                     $result["BUYER_BUDGET"] = 0;
                 }
                 break;
             case "PROPERTIES_ARRAY":
                 if (!$order) {
                     throw new \Bitrix\Main\SystemException("Can't init order");
                 }
                 if (intval($personTypeId) <= 0) {
                     throw new \Bitrix\Main\ArgumentNullException("personTypeId");
                 }
                 $order->setPersonTypeId($personTypeId);
                 $result["PROPERTIES_ARRAY"] = $order->getPropertyCollection()->getArray();
                 break;
             case "PRODUCT":
                 $result["PRODUCT"] = array();
                 break;
             case "COUPONS":
                 if (!$userId) {
                     throw new \Bitrix\Main\ArgumentNullException("userId");
                 }
                 $result["COUPONS"] = Admin\OrderEdit::getCouponsData();
                 break;
             case "COUPONS_LIST":
                 $result["COUPONS_LIST"] = Admin\OrderEdit::getCouponList($order);
                 break;
             default:
                 throw new \Bitrix\Main\SystemException("Field: \"" . $demandedField . "\" is unknown!");
         }
     }
     return $result;
 }