Exemple #1
0
            /// <summary>
            /// Sends an email to the requested customer using the email template defined in AX.
            /// </summary>
            /// <param name="request">Request containing the customer and email template identifier.</param>
            /// <returns>SendCustomerEmailServiceResponse object.</returns>
            private static NullResponse SendEmailToCustomer(SendEmailRealtimeRequest request)
            {
                TransactionServiceClient transactionService = new TransactionServiceClient(request.RequestContext);

                transactionService.SendEmail(request.EmailAddress, request.Language, request.EmailId, request.Mappings, request.XmlData);

                return(new NullResponse());
            }
Exemple #2
0
            private void SendCustomerEmail(string email, string templateId, ICollection <NameValuePair> properties)
            {
                var serviceRequest = new SendEmailRealtimeRequest(
                    email,
                    properties,
                    this.Context.GetChannelConfiguration().DefaultLanguageId,
                    xmlData: null,
                    emailId: templateId);

                this.Context.Execute <NullResponse>(serviceRequest);
            }
Exemple #3
0
            private void SendCustomerEmail(Customer customer, string templateId, ICollection <NameValuePair> properties)
            {
                var serviceRequest = new SendEmailRealtimeRequest(
                    customer.Email,
                    properties,
                    customer.Language ?? this.Context.LanguageId,
                    null /*xmlData*/,
                    templateId);

                this.Context.Execute <NullResponse>(serviceRequest);
            }
            /// <summary>
            /// Executes the workflow to create the customer.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>The response.</returns>
            protected override CreateCustomerResponse Process(CreateCustomerRequest request)
            {
                ThrowIf.Null(request, "request");

                CustomerHelper.ValidateAddresses(this.Context, request.NewCustomer.Addresses);

                // Checking whether this is context of RetailStore or not because DeviceConfiguration exists only for RetailStores and not for OnlineStores
                if (this.Context.GetPrincipal().IsEmployee)
                {
                    DeviceConfiguration deviceConfiguration = request.RequestContext.GetDeviceConfiguration();
                    System.Diagnostics.Debug.WriteLine(deviceConfiguration.CreateAsyncCustomers);

                    if (deviceConfiguration.CreateAsyncCustomers)
                    {
                        request.NewCustomer.IsAsyncCustomer = true;
                    }
                }

                // save new customer
                var saveCustomerServiceRequest  = new SaveCustomerServiceRequest(request.NewCustomer);
                var saveCustomerServiceResponse = this.Context.Execute <SaveCustomerServiceResponse>(saveCustomerServiceRequest);

                Customer addedCustomer = saveCustomerServiceResponse.UpdatedCustomer;

                if (addedCustomer != null && !string.IsNullOrWhiteSpace(addedCustomer.Email))
                {
                    ICollection <NameValuePair> mappings = GetCreateCustomerEmailMappings(addedCustomer);

                    // Send new customer email to customer
                    var sendCustomerEmailServiceRequest = new SendEmailRealtimeRequest(addedCustomer.Email, mappings, addedCustomer.Language ?? CultureInfo.CurrentUICulture.ToString(), null, NewCustomerEmailId);

                    // don't fail the customer creation if there is is an error sending the email, log the error.
                    try
                    {
                        this.Context.Execute <NullResponse>(sendCustomerEmailServiceRequest);
                    }
                    catch (Exception ex)
                    {
                        RetailLogger.Log.CrtWorkflowCreateCustomerEmailFailure(ex);
                    }
                }

                return(new CreateCustomerResponse(addedCustomer));
            }
            /// <summary>
            /// Make the transaction service call to email the receipt.
            /// </summary>
            /// <param name="salesOrder">The sales order.</param>
            private void SendReceiptMail(SalesOrder salesOrder)
            {
                List <ReceiptType> receiptTypes = new List <ReceiptType>();

                receiptTypes.Add(ReceiptType.SalesReceipt);

                var emailReceipt = new GetEmailReceiptServiceRequest(
                    salesOrder,
                    receiptTypes,
                    salesOrder.TenderLines,
                    false);

                var emailResponse = this.Context.Execute <GetEmailReceiptServiceResponse>(emailReceipt);

                if (emailResponse.Receipts == null || emailResponse.Receipts.Results.Count == 0)
                {
                    return;
                }

                string emailMessage = emailResponse.Receipts.Results[0].Header + emailResponse.Receipts.Results[0].Body + emailResponse.Receipts.Results[0].Footer;

                emailMessage = this.ConvertToHTML(emailMessage);

                string language = string.Empty;

                if (!string.IsNullOrEmpty(salesOrder.CustomerId))
                {
                    var getCustomerDataRequest = new GetCustomerDataRequest(salesOrder.CustomerId);
                    SingleEntityDataServiceResponse <Customer> getCustomerDataResponse = this.Context.Runtime.Execute <SingleEntityDataServiceResponse <Customer> >(getCustomerDataRequest, this.Context);
                    Customer customer = getCustomerDataResponse.Entity;

                    if (customer == null)
                    {
                        language = this.Context.GetChannelConfiguration().DefaultLanguageId;
                    }
                    else
                    {
                        language = customer.Language;
                    }
                }

                if (string.IsNullOrEmpty(language))
                {
                    language = CultureInfo.CurrentUICulture.ToString();
                }

                NameValuePair mapping = new NameValuePair
                {
                    Name  = this.receiptEmailTemplateParameter,
                    Value = emailMessage
                };

                Collection <NameValuePair> mappings = new Collection <NameValuePair>();

                mappings.Add(mapping);

                var emailServiceRequest = new SendEmailRealtimeRequest(
                    salesOrder.ReceiptEmail,
                    mappings,
                    language,
                    string.Empty,
                    this.receiptEmailTemplate);

                this.Context.Execute <NullResponse>(emailServiceRequest);
            }