/// <summary> /// Returns where condition based on webpart fields. /// </summary> private WhereCondition GetWhereCondition() { var where = new WhereCondition().WhereEquals("SKUSiteID", SiteContext.CurrentSiteID); // Show products only from current site or global too, based on setting if (ECommerceSettings.AllowGlobalProducts(SiteContext.CurrentSiteName)) { where.Where(w => w.WhereEquals("SKUSiteID", SiteContext.CurrentSiteID).Or().WhereNull("SKUSiteID")); } // Show/hide product variants - it is based on type of inventory tracking for parent product string trackByVariants = TrackInventoryTypeEnum.ByVariants.ToStringRepresentation(); where.Where(v => v.Where(w => w.WhereNull("SKUParentSKUID").And().WhereNotEquals("SKUTrackInventory", trackByVariants)) .Or() .Where(GetParentProductWhereCondition(new WhereCondition().WhereEquals("SKUTrackInventory", trackByVariants)))); // Product type filter if (!string.IsNullOrEmpty(ProductType) && (ProductType != FILTER_ALL)) { if (ProductType == PRODUCT_TYPE_PRODUCTS) { where.WhereNull("SKUOptionCategoryID"); } else if (ProductType == PRODUCT_TYPE_PRODUCT_OPTIONS) { where.WhereNotNull("SKUOptionCategoryID"); } } // Representing filter if (!string.IsNullOrEmpty(Representing) && (Representing != FILTER_ALL)) { SKUProductTypeEnum productTypeEnum = Representing.ToEnum <SKUProductTypeEnum>(); string productTypeString = productTypeEnum.ToStringRepresentation(); where.WhereEquals("SKUProductType", productTypeString); } // Product number filter if (!string.IsNullOrEmpty(ProductNumber)) { where.WhereContains("SKUNumber", ProductNumber); } // Department filter DepartmentInfo di = DepartmentInfoProvider.GetDepartmentInfo(Department, CurrentSiteName); di = di ?? DepartmentInfoProvider.GetDepartmentInfo(Department, null); if (di != null) { where.Where(GetColumnWhereCondition("SKUDepartmentID", new WhereCondition().WhereEquals("SKUDepartmentID", di.DepartmentID))); } // Manufacturer filter ManufacturerInfo mi = ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, CurrentSiteName); mi = mi ?? ManufacturerInfoProvider.GetManufacturerInfo(Manufacturer, null); if (mi != null) { where.Where(GetColumnWhereCondition("SKUManufacturerID", new WhereCondition().WhereEquals("SKUManufacturerID", mi.ManufacturerID))); } // Brand filter BrandInfo bi = BrandInfoProvider.GetBrandInfo(Brand, CurrentSiteName); if (bi != null) { where.Where(GetColumnWhereCondition("SKUBrandID", new WhereCondition().WhereEquals("SKUBrandID", bi.BrandID))); } // Collection filter CollectionInfo ci = CollectionInfoProvider.GetCollectionInfo(Collection, CurrentSiteName); if (ci != null) { where.Where(GetColumnWhereCondition("SKUCollectionID", new WhereCondition().WhereEquals("SKUCollectionID", ci.CollectionID))); } // Tax class filter TaxClassInfo tci = TaxClassInfoProvider.GetTaxClassInfo(TaxClass, CurrentSiteName); if (tci != null) { where.Where(GetColumnWhereCondition("SKUTaxClassID", new WhereCondition().WhereEquals("SKUTaxClassID", tci.TaxClassID))); } // Supplier filter SupplierInfo si = SupplierInfoProvider.GetSupplierInfo(Supplier, CurrentSiteName); si = si ?? SupplierInfoProvider.GetSupplierInfo(Supplier, null); if (si != null) { where.Where(GetColumnWhereCondition("SKUSupplierID", new WhereCondition().WhereEquals("SKUSupplierID", si.SupplierID))); } // Needs shipping filter if (!string.IsNullOrEmpty(NeedsShipping) && (NeedsShipping != FILTER_ALL)) { if (NeedsShipping == NEEDS_SHIPPING_YES) { where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereTrue("SKUNeedsShipping"))); } else if (NeedsShipping == NEEDS_SHIPPING_NO) { where.Where(GetColumnWhereCondition("SKUNeedsShipping", new WhereCondition().WhereFalse("SKUNeedsShipping").Or().WhereNull("SKUNeedsShipping"))); } } // Price from filter if (PriceFrom > 0) { where.WhereGreaterOrEquals("SKUPrice", PriceFrom); } // Price to filter if (PriceTo > 0) { where.WhereLessOrEquals("SKUPrice", PriceTo); } // Public status filter PublicStatusInfo psi = PublicStatusInfoProvider.GetPublicStatusInfo(PublicStatus, CurrentSiteName); if (psi != null) { where.Where(GetColumnWhereCondition("SKUPublicStatusID", new WhereCondition().WhereEquals("SKUPublicStatusID", psi.PublicStatusID))); } // Internal status filter InternalStatusInfo isi = InternalStatusInfoProvider.GetInternalStatusInfo(InternalStatus, CurrentSiteName); if (isi != null) { where.Where(GetColumnWhereCondition("SKUInternalStatusID", new WhereCondition().WhereEquals("SKUInternalStatusID", isi.InternalStatusID))); } // Allow for sale filter if (!string.IsNullOrEmpty(AllowForSale) && (AllowForSale != FILTER_ALL)) { if (AllowForSale == ALLOW_FOR_SALE_YES) { where.WhereTrue("SKUEnabled"); } else if (AllowForSale == ALLOW_FOR_SALE_NO) { where.WhereEqualsOrNull("SKUEnabled", false); } } // Available items filter if (!string.IsNullOrEmpty(AvailableItems)) { int value = ValidationHelper.GetInteger(AvailableItems, int.MaxValue); where.WhereLessOrEquals("SKUAvailableItems", value); } // Needs to be reordered filter if (NeedsToBeReordered) { where.Where(w => w.Where(v => v.WhereNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems", 0)) .Or() .Where(z => z.WhereNotNull("SKUReorderAt").And().WhereLessOrEquals("SKUAvailableItems".AsColumn(), "SKUReorderAt".AsColumn()))); } return(where); }
private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { DataRowView rowView = parameter as DataRowView; if (rowView != null) { SKUInfo sku = new SKUInfo(rowView.Row); switch (sourceName.ToLowerCSafe()) { case "skuname": string fullName = sku.SKUName; // For variant, add name from parent SKU if (sku.SKUParentSKUID != 0) { SKUInfo parentSku = SKUInfoProvider.GetSKUInfo(sku.SKUParentSKUID); fullName = string.Format("{0}: {1}", parentSku.SKUName, sku.SKUName); } return(HTMLHelper.HTMLEncode(fullName)); case "optioncategory": OptionCategoryInfo optionCategory = OptionCategoryInfoProvider.GetOptionCategoryInfo(sku.SKUOptionCategoryID); // Return option category display name for product option or '-' for product if (optionCategory != null) { return(HTMLHelper.HTMLEncode(optionCategory.CategoryDisplayName ?? "")); } return("-"); case "skunumber": return(ResHelper.LocalizeString(sku.SKUNumber, null, true)); case "skuprice": // Format price return(CurrencyInfoProvider.GetFormattedPrice(sku.SKUPrice, sku.SKUSiteID)); case "skudepartmentid": // Transform to display name and localize DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo(sku.SKUDepartmentID); return((department != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(department.DepartmentDisplayName)) : ""); case "skumanufacturerid": // Transform to display name and localize ManufacturerInfo manufacturer = ManufacturerInfoProvider.GetManufacturerInfo(sku.SKUManufacturerID); return((manufacturer != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(manufacturer.ManufacturerDisplayName)) : ""); case "skubrandid": // Transform to display name and localize BrandInfo brand = BrandInfoProvider.GetBrandInfo(sku.SKUBrandID); return((brand != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(brand.BrandDisplayName)) : ""); case "skucollectionid": // Transform to display name and localize CollectionInfo collection = CollectionInfoProvider.GetCollectionInfo(sku.SKUCollectionID); return((collection != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(collection.CollectionDisplayName)) : ""); case "skutaxclassid": // Transform to display name and localize TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo(sku.SKUTaxClassID); return((taxClass != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(taxClass.TaxClassDisplayName)) : ""); case "skusupplierid": // Transform to display name and localize SupplierInfo supplier = SupplierInfoProvider.GetSupplierInfo(sku.SKUSupplierID); return((supplier != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(supplier.SupplierDisplayName)) : ""); case "skupublicstatusid": // Transform to display name and localize PublicStatusInfo publicStatus = PublicStatusInfoProvider.GetPublicStatusInfo(sku.SKUPublicStatusID); return((publicStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(publicStatus.PublicStatusDisplayName)) : ""); case "skuinternalstatusid": // Transform to display name and localize InternalStatusInfo internalStatus = InternalStatusInfoProvider.GetInternalStatusInfo(sku.SKUInternalStatusID); return((internalStatus != null) ? HTMLHelper.HTMLEncode(ResHelper.LocalizeString(internalStatus.InternalStatusDisplayName)) : ""); case "skuavailableitems": int?count = sku.SKUAvailableItems as int?; int?reorderAt = sku.SKUReorderAt as int?; // Emphasize the number when product needs to be reordered if (count.HasValue && ((reorderAt.HasValue && (count <= reorderAt)) || (!reorderAt.HasValue && (count <= 0)))) { // Format message informing about insufficient stock level return(string.Format("<span class=\"OperationFailed\">{0}</span>", count)); } return(count); case "itemstobereordered": int difference = sku.SKUReorderAt - sku.SKUAvailableItems; // Return difference, or '-' return((difference > 0) ? difference.ToString() : "-"); case "skusiteid": return(UniGridFunctions.ColoredSpanYesNo(sku.SKUSiteID == 0)); } } return(parameter); }