コード例 #1
0
        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);
        }
コード例 #2
0
        protected ShipmentDetailsModel PrepareShipmentDetailsModel(Shipment shipment)
        {
            if (shipment == null)
            {
                throw new ArgumentNullException("shipment");
            }

            var order = shipment.Order;

            if (order == null)
            {
                throw new SmartException(T("Order.NotFound", shipment.OrderId));
            }

            var store            = _storeService.GetStoreById(order.StoreId) ?? _services.StoreContext.CurrentStore;
            var catalogSettings  = _services.Settings.LoadSetting <CatalogSettings>(store.Id);
            var shippingSettings = _services.Settings.LoadSetting <ShippingSettings>(store.Id);

            var model = new ShipmentDetailsModel
            {
                Id             = shipment.Id,
                TrackingNumber = shipment.TrackingNumber
            };

            if (shipment.ShippedDateUtc.HasValue)
            {
                model.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc);
            }

            if (shipment.DeliveryDateUtc.HasValue)
            {
                model.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc);
            }

            var srcm = _shippingService.LoadShippingRateComputationMethodBySystemName(order.ShippingRateComputationMethodSystemName);

            if (srcm != null && srcm.IsShippingRateComputationMethodActive(shippingSettings))
            {
                var shipmentTracker = srcm.Value.ShipmentTracker;
                if (shipmentTracker != null)
                {
                    model.TrackingNumberUrl = shipmentTracker.GetUrl(shipment.TrackingNumber);
                    if (shippingSettings.DisplayShipmentEventsToCustomers)
                    {
                        var shipmentEvents = shipmentTracker.GetShipmentEvents(shipment.TrackingNumber);
                        if (shipmentEvents != null)
                        {
                            foreach (var shipmentEvent in shipmentEvents)
                            {
                                var shipmentEventCountry = _countryService.GetCountryByTwoLetterIsoCode(shipmentEvent.CountryCode);

                                var shipmentStatusEventModel = new ShipmentDetailsModel.ShipmentStatusEventModel
                                {
                                    Country   = (shipmentEventCountry != null ? shipmentEventCountry.GetLocalized(x => x.Name) : shipmentEvent.CountryCode),
                                    Date      = shipmentEvent.Date,
                                    EventName = shipmentEvent.EventName,
                                    Location  = shipmentEvent.Location
                                };

                                model.ShipmentStatusEvents.Add(shipmentStatusEventModel);
                            }
                        }
                    }
                }
            }

            //products in this shipment
            model.ShowSku = catalogSettings.ShowProductSku;

            foreach (var shipmentItem in shipment.ShipmentItems)
            {
                var orderItem = _orderService.GetOrderItemById(shipmentItem.OrderItemId);
                if (orderItem == null)
                {
                    continue;
                }

                orderItem.Product.MergeWithCombination(orderItem.AttributesXml);

                var attributeQueryData = new List <List <int> >();

                var shipmentItemModel = new ShipmentDetailsModel.ShipmentItemModel
                {
                    Id              = shipmentItem.Id,
                    Sku             = orderItem.Product.Sku,
                    ProductId       = orderItem.Product.Id,
                    ProductName     = orderItem.Product.GetLocalized(x => x.Name),
                    ProductSeName   = orderItem.Product.GetSeName(),
                    AttributeInfo   = orderItem.AttributeDescription,
                    QuantityOrdered = orderItem.Quantity,
                    QuantityShipped = shipmentItem.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));
                }

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

                model.Items.Add(shipmentItemModel);
            }

            model.Order = PrepareOrderDetailsModel(order);

            return(model);
        }