public ActionResult AskQuestion(int id) { var product = _productService.GetProductById(id); if (product == null || product.Deleted || product.IsSystemProduct || !product.Published || !_catalogSettings.AskQuestionEnabled) { return(HttpNotFound()); } var attributesXml = ""; if (TempData.TryGetValue("AskQuestionAttributesXml-" + id, out var obj)) { attributesXml = obj as string; } // Check if saved attributeXml belongs to current product id var attributeInfo = ""; if (attributesXml.HasValue()) { attributeInfo = _productAttributeFormatter.FormatAttributes( product, attributesXml, null, separator: ", ", renderPrices: false, renderGiftCardAttributes: false, allowHyperlinks: false); } var customer = _services.WorkContext.CurrentCustomer; var model = new ProductAskQuestionModel { Id = product.Id, ProductName = product.GetLocalized(x => x.Name), ProductSeName = product.GetSeName(), SenderEmail = customer.Email, SenderName = customer.GetFullName(), SenderNameRequired = _privacySettings.Value.FullNameOnProductRequestRequired, SenderPhone = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone), DisplayCaptcha = _captchaSettings.CanDisplayCaptcha && _captchaSettings.ShowOnAskQuestionPage, SelectedAttributes = attributeInfo, ProductUrl = _productUrlHelper.GetProductUrl(id, product.GetSeName(), attributesXml), IsQuoteRequest = product.CallForPrice }; var questionTitle = model.IsQuoteRequest ? T("Products.AskQuestion.Question.QuoteRequest") : T("Products.AskQuestion.Question.GeneralInquiry"); model.Question = questionTitle.Text.FormatCurrentUI(model.ProductName); return(View(model)); }
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 = Services.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, TrackingNumberUrl = shipment.TrackingUrl }; 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) { // The URL entered by the merchant takes precedence over an automatically generated URL. if (model.TrackingNumberUrl.IsEmpty()) { 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 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 }; shipmentItemModel.ProductUrl = _productUrlHelper.GetProductUrl(shipmentItemModel.ProductSeName, orderItem); model.Items.Add(shipmentItemModel); } model.Order = _orderHelper.PrepareOrderDetailsModel(order); return(model); }
private OrderDetailsModel.OrderItemModel PrepareOrderItemModel( Order order, OrderItem orderItem, CatalogSettings catalogSettings, ShoppingCartSettings shoppingCartSettings, MediaSettings mediaSettings) { var language = _services.WorkContext.WorkingLanguage; orderItem.Product.MergeWithCombination(orderItem.AttributesXml); var model = new OrderDetailsModel.OrderItemModel { Id = orderItem.Id, Sku = orderItem.Product.Sku, ProductId = orderItem.Product.Id, ProductName = orderItem.Product.GetLocalized(x => x.Name), ProductSeName = orderItem.Product.GetSeName(), ProductType = orderItem.Product.ProductType, Quantity = orderItem.Quantity, AttributeInfo = orderItem.AttributeDescription }; var quantityUnit = _quantityUnitService.GetQuantityUnitById(orderItem.Product.QuantityUnitId); model.QuantityUnit = quantityUnit == null ? "" : quantityUnit.GetLocalized(x => x.Name); if (orderItem.Product.ProductType == ProductType.BundledProduct && orderItem.BundleData.HasValue()) { var bundleData = orderItem.GetBundleData(); var bundleItems = shoppingCartSettings.ShowProductBundleImagesOnShoppingCart ? _productService.GetBundleItems(orderItem.ProductId).ToDictionarySafe(x => x.Item.ProductId) : new Dictionary <int, ProductBundleItemData>(); model.BundlePerItemPricing = orderItem.Product.BundlePerItemPricing; model.BundlePerItemShoppingCart = bundleData.Any(x => x.PerItemShoppingCart); foreach (var bid in bundleData) { var bundleItemModel = new OrderDetailsModel.BundleItemModel { Sku = bid.Sku, ProductName = bid.ProductName, ProductSeName = bid.ProductSeName, VisibleIndividually = bid.VisibleIndividually, Quantity = bid.Quantity, DisplayOrder = bid.DisplayOrder, AttributeInfo = bid.AttributesInfo }; bundleItemModel.ProductUrl = _productUrlHelper.GetProductUrl(bid.ProductId, bundleItemModel.ProductSeName, bid.AttributesXml); if (model.BundlePerItemShoppingCart) { var priceWithDiscount = _currencyService.ConvertCurrency(bid.PriceWithDiscount, order.CurrencyRate); bundleItemModel.PriceWithDiscount = _priceFormatter.FormatPrice(priceWithDiscount, true, order.CustomerCurrencyCode, language, false, false); } // Bundle item picture. if (shoppingCartSettings.ShowProductBundleImagesOnShoppingCart && bundleItems.TryGetValue(bid.ProductId, out var bundleItem)) { bundleItemModel.HideThumbnail = bundleItem.Item.HideThumbnail; bundleItemModel.Picture = PrepareOrderItemPictureModel( bundleItem.Item.Product, mediaSettings.CartThumbBundleItemPictureSize, bid.ProductName, bid.AttributesXml, catalogSettings); } model.BundleItems.Add(bundleItemModel); } } // Unit price, subtotal. switch (order.CustomerTaxDisplayType) { case TaxDisplayType.ExcludingTax: { var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate); model.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false, false); var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate); model.SubTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, false, false); } break; case TaxDisplayType.IncludingTax: { var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate); model.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true, false); var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate); model.SubTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, language, true, false); } break; } model.ProductUrl = _productUrlHelper.GetProductUrl(model.ProductSeName, orderItem); if (shoppingCartSettings.ShowProductImagesOnShoppingCart) { model.Picture = PrepareOrderItemPictureModel( orderItem.Product, mediaSettings.CartThumbPictureSize, model.ProductName, orderItem.AttributesXml, catalogSettings); } return(model); }
public ActionResult Search(CatalogSearchQuery query) { var model = new SearchResultModel(query); CatalogSearchResult result = null; if (query.Term == null || query.Term.Length < _searchSettings.InstantSearchTermMinLength) { model.SearchResult = new CatalogSearchResult(query); model.Error = T("Search.SearchTermMinimumLengthIsNCharacters", _searchSettings.InstantSearchTermMinLength); return(View(model)); } // 'Continue shopping' URL. _genericAttributeService.SaveAttribute(Services.WorkContext.CurrentCustomer, SystemCustomerAttributeNames.LastContinueShoppingPage, Services.WebHelper.GetThisPageUrl(false), Services.StoreContext.CurrentStore.Id); try { if (_searchSettings.SearchProductByIdentificationNumber) { var product = _productService.Value.GetProductByIdentificationNumber(query.Term, out var attributeCombination); if (product != null) { if (attributeCombination != null) { return(Redirect(_productUrlHelper.GetProductUrl(product.Id, product.GetSeName(), attributeCombination.AttributesXml))); } return(RedirectToRoute("Product", new { SeName = product.GetSeName() })); } } result = _catalogSearchService.Search(query); } catch (Exception ex) { model.Error = ex.ToString(); result = new CatalogSearchResult(query); } if (result.TotalHitsCount == 0 && result.SpellCheckerSuggestions.Any()) { // No matches, but spell checker made a suggestion. // We implicitly search again with the first suggested term. var oldSuggestions = result.SpellCheckerSuggestions; var oldTerm = query.Term; query.Term = oldSuggestions[0]; result = _catalogSearchService.Search(query); if (result.TotalHitsCount > 0) { model.AttemptedTerm = oldTerm; // Restore the original suggestions. result.SpellCheckerSuggestions = oldSuggestions.Where(x => x != query.Term).ToArray(); } else { query.Term = oldTerm; } } model.SearchResult = result; model.Term = query.Term; model.TotalProductsCount = result.TotalHitsCount; var mappingSettings = _catalogHelper.GetBestFitProductSummaryMappingSettings(query.GetViewMode()); var summaryModel = _catalogHelper.MapProductSummaryModel(result.Hits, mappingSettings); // Prepare paging/sorting/mode stuff. _catalogHelper.MapListActions(summaryModel, null, _catalogSettings.DefaultPageSizeOptions); // Add product hits. model.TopProducts = summaryModel; return(View(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); }