public JsonResult SaveCcAttributes(int productId, int attributeId, int attributeOptionId, string attributeValue) { try { var specificationAttributes = _specificationAttributeService.GetProductSpecificationAttributes(productId); var prodSpecAttr = specificationAttributes.FirstOrDefault( x => x.SpecificationAttributeOption.SpecificationAttributeId == attributeId); if (prodSpecAttr == null) { prodSpecAttr = new ProductSpecificationAttribute { AttributeType = SpecificationAttributeType.CustomText, ProductId = productId, SpecificationAttributeOptionId = attributeOptionId, DisplayOrder = 0, ShowOnProductPage = false, AllowFiltering = false, CustomValue = attributeValue, }; _specificationAttributeService.InsertProductSpecificationAttribute(prodSpecAttr); } else { prodSpecAttr.CustomValue = attributeValue; prodSpecAttr.ShowOnProductPage = false; _specificationAttributeService.UpdateProductSpecificationAttribute(prodSpecAttr); } var productAttributeMappings = _productAttributeService.GetProductAttributeMappingsByProductId(productId); foreach (var attrId in _ccService.GetCcAttrIds()) { if (productAttributeMappings.All(map => map.ProductAttributeId != attrId)) { _productAttributeService.InsertProductAttributeMapping(new ProductAttributeMapping { AttributeControlType = AttributeControlType.TextBox, DefaultValue = "", DisplayOrder = 100, ProductId = productId, ProductAttributeId = attrId }); } } return(Json(new { status = "success" })); } catch (Exception ex) { return(Json(new { status = "error", message = ex.Message })); } }
public override string FormatAttributes(Product product, string attributesXml, Customer customer, string serapator = "<br />", bool htmlEncode = true, bool renderPrices = true, bool renderProductAttributes = true, bool renderGiftCardAttributes = true, bool allowHyperlinks = true) { var isProdcutForCc = _ccService.IsProductForCc(product); if (isProdcutForCc) { attributesXml = _ccService.RemoveAttrMappings(attributesXml, _ccService.GetCcAttrIds()); } var result = base.FormatAttributes(product, attributesXml, customer, serapator, htmlEncode, renderPrices, renderProductAttributes, renderGiftCardAttributes, allowHyperlinks); return(result.ToString()); }