Implemented groundwork for search configuration.

This commit is contained in:
2021-07-22 16:12:27 -05:00
parent 3129e5e564
commit 2719142538
41 changed files with 1037 additions and 205 deletions

View File

@@ -25,7 +25,7 @@ namespace Props.Shop.Framework
public int MinPurchases { get; set; }
public bool KeepUnknownPurchaseCount { get; set; } = true;
public int MinReviews { get; set; }
public bool KeepUnknownRatingCount { get; set; } = true;
public bool KeepUnknownReviewCount { get; set; } = true;
public bool EnableMaxShippingFee { get; set; }
private int maxShippingFee;
@@ -59,7 +59,7 @@ namespace Props.Shop.Framework
MinPurchases == other.MinPurchases &&
KeepUnknownPurchaseCount == other.KeepUnknownPurchaseCount &&
MinReviews == other.MinReviews &&
KeepUnknownRatingCount == other.KeepUnknownRatingCount &&
KeepUnknownReviewCount == other.KeepUnknownReviewCount &&
EnableMaxShippingFee == other.EnableMaxShippingFee &&
MaxShippingFee == other.MaxShippingFee &&
KeepUnknownShipping == other.KeepUnknownShipping;
@@ -81,5 +81,16 @@ namespace Props.Shop.Framework
{
return (Filters)this.MemberwiseClone();
}
public bool Validate(ProductListing listing)
{
if (listing.Shipping == null && !KeepUnknownShipping || (EnableMaxShippingFee && listing.Shipping > MaxShippingFee)) return false;
float shippingDifference = listing.Shipping != null ? listing.Shipping.Value : 0;
if (!(listing.LowerPrice + shippingDifference >= LowerPrice && (!EnableUpperPrice || listing.UpperPrice + shippingDifference <= UpperPrice))) return false;
if ((listing.Rating == null && !KeepUnrated) && MinRating > (listing.Rating == null ? 0 : listing.Rating)) return false;
if ((listing.PurchaseCount == null && !KeepUnknownPurchaseCount) || MinPurchases > (listing.PurchaseCount == null ? 0 : listing.PurchaseCount)) return false;
if ((listing.ReviewCount == null && !KeepUnknownReviewCount) || MinReviews > (listing.ReviewCount == null ? 0 : listing.ReviewCount)) return false;
return true;
}
}
}