예제 #1
0
            /// <summary>
            /// Executes the workflow to fetch the sales order and convert into a cart.
            /// </summary>
            /// <param name="request">Instance of <see cref="RecallCustomerOrderRequest"/>.</param>
            /// <returns>Instance of <see cref="RecallCustomerOrderResponse"/>.</returns>
            protected override RecallCustomerOrderResponse Process(RecallCustomerOrderRequest request)
            {
                ThrowIf.Null(request, "request");

                // Recall the customer order
                var realtimeRequest = new RecallCustomerOrderRealtimeRequest(
                    request.Id,
                    request.IsQuote);

                var serviceResponse = this.Context.Execute <RecallCustomerOrderRealtimeResponse>(realtimeRequest);

                if (serviceResponse.SalesOrder == null)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, string.Format("The order/ quote: {0} is not found.", request.Id));
                }

                // update the transaction id in sales order if the request contains transaction Id.
                if (!string.IsNullOrWhiteSpace(request.TransactionId))
                {
                    serviceResponse.SalesOrder.Id = request.TransactionId;
                }

                Cart cart = CustomerOrderWorkflowHelper.SaveTransactionAndConvertToCart(this.Context, serviceResponse.SalesOrder);

                // Return cart
                return(new RecallCustomerOrderResponse(cart));
            }
            /// <summary>
            /// Recall a customer order by sales id.
            /// </summary>
            /// <param name="request">The request containing the sales id.</param>
            /// <returns>The response containing the sales order.</returns>
            private static RecallCustomerOrderRealtimeResponse RecallCustomerOrder(RecallCustomerOrderRealtimeRequest request)
            {
                if (request == null)
                {
                    throw new ArgumentNullException("request");
                }

                var client = new TransactionServiceClient(request.RequestContext);
                ReadOnlyCollection <object> transactionResponse;

                if (request.IsQuote)
                {
                    transactionResponse = client.GetCustomerQuote(request.Id);
                }
                else
                {
                    transactionResponse = client.GetCustomerOrder(request.Id, includeOnlineOrders: true);
                }

                var orderInfo = CustomerOrderInfo.FromXml(transactionResponse[0].ToString());
                var order     = SalesOrderHelper.GetSalesOrderFromInfo(orderInfo, request.RequestContext.GetChannelConfiguration(), request.RequestContext);

                // Check that the channel currency code is the same as the recalled order
                if (order != null && !string.IsNullOrWhiteSpace(order.CurrencyCode) && !request.RequestContext.GetChannelConfiguration().Currency.Equals(order.CurrencyCode, StringComparison.OrdinalIgnoreCase))
                {
                    throw new DataValidationException(
                              DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CurrencyChannelOrderMismatch,
                              string.Format("Channel currency = {0} doesn't match sales order currency = {1}", request.RequestContext.GetChannelConfiguration().Currency, order.CurrencyCode));
                }

                var response = new RecallCustomerOrderRealtimeResponse(order);

                return(response);
            }
            /// <summary>
            /// Returns Sales Order by sales id and terminal id. Used to get remote orders from AX which does not have transaction id.
            /// </summary>
            /// <param name="salesId">The sales id parameter.</param>
            /// <returns>The  SalesOrder.</returns>
            private SalesOrder GetTransactionBySalesId(string salesId)
            {
                // Recall the customer order
                var realtimeRequest = new RecallCustomerOrderRealtimeRequest(salesId, isQuote: false);

                var        serviceResponse = this.Context.Execute <RecallCustomerOrderRealtimeResponse>(realtimeRequest);
                SalesOrder salesOrder      = serviceResponse.SalesOrder;

                // Channel and terminal don't come from ax
                salesOrder.ChannelId  = this.Context.GetPrincipal().ChannelId;
                salesOrder.TerminalId = this.Context.GetTerminal().TerminalId;

                // Perform order calculations (deposit, amount due, etc)
                CartWorkflowHelper.Calculate(this.Context, salesOrder, requestedMode: null);

                return(salesOrder);
            }