/**
  * Save sale discount.
  *
  * @param array &$order				Current order data.
  * @param array $discount			Discount data.
  * @return bool
  */
 public static function calculateSaleDiscount(&$order, $discount)
 {
     if (!self::$init) {
         self::init();
     }
     if (!self::isSuccess()) {
         return false;
     }
     if (!empty($order['DISCOUNT_RESULT']) && is_array($order['DISCOUNT_RESULT'])) {
         $stepResult = self::getStepResult($order);
     } else {
         $stepResult = self::getStepResultOld($order);
     }
     $applied = !empty($stepResult);
     $orderDiscountId = 0;
     $orderCouponId = '';
     if ($applied) {
         self::correctStepResult($order, $stepResult, $discount);
         if (!empty($order['DISCOUNT_DESCR']) && is_array($order['DISCOUNT_DESCR'])) {
             $discount['ACTIONS_DESCR'] = $order['DISCOUNT_DESCR'];
         }
         $discountResult = self::convertDiscount($discount);
         if (!$discountResult->isSuccess()) {
             return false;
         }
         $orderDiscountId = $discountResult->getId();
         $discountData = $discountResult->getData();
         $discount['ORDER_DISCOUNT_ID'] = $orderDiscountId;
         if ($discountData['USE_COUPONS'] == 'Y') {
             if (empty($discount['COUPON'])) {
                 return false;
             }
             $couponResult = self::convertCoupon($discount['COUPON']['COUPON'], $orderDiscountId);
             if (!$couponResult->isSuccess()) {
                 return false;
             }
             $orderCouponId = $couponResult->getId();
             Sale\DiscountCouponsManager::setApply($orderCouponId, $stepResult);
             unset($couponResult);
         }
     }
     if (array_key_exists('DISCOUNT_DESCR', $order)) {
         unset($order['DISCOUNT_DESCR']);
     }
     if (array_key_exists('DISCOUNT_RESULT', $order)) {
         unset($order['DISCOUNT_RESULT']);
     }
     self::$currentOrderData = $order;
     if ($applied && $orderCouponId != '') {
         $couponApply = Sale\DiscountCouponsManager::setApply(self::$couponsCache[$orderCouponId]['COUPON'], $stepResult);
         unset($couponApply);
     }
     if ($applied) {
         self::$discountResult['ORDER'][] = array('DISCOUNT_ID' => $orderDiscountId, 'COUPON_ID' => $orderCouponId, 'RESULT' => $stepResult);
         return true;
     }
     return false;
 }