public virtual SubmitReturnRequestModel.OrderItemModel PrepareSubmitReturnRequestOrderItemModel(OrderItem orderItem)
        {
            if (orderItem == null)
            {
                throw new ArgumentNullException("orderItem");
            }

            var order = orderItem.Order;

            var model = new SubmitReturnRequestModel.OrderItemModel
            {
                Id            = orderItem.Id,
                ProductId     = orderItem.Product.Id,
                ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                ProductSeName = orderItem.Product.GetSeName(),
                AttributeInfo = orderItem.AttributeDescription,
                Quantity      = orderItem.Quantity
            };

            //unit price
            if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                //including tax
                var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                model.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
            }
            else
            {
                //excluding tax
                var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                model.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
            }

            return(model);
        }
        /// <summary>
        /// Prepares the order item models for return request by specified order.
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>
        /// The <see cref="Task"/> containing the <see cref="IList{SubmitReturnRequestModel.OrderItemModel}"/>
        /// </returns>
        protected virtual async Task <IList <SubmitReturnRequestModel.OrderItemModel> > PrepareSubmitReturnRequestOrderItemModelsAsync(Order order)
        {
            if (order is null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            var models = new List <SubmitReturnRequestModel.OrderItemModel>();

            var returnRequestAvailability = await _returnRequestService.GetReturnRequestAvailabilityAsync(order.Id);

            if (returnRequestAvailability?.IsAllowed == true)
            {
                foreach (var returnableOrderItem in returnRequestAvailability.ReturnableOrderItems)
                {
                    if (returnableOrderItem.AvailableQuantityForReturn == 0)
                    {
                        continue;
                    }

                    var orderItem = returnableOrderItem.OrderItem;
                    var product   = await _productService.GetProductByIdAsync(orderItem.ProductId);

                    var model = new SubmitReturnRequestModel.OrderItemModel
                    {
                        Id            = orderItem.Id,
                        ProductId     = product.Id,
                        ProductName   = await _localizationService.GetLocalizedAsync(product, x => x.Name),
                        ProductSeName = await _urlRecordService.GetSeNameAsync(product),
                        AttributeInfo = orderItem.AttributeDescription,
                        Quantity      = returnableOrderItem.AvailableQuantityForReturn
                    };

                    var languageId = (await _workContext.GetWorkingLanguageAsync()).Id;

                    //unit price
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        model.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, true);
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        model.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, false);
                    }

                    models.Add(model);
                }
            }

            return(models);
        }
        /// <summary>
        /// Prepare the order item model
        /// </summary>
        /// <param name="orderItem">Order item</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the order item model
        /// </returns>
        public virtual async Task <SubmitReturnRequestModel.OrderItemModel> PrepareSubmitReturnRequestOrderItemModelAsync(OrderItem orderItem)
        {
            if (orderItem == null)
            {
                throw new ArgumentNullException(nameof(orderItem));
            }

            var order = await _orderService.GetOrderByIdAsync(orderItem.OrderId);

            var product = await _productService.GetProductByIdAsync(orderItem.ProductId);

            var model = new SubmitReturnRequestModel.OrderItemModel
            {
                Id            = orderItem.Id,
                ProductId     = product.Id,
                ProductName   = await _localizationService.GetLocalizedAsync(product, x => x.Name),
                ProductSeName = await _urlRecordService.GetSeNameAsync(product),
                AttributeInfo = orderItem.AttributeDescription,
                Quantity      = orderItem.Quantity
            };

            var languageId = (await _workContext.GetWorkingLanguageAsync()).Id;

            //unit price
            if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                //including tax
                var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                model.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, true);
            }
            else
            {
                //excluding tax
                var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                model.UnitPrice = await _priceFormatter.FormatPriceAsync(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, languageId, false);
            }

            return(model);
        }
        protected virtual SubmitReturnRequestModel PrepareReturnRequestModel(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId = order.Id;

            //return reasons
            model.AvailableReturnReasons = _cacheManager.Get(string.Format(ModelCacheEventConsumer.RETURNREQUESTREASONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                             () =>
            {
                var reasons = new List <SubmitReturnRequestModel.ReturnRequestReasonModel>();
                foreach (var rrr in _returnRequestService.GetAllReturnRequestReasons())
                {
                    reasons.Add(new SubmitReturnRequestModel.ReturnRequestReasonModel()
                    {
                        Id   = rrr.Id,
                        Name = rrr.GetLocalized(x => x.Name)
                    });
                }
                return(reasons);
            });

            //return actions
            model.AvailableReturnActions = _cacheManager.Get(string.Format(ModelCacheEventConsumer.RETURNREQUESTACTIONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                             () =>
            {
                var actions = new List <SubmitReturnRequestModel.ReturnRequestActionModel>();
                foreach (var rra in _returnRequestService.GetAllReturnRequestActions())
                {
                    actions.Add(new SubmitReturnRequestModel.ReturnRequestActionModel()
                    {
                        Id   = rra.Id,
                        Name = rra.GetLocalized(x => x.Name)
                    });
                }
                return(actions);
            });

            //products
            var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName = orderItem.Product.GetSeName(),
                    AttributeInfo = orderItem.AttributeDescription,
                    Quantity      = orderItem.Quantity
                };
                model.Items.Add(orderItemModel);

                //unit price
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
                else
                {
                    //excluding tax
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            return(model);
        }
Esempio n. 5
0
        protected virtual SubmitReturnRequestModel PrepareReturnRequestModel(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId     = order.Id;
            model.OrderNumber = _orderService.GetOrderById(order.Id).OrderNumber;
            //return reasons
            model.AvailableReturnReasons = _cacheManager.Get(string.Format(ModelCacheEventConsumer.RETURNREQUESTREASONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                             () =>
            {
                var reasons = new List <SubmitReturnRequestModel.ReturnRequestReasonModel>();
                foreach (var rrr in _returnRequestService.GetAllReturnRequestReasons())
                {
                    reasons.Add(new SubmitReturnRequestModel.ReturnRequestReasonModel()
                    {
                        Id   = rrr.Id,
                        Name = rrr.GetLocalized(x => x.Name)
                    });
                }
                return(reasons);
            });

            //return actions
            model.AvailableReturnActions = _cacheManager.Get(string.Format(ModelCacheEventConsumer.RETURNREQUESTACTIONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                             () =>
            {
                var actions = new List <SubmitReturnRequestModel.ReturnRequestActionModel>();
                foreach (var rra in _returnRequestService.GetAllReturnRequestActions())
                {
                    actions.Add(new SubmitReturnRequestModel.ReturnRequestActionModel()
                    {
                        Id   = rra.Id,
                        Name = rra.GetLocalized(x => x.Name)
                    });
                }
                return(actions);
            });

            var shipments = Grand.Core.Infrastructure.EngineContextExperimental.Current.Resolve <Grand.Services.Shipping.IShipmentService>().GetShipmentsByOrder(order.Id);

            //products
            var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var qtyDelivery = shipments.Where(x => x.DeliveryDateUtc.HasValue).SelectMany(x => x.ShipmentItems).Where(x => x.OrderItemId == orderItem.Id).Sum(x => x.Quantity);
                var qtyReturn   = _returnRequestService.SearchReturnRequests(customerId: order.CustomerId, orderItemId: orderItem.Id).Sum(x => x.Quantity);

                var product = _productService.GetProductByIdIncludeArch(orderItem.ProductId);
                if (!product.NotReturnable)
                {
                    var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                    {
                        Id            = orderItem.Id,
                        ProductId     = orderItem.ProductId,
                        ProductName   = product.GetLocalized(x => x.Name),
                        ProductSeName = product.GetSeName(),
                        AttributeInfo = orderItem.AttributeDescription,
                        Quantity      = qtyDelivery - qtyReturn,
                    };
                    model.Items.Add(orderItemModel);
                    //unit price
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                    }
                }
            }

            return(model);
        }
Esempio n. 6
0
        protected virtual SubmitReturnRequestModel PrepareReturnRequestModel(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId = order.Id;

            //return reasons
            if (_orderSettings.ReturnRequestReasons != null)
            {
                foreach (var rrr in _orderSettings.ReturnRequestReasons)
                {
                    model.AvailableReturnReasons.Add(new SelectListItem
                    {
                        Text  = rrr,
                        Value = rrr
                    });
                }
            }

            //return actions
            if (_orderSettings.ReturnRequestActions != null)
            {
                foreach (var rra in _orderSettings.ReturnRequestActions)
                {
                    model.AvailableReturnActions.Add(new SelectListItem
                    {
                        Text  = rra,
                        Value = rra
                    });
                }
            }

            //products
            var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName = orderItem.Product.GetSeName(),
                    AttributeInfo = orderItem.AttributeDescription,
                    Quantity      = orderItem.Quantity
                };
                model.Items.Add(orderItemModel);

                //unit price
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
                else
                {
                    //excluding tax
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            return(model);
        }
Esempio n. 7
0
        protected async Task <SubmitReturnRequestModel> PrepareReturnRequestModelAsync(SubmitReturnRequestModel model, Order order)
        {
            Guard.NotNull(order, nameof(order));
            Guard.NotNull(model, nameof(model));

            model.OrderId = order.Id;

            var    language             = Services.WorkContext.WorkingLanguage;
            string returnRequestReasons = _orderSettings.GetLocalizedSetting(x => x.ReturnRequestReasons, order.CustomerLanguageId, order.StoreId, true, false);
            string returnRequestActions = _orderSettings.GetLocalizedSetting(x => x.ReturnRequestActions, order.CustomerLanguageId, order.StoreId, true, false);

            // Return reasons.
            var availableReturnReasons = new List <SelectListItem>();

            foreach (var rrr in returnRequestReasons.SplitSafe(","))
            {
                availableReturnReasons.Add(new SelectListItem {
                    Text = rrr, Value = rrr
                });
            }
            ViewBag.AvailableReturnReasons = availableReturnReasons;

            // Return actions.
            var availableReturnActions = new List <SelectListItem>();

            foreach (var rra in returnRequestActions.SplitSafe(","))
            {
                availableReturnActions.Add(new SelectListItem {
                    Text = rra, Value = rra
                });
            }
            ViewBag.AvailableReturnActions = availableReturnActions;

            foreach (var orderItem in order.OrderItems)
            {
                var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName = await orderItem.Product.GetActiveSlugAsync(),
                    AttributeInfo = orderItem.AttributeDescription,
                    Quantity      = orderItem.Quantity
                };

                orderItemModel.ProductUrl = await _productUrlHelper.GetProductUrlAsync(orderItemModel.ProductSeName, orderItem);

                // TODO: (mh) (core) Reconsider when pricing is available.
                var customerCurrency = await _db.Currencies
                                       .AsNoTracking()
                                       .Where(x => x.CurrencyCode == order.CustomerCurrencyCode)
                                       .FirstOrDefaultAsync() ?? new Currency
                {
                    CurrencyCode = order.CustomerCurrencyCode
                };

                // Unit price.
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayType.ExcludingTax:
                {
                    // TODO: (mh) (core) _currencyService.ConvertToCurrency doesn't take a rate as paramter.
                    //var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    //orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                    orderItemModel.UnitPrice = new Money(orderItem.UnitPriceExclTax, customerCurrency);
                }
                break;

                case TaxDisplayType.IncludingTax:
                {
                    //var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    //orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                    orderItemModel.UnitPrice = new Money(orderItem.UnitPriceInclTax, customerCurrency);
                }
                break;
                }

                model.Items.Add(orderItemModel);
            }

            return(model);
        }
        public virtual async Task <SubmitReturnRequestModel> PrepareReturnRequest(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId     = order.Id;
            model.OrderNumber = (await _orderService.GetOrderById(order.Id)).OrderNumber;
            //return reasons
            model.AvailableReturnReasons = await _cacheManager.GetAsync(string.Format(ModelCacheEventConsumer.RETURNREQUESTREASONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                                        async() =>
            {
                var reasons = new List <SubmitReturnRequestModel.ReturnRequestReasonModel>();
                foreach (var rrr in await _returnRequestService.GetAllReturnRequestReasons())
                {
                    reasons.Add(new SubmitReturnRequestModel.ReturnRequestReasonModel()
                    {
                        Id   = rrr.Id,
                        Name = rrr.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id)
                    });
                }
                return(reasons);
            });

            //return actions
            model.AvailableReturnActions = await _cacheManager.GetAsync(string.Format(ModelCacheEventConsumer.RETURNREQUESTACTIONS_MODEL_KEY, _workContext.WorkingLanguage.Id),
                                                                        async() =>
            {
                var actions = new List <SubmitReturnRequestModel.ReturnRequestActionModel>();
                foreach (var rra in await _returnRequestService.GetAllReturnRequestActions())
                {
                    actions.Add(new SubmitReturnRequestModel.ReturnRequestActionModel()
                    {
                        Id   = rra.Id,
                        Name = rra.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id)
                    });
                }
                return(actions);
            });

            var shipments = await _serviceProvider.GetRequiredService <Grand.Services.Shipping.IShipmentService>().GetShipmentsByOrder(order.Id);

            //products
            var orderItems = await _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var qtyDelivery    = shipments.Where(x => x.DeliveryDateUtc.HasValue).SelectMany(x => x.ShipmentItems).Where(x => x.OrderItemId == orderItem.Id).Sum(x => x.Quantity);
                var returnRequests = await _returnRequestService.SearchReturnRequests(customerId : order.CustomerId, orderItemId : orderItem.Id);

                int qtyReturn = 0;

                foreach (var rr in returnRequests)
                {
                    foreach (var rrItem in rr.ReturnRequestItems)
                    {
                        qtyReturn += rrItem.Quantity;
                    }
                }

                var product = await _productService.GetProductByIdIncludeArch(orderItem.ProductId);

                if (!product.NotReturnable)
                {
                    var orderItemModel = new SubmitReturnRequestModel.OrderItemModel {
                        Id            = orderItem.Id,
                        ProductId     = orderItem.ProductId,
                        ProductName   = product.GetLocalized(x => x.Name, _workContext.WorkingLanguage.Id),
                        ProductSeName = product.GetSeName(_workContext.WorkingLanguage.Id),
                        AttributeInfo = orderItem.AttributeDescription,
                        Quantity      = qtyDelivery - qtyReturn,
                    };
                    if (orderItemModel.Quantity > 0)
                    {
                        model.Items.Add(orderItemModel);
                    }
                    //unit price
                    if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                    {
                        //including tax
                        var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                        orderItemModel.UnitPrice = await _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                    }
                    else
                    {
                        //excluding tax
                        var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                        orderItemModel.UnitPrice = await _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                    }
                }
            }
            if (_orderSettings.ReturnRequests_AllowToSpecifyPickupAddress)
            {
                //existing addresses
                var addresses = new List <Address>();
                foreach (var item in _workContext.CurrentCustomer.Addresses)
                {
                    if (string.IsNullOrEmpty(item.CountryId))
                    {
                        addresses.Add(item);
                        continue;
                    }
                    var country = await _countryService.GetCountryById(item.CountryId);

                    if (country == null || (country.AllowsShipping && _storeMappingService.Authorize(country)))
                    {
                        addresses.Add(item);
                        continue;
                    }
                }

                foreach (var address in addresses)
                {
                    var addressModel = new AddressModel();
                    await _addressViewModelService.PrepareModel(model : addressModel,
                                                                address : address,
                                                                excludeProperties : false);

                    model.ExistingAddresses.Add(addressModel);
                }

                //new address
                var countries = await _countryService.GetAllCountriesForShipping();

                await _addressViewModelService.PrepareModel(model : model.NewAddress,
                                                            address : null,
                                                            excludeProperties : false,
                                                            loadCountries : () => countries,
                                                            prePopulateWithCustomerFields : true,
                                                            customer : _workContext.CurrentCustomer);
            }
            model.ShowPickupAddress  = _orderSettings.ReturnRequests_AllowToSpecifyPickupAddress;
            model.ShowPickupDate     = _orderSettings.ReturnRequests_AllowToSpecifyPickupDate;
            model.PickupDateRequired = _orderSettings.ReturnRequests_PickupDateRequired;

            return(model);
        }
        protected SubmitReturnRequestModel PrepareReturnRequestModel(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId = order.Id;

            var    language             = Services.WorkContext.WorkingLanguage;
            string returnRequestReasons = _orderSettings.GetLocalized(x => x.ReturnRequestReasons, order.CustomerLanguageId, true, false);
            string returnRequestActions = _orderSettings.GetLocalized(x => x.ReturnRequestActions, order.CustomerLanguageId, true, false);

            // Return reasons.
            foreach (var rrr in returnRequestReasons.SplitSafe(","))
            {
                model.AvailableReturnReasons.Add(new SelectListItem {
                    Text = rrr, Value = rrr
                });
            }

            // Return actions.
            foreach (var rra in returnRequestActions.SplitSafe(","))
            {
                model.AvailableReturnActions.Add(new SelectListItem {
                    Text = rra, Value = rra
                });
            }

            // Products.
            var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName = orderItem.Product.GetSeName(),
                    AttributeInfo = orderItem.AttributeDescription,
                    Quantity      = orderItem.Quantity
                };

                orderItemModel.ProductUrl = _productUrlHelper.GetProductUrl(orderItemModel.ProductSeName, orderItem);

                // Unit price.
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayType.ExcludingTax:
                {
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false);
                }
                break;

                case TaxDisplayType.IncludingTax:
                {
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true);
                }
                break;
                }

                model.Items.Add(orderItemModel);
            }

            return(model);
        }
        protected SubmitReturnRequestModel PrepareReturnRequestModel(SubmitReturnRequestModel model, Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException("order");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.OrderId = order.Id;

            string returnRequestReasons = _orderSettings.GetLocalized(x => x.ReturnRequestReasons, order.CustomerLanguageId, true, false);
            string returnRequestActions = _orderSettings.GetLocalized(x => x.ReturnRequestActions, order.CustomerLanguageId, true, false);

            //return reasons
            foreach (var rrr in returnRequestReasons.SplitSafe(","))
            {
                model.AvailableReturnReasons.Add(new SelectListItem()
                {
                    Text = rrr, Value = rrr
                });
            }

            //return actions
            foreach (var rra in returnRequestActions.SplitSafe(","))
            {
                model.AvailableReturnActions.Add(new SelectListItem()
                {
                    Text = rra, Value = rra
                });
            }

            //products
            var orderItems = _orderService.GetAllOrderItems(order.Id, null, null, null, null, null, null);

            foreach (var orderItem in orderItems)
            {
                var attributeQueryData = new List <List <int> >();

                var orderItemModel = new SubmitReturnRequestModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName = orderItem.Product.GetSeName(),
                    AttributeInfo = orderItem.AttributeDescription,
                    Quantity      = orderItem.Quantity
                };

                if (orderItem.Product.ProductType != ProductType.BundledProduct)
                {
                    _productAttributeParser.DeserializeQueryData(attributeQueryData, orderItem.AttributesXml, orderItem.ProductId);
                }
                else if (orderItem.Product.BundlePerItemPricing && orderItem.BundleData.HasValue())
                {
                    var bundleData = orderItem.GetBundleData();

                    bundleData.ForEach(x => _productAttributeParser.DeserializeQueryData(attributeQueryData, x.AttributesXml, x.ProductId, x.BundleItemId));
                }

                orderItemModel.ProductUrl = _productAttributeParser.GetProductUrlWithAttributes(attributeQueryData, orderItemModel.ProductSeName);

                //unit price
                switch (order.CustomerTaxDisplayType)
                {
                case TaxDisplayType.ExcludingTax:
                {
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
                break;

                case TaxDisplayType.IncludingTax:
                {
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
                break;
                }

                model.Items.Add(orderItemModel);
            }

            return(model);
        }