//edit public ActionResult ValueEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (cav == null) { //No checkout attribute value found with the specified id return(RedirectToAction("List")); } var model = cav.ToModel(); model.PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name; //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
public virtual IActionResult ValueEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } //try to get a checkout attribute value with the specified id var checkoutAttributeValue = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (checkoutAttributeValue == null) { return(RedirectToAction("List")); } //try to get a checkout attribute with the specified id var checkoutAttribute = _checkoutAttributeService.GetCheckoutAttributeById(checkoutAttributeValue.CheckoutAttributeId); if (checkoutAttribute == null) { return(RedirectToAction("List")); } //prepare model var model = _checkoutAttributeModelFactory.PrepareCheckoutAttributeValueModel(null, checkoutAttribute, checkoutAttributeValue); return(View(model)); }
/// <summary> /// Get checkout attribute values /// </summary> /// <param name="attributes">Attributes</param> /// <returns>Checkout attribute values</returns> public virtual IList <CheckoutAttributeValue> ParseCheckoutAttributeValues(string attributes) { var caValues = new List <CheckoutAttributeValue>(); var caCollection = ParseCheckoutAttributes(attributes); foreach (var ca in caCollection) { if (!ca.ShouldHaveValues()) { continue; } var caValuesStr = ParseValues(attributes, ca.Id); foreach (string caValueStr in caValuesStr) { if (!String.IsNullOrEmpty(caValueStr)) { int caValueId = 0; if (int.TryParse(caValueStr, out caValueId)) { var caValue = _checkoutAttributeService.GetCheckoutAttributeValueById(caValueId); if (caValue != null) { caValues.Add(caValue); } } } } } return(caValues); }
/// <summary> /// Get checkout attribute values /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <returns>Checkout attribute values</returns> public virtual IList <CheckoutAttributeValue> ParseCheckoutAttributeValues(string attributesXml) { var values = new List <CheckoutAttributeValue>(); var attributes = ParseCheckoutAttributes(attributesXml); foreach (var attribute in attributes) { if (!attribute.ShouldHaveValues()) { continue; } var valuesStr = ParseValues(attributesXml, attribute.Id); foreach (string valueStr in valuesStr) { if (!String.IsNullOrEmpty(valueStr)) { int id; if (int.TryParse(valueStr, out id)) { var value = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (value != null) { values.Add(value); } } } } } return(values); }
public ActionResult ValueEditPopup(int id) { var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (cav == null) { return(RedirectToAction("List")); } var model = cav.ToModel(); PrepareModel(model, cav.CheckoutAttribute); AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
public ActionResult ValueEditPopup(int id) { var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (cav == null) { return(RedirectToAction("List")); } var model = cav.ToModel(); model.PrimaryStoreCurrencyCode = _services.StoreContext.CurrentStore.PrimaryStoreCurrency.CurrencyCode; model.BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId)?.GetLocalized(x => x.Name) ?? string.Empty; AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
//edit public ActionResult ValueEditPopup(int id) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageAttributes)) { return(AccessDeniedView()); } var cav = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (cav == null) { //No checkout attribute value found with the specified id return(RedirectToAction("List")); } var model = new CheckoutAttributeValueModel { CheckoutAttributeId = cav.CheckoutAttributeId, Name = cav.Name, ColorSquaresRgb = cav.ColorSquaresRgb, DisplayColorSquaresRgb = cav.CheckoutAttribute.AttributeControlType == AttributeControlType.ColorSquares, PriceAdjustment = cav.PriceAdjustment, WeightAdjustment = cav.WeightAdjustment, IsPreSelected = cav.IsPreSelected, DisplayOrder = cav.DisplayOrder, PrimaryStoreCurrencyCode = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode, BaseWeightIn = _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).Name }; //locales AddLocales(_languageService, model.Locales, (locale, languageId) => { locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false); }); return(View(model)); }
/// <summary> /// Get checkout attribute values /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <returns>Checkout attribute values</returns> public virtual IEnumerable <(CheckoutAttribute attribute, IEnumerable <CheckoutAttributeValue> values)> ParseCheckoutAttributeValues(string attributesXml) { if (string.IsNullOrEmpty(attributesXml)) { yield break; } var attributes = ParseCheckoutAttributes(attributesXml); foreach (var attribute in attributes) { if (!attribute.ShouldHaveValues()) { continue; } var valuesStr = ParseValues(attributesXml, attribute.Id); yield return(attribute, getValues(valuesStr)); } IEnumerable <CheckoutAttributeValue> getValues(IList <string> valuesStr) { foreach (var valueStr in valuesStr) { if (string.IsNullOrEmpty(valueStr)) { continue; } if (!int.TryParse(valueStr, out var id)) { continue; } var value = _checkoutAttributeService.GetCheckoutAttributeValueById(id); if (value != null) { yield return(value); } } } }
/// <summary> /// Formats attributes /// </summary> /// <param name="attributes">Attributes</param> /// <param name="customer">Customer</param> /// <param name="serapator">Serapator</param> /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param> /// <param name="renderPrices">A value indicating whether to render prices</param> /// <param name="allowHyperlinks">A value indicating whether to HTML hyperink tags could be rendered (if required)</param> /// <returns>Attributes</returns> public string FormatAttributes(string attributes, Customer customer, string serapator = "<br />", bool htmlEncode = true, bool renderPrices = true, bool allowHyperlinks = true) { var result = new StringBuilder(); var caCollection = _checkoutAttributeParser.ParseCheckoutAttributes(attributes); for (int i = 0; i < caCollection.Count; i++) { var ca = caCollection[i]; var valuesStr = _checkoutAttributeParser.ParseValues(attributes, ca.Id); for (int j = 0; j < valuesStr.Count; j++) { string valueStr = valuesStr[j]; string caAttribute = ""; if (!ca.ShouldHaveValues()) { //no values if (ca.AttributeControlType == AttributeControlType.MultilineTextbox) { //multiline textbox var attributeName = ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id); //encode (if required) if (htmlEncode) { attributeName = HttpUtility.HtmlEncode(attributeName); } caAttribute = string.Format("{0}: {1}", attributeName, HtmlHelper.FormatText(valueStr, false, true, false, false, false, false)); //we never encode multiline textbox input } else if (ca.AttributeControlType == AttributeControlType.FileUpload) { //file upload Guid downloadGuid; Guid.TryParse(valueStr, out downloadGuid); var download = _downloadService.GetDownloadByGuid(downloadGuid); if (download != null) { //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) string attributeText = ""; var fileName = string.Format("{0}{1}", download.Filename ?? download.DownloadGuid.ToString(), download.Extension); //encode (if required) if (htmlEncode) { fileName = HttpUtility.HtmlEncode(fileName); } if (allowHyperlinks) { //hyperlinks are allowed var downloadLink = string.Format("{0}download/getfileupload/?downloadId={1}", _webHelper.GetStoreLocation(false), download.DownloadGuid); attributeText = string.Format("<a href=\"{0}\" class=\"fileuploadattribute\">{1}</a>", downloadLink, fileName); } else { //hyperlinks aren't allowed attributeText = fileName; } var attributeName = ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id); //encode (if required) if (htmlEncode) { attributeName = HttpUtility.HtmlEncode(attributeName); } caAttribute = string.Format("{0}: {1}", attributeName, attributeText); } } else { //other attributes (textbox, datepicker) caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id), valueStr); //encode (if required) if (htmlEncode) { caAttribute = HttpUtility.HtmlEncode(caAttribute); } } } else { int caId = 0; if (int.TryParse(valueStr, out caId)) { var caValue = _checkoutAttributeService.GetCheckoutAttributeValueById(caId); if (caValue != null) { caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id), caValue.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id)); if (renderPrices) { decimal priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(caValue, customer); decimal priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency); if (priceAdjustmentBase > 0) { string priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustment); caAttribute += string.Format(" [+{0}]", priceAdjustmentStr); } } } //encode (if required) if (htmlEncode) { caAttribute = HttpUtility.HtmlEncode(caAttribute); } } } if (!String.IsNullOrEmpty(caAttribute)) { if (i != 0 || j != 0) { result.Append(serapator); } result.Append(caAttribute); } } } return(result.ToString()); }
/// <summary> /// Formats attributes /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <param name="customer">Customer</param> /// <param name="separator">Separator</param> /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param> /// <param name="renderPrices">A value indicating whether to render prices</param> /// <param name="allowHyperlinks">A value indicating whether to HTML hyperlink tags could be rendered (if required)</param> /// <returns>Attributes</returns> public virtual string FormatAttributes(string attributesXml, Customer customer, string separator = "<br />", bool htmlEncode = true, bool renderPrices = true, bool allowHyperlinks = true) { var result = new StringBuilder(); var attributes = _checkoutAttributeParser.ParseCheckoutAttributes(attributesXml); for (var i = 0; i < attributes.Count; i++) { var attribute = attributes[i]; var valuesStr = _checkoutAttributeParser.ParseValues(attributesXml, attribute.Id); for (var j = 0; j < valuesStr.Count; j++) { var valueStr = valuesStr[j]; var formattedAttribute = ""; if (!attribute.ShouldHaveValues()) { //no values if (attribute.AttributeControlType == AttributeControlType.MultilineTextbox) { //multiline textbox var attributeName = _localizationService.GetLocalized(attribute, a => a.Name, _workContext.WorkingLanguage.Id); //encode (if required) if (htmlEncode) { attributeName = WebUtility.HtmlEncode(attributeName); } formattedAttribute = $"{attributeName}: {HtmlHelper.FormatText(valueStr, false, true, false, false, false, false)}"; //we never encode multiline textbox input } else if (attribute.AttributeControlType == AttributeControlType.FileUpload) { //file upload Guid.TryParse(valueStr, out Guid downloadGuid); var download = _downloadService.GetDownloadByGuid(downloadGuid); if (download != null) { //TODO add a method for getting URL (use routing because it handles all SEO friendly URLs) string attributeText; var fileName = $"{download.Filename ?? download.DownloadGuid.ToString()}{download.Extension}"; //encode (if required) if (htmlEncode) { fileName = WebUtility.HtmlEncode(fileName); } if (allowHyperlinks) { //hyperlinks are allowed var downloadLink = $"{_webHelper.GetStoreLocation(false)}download/getfileupload/?downloadId={download.DownloadGuid}"; attributeText = $"<a href=\"{downloadLink}\" class=\"fileuploadattribute\">{fileName}</a>"; } else { //hyperlinks aren't allowed attributeText = fileName; } var attributeName = _localizationService.GetLocalized(attribute, a => a.Name, _workContext.WorkingLanguage.Id); //encode (if required) if (htmlEncode) { attributeName = WebUtility.HtmlEncode(attributeName); } formattedAttribute = $"{attributeName}: {attributeText}"; } } else { //other attributes (textbox, datepicker) formattedAttribute = $"{_localizationService.GetLocalized(attribute, a => a.Name, _workContext.WorkingLanguage.Id)}: {valueStr}"; //encode (if required) if (htmlEncode) { formattedAttribute = WebUtility.HtmlEncode(formattedAttribute); } } } else { if (int.TryParse(valueStr, out int attributeValueId)) { var attributeValue = _checkoutAttributeService.GetCheckoutAttributeValueById(attributeValueId); if (attributeValue != null) { formattedAttribute = $"{_localizationService.GetLocalized(attribute, a => a.Name, _workContext.WorkingLanguage.Id)}: {_localizationService.GetLocalized(attributeValue, a => a.Name, _workContext.WorkingLanguage.Id)}"; if (renderPrices) { var priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(attributeValue, customer); var priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency); if (priceAdjustmentBase > 0) { var priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustment); formattedAttribute += $" [+{priceAdjustmentStr}]"; } } } //encode (if required) if (htmlEncode) { formattedAttribute = WebUtility.HtmlEncode(formattedAttribute); } } } if (!string.IsNullOrEmpty(formattedAttribute)) { if (i != 0 || j != 0) { result.Append(separator); } result.Append(formattedAttribute); } } } return(result.ToString()); }
/// <summary> /// Formats attributes /// </summary> /// <param name="attributes">Attributes</param> /// <param name="customer">Customer</param> /// <param name="serapator">Serapator</param> /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param> /// <param name="renderPrices">A value indicating whether to render prices</param> /// <returns>Attributes</returns> public string FormatAttributes(string attributes, Customer customer, string serapator = "<br />", bool htmlEncode = true, bool renderPrices = true) { var result = new StringBuilder(); var caCollection = _checkoutAttributeParser.ParseCheckoutAttributes(attributes); for (int i = 0; i < caCollection.Count; i++) { var ca = caCollection[i]; var valuesStr = _checkoutAttributeParser.ParseValues(attributes, ca.Id); for (int j = 0; j < valuesStr.Count; j++) { string valueStr = valuesStr[j]; string caAttribute = string.Empty; if (!ca.ShouldHaveValues()) { if (ca.AttributeControlType == AttributeControlType.MultilineTextbox) { caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id), HtmlHelper.FormatText(valueStr, false, true, true, false, false, false)); } else { caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id), valueStr); } } else { int caId = 0; if (int.TryParse(valueStr, out caId)) { var caValue = _checkoutAttributeService.GetCheckoutAttributeValueById(caId); if (caValue != null) { caAttribute = string.Format("{0}: {1}", ca.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id), caValue.GetLocalized(a => a.Name, _workContext.WorkingLanguage.Id)); if (renderPrices) { decimal priceAdjustmentBase = _taxService.GetCheckoutAttributePrice(caValue, customer); decimal priceAdjustment = _currencyService.ConvertFromPrimaryStoreCurrency(priceAdjustmentBase, _workContext.WorkingCurrency); if (priceAdjustmentBase > 0) { string priceAdjustmentStr = _priceFormatter.FormatPrice(priceAdjustment); caAttribute += string.Format(" [+{0}]", priceAdjustmentStr); } } } } } if (!String.IsNullOrEmpty(caAttribute)) { if (i != 0 || j != 0) { result.Append(serapator); } //we don't encode multiline textbox input if (htmlEncode && ca.AttributeControlType != AttributeControlType.MultilineTextbox) { result.Append(HttpUtility.HtmlEncode(caAttribute)); } else { result.Append(caAttribute); } } } } return(result.ToString()); }