public List<IActiveProductAttribute> GetCatalogueAttributes(int storeID, string cultureCode) { IQuery aQuery = this._sessionManager.OpenSession().CreateQuery(" from AttributeGroupAttribute"); IList aList = aQuery.List(); List<Domain.Catalogue.Interfaces.IActiveProductAttribute> attributes = new List<IActiveProductAttribute>(); foreach (AttributeGroupAttribute active in aList) { Domain.Catalogue.ActiveProductAttribute a = new Domain.Catalogue.ActiveProductAttribute(); a.Name = active.Attribute.AttributeReference; a.Group.ID = active.AttributeGroupid; a.Group.Name = active.AttributeGroup.AttributeGroupName; a.DataType = active.Attribute.AttributeType.Name; foreach (AttributeOptionValue aov in active.Attribute.Options) { AttributeOption option = new AttributeOption(); option.ShortCode = aov.OptionID.ToString(); option.PickListValue = aov.OptionName; a.AttributeOptionList.Add(option); } attributes.Add(a); } return attributes; }
public List<IActiveProductAttribute> GetProductAttributes(IProduct ep) { List<IActiveProductAttribute> attributeList = new List<IActiveProductAttribute>(); IActiveProductAttribute active = null; int lastAttributeID = 0; //Replaced with a stored procedure to make it far, far quicker using (SpHandler sph = new SpHandler("getProductAttributes", new SqlParameter("@productID", ep.ProductID))) { sph.ExecuteReader(); while (sph.DataReader.Read()) { int attributeID = Convert.ToInt32(sph.DataReader["attributeID"]); //Create a new attribute as it is found. Relies on values returned grouped by attributeid if (attributeID != lastAttributeID) { active = new ActiveProductAttribute(); active.DataType = Convert.ToString(sph.DataReader["type"]); active.BaseUnit = Convert.ToString(sph.DataReader["baseUnit"]); active.Name = Convert.ToString(sph.DataReader["attributeDescription"]); lastAttributeID = attributeID; } if (active != null) { //Add options to the current attribute IAttributeOption option = new AttributeOption(); option.PickListValue = Convert.ToString(sph.DataReader["optionName"]); option.ShortCode = Convert.ToString(sph.DataReader["optionID"]); option.Url = Convert.ToString(sph.DataReader["optionData"]); option.Price = Convert.ToDecimal(sph.DataReader["optionPrice"]); active.AttributeOptionList.Add(option); } } } return attributeList; }