//edit
        public virtual IActionResult ValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            //try to get a vendor attribute value with the specified id
            var vendorAttributeValue = _vendorAttributeService.GetVendorAttributeValueById(id);

            if (vendorAttributeValue == null)
            {
                return(RedirectToAction("List"));
            }

            //try to get a vendor attribute with the specified id
            var vendorAttribute = _vendorAttributeService.GetVendorAttributeById(vendorAttributeValue.VendorAttributeId);

            if (vendorAttribute == null)
            {
                return(RedirectToAction("List"));
            }

            //prepare model
            var model = _vendorAttributeModelFactory.PrepareVendorAttributeValueModel(null, vendorAttribute, vendorAttributeValue);

            return(View(model));
        }
Exemple #2
0
        //edit
        public virtual IActionResult ValueEditPopup(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var cav = _vendorAttributeService.GetVendorAttributeValueById(id);

            if (cav == null)
            {
                //No vendor attribute value found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new VendorAttributeValueModel
            {
                VendorAttributeId = cav.VendorAttributeId,
                Name          = cav.Name,
                IsPreSelected = cav.IsPreSelected,
                DisplayOrder  = cav.DisplayOrder
            };

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.Name = cav.GetLocalized(x => x.Name, languageId, false, false);
            });

            return(View(model));
        }
        /// <summary>
        /// Get vendor attribute values from XML
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <returns>List of vendor attribute values</returns>
        public virtual IList <VendorAttributeValue> ParseVendorAttributeValues(string attributesXml)
        {
            var values = new List <VendorAttributeValue>();

            if (string.IsNullOrEmpty(attributesXml))
            {
                return(values);
            }

            var attributes = ParseVendorAttributes(attributesXml);

            foreach (var attribute in attributes)
            {
                if (!attribute.ShouldHaveValues())
                {
                    continue;
                }

                var valuesStr = ParseValues(attributesXml, attribute.Id);
                foreach (var valueStr in valuesStr)
                {
                    if (string.IsNullOrEmpty(valueStr))
                    {
                        continue;
                    }

                    if (!int.TryParse(valueStr, out var id))
                    {
                        continue;
                    }

                    var value = _vendorAttributeService.GetVendorAttributeValueById(id);
                    if (value != null)
                    {
                        values.Add(value);
                    }
                }
            }

            return(values);
        }
Exemple #4
0
        /// <summary>
        /// Format vendor attributes
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <param name="separator">Separator</param>
        /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param>
        /// <returns>Formatted attributes</returns>
        public virtual string FormatAttributes(string attributesXml, string separator = "<br />", bool htmlEncode = true)
        {
            var result = new StringBuilder();

            var attributes = _vendorAttributeParser.ParseVendorAttributes(attributesXml);

            for (var i = 0; i < attributes.Count; i++)
            {
                var attribute = attributes[i];
                var valuesStr = _vendorAttributeParser.ParseValues(attributesXml, attribute.Id);
                for (var j = 0; j < valuesStr.Count; j++)
                {
                    var valueStr           = valuesStr[j];
                    var formattedAttribute = string.Empty;
                    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
                            //not supported for vendor attributes
                        }
                        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 var attributeValueId))
                        {
                            var attributeValue = _vendorAttributeService.GetVendorAttributeValueById(attributeValueId);
                            if (attributeValue != null)
                            {
                                formattedAttribute = $"{_localizationService.GetLocalized(attribute, a => a.Name, _workContext.WorkingLanguage.Id)}: {_localizationService.GetLocalized(attributeValue, a => a.Name, _workContext.WorkingLanguage.Id)}";
                            }
                            //encode (if required)
                            if (htmlEncode)
                            {
                                formattedAttribute = WebUtility.HtmlEncode(formattedAttribute);
                            }
                        }
                    }

                    if (string.IsNullOrEmpty(formattedAttribute))
                    {
                        continue;
                    }

                    if (i != 0 || j != 0)
                    {
                        result.Append(separator);
                    }
                    result.Append(formattedAttribute);
                }
            }

            return(result.ToString());
        }