-
Notifications
You must be signed in to change notification settings - Fork 93
Add Start and End time to ProductPart #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting concept, but this is not a core product feature, so it shouldn't be in Move these fields into a new content part. As this is related to availability, it should be in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| using OrchardCore.Commerce.Indexes; | ||
| using OrchardCore.Commerce.Models; | ||
| using OrchardCore.ContentManagement; | ||
| using OrchardCore.ContentManagement.Metadata; | ||
| using OrchardCore.ContentManagement.Metadata.Records; | ||
| using OrchardCore.ContentManagement.Records; | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
@@ -41,6 +43,12 @@ public async Task<ProductList> GetProductsAsync(ProductListPart productList, Pro | |
|
|
||
| var query = _session.Query<ContentItem>(); | ||
| query = query.With<ContentItemIndex>(index => index.ContentType.IsIn(productTypes) && index.Published); | ||
|
|
||
| // Filter products by start and end time | ||
| var utcNow = DateTime.UtcNow; | ||
| query = query.With<ProductPartIndex>(index => | ||
| (index.StartTimeUtc == null || index.StartTimeUtc <= utcNow) && | ||
| (index.EndTimeUtc == null || index.EndTimeUtc >= utcNow)); | ||
|
Comment on lines
+47
to
+51
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a new |
||
|
|
||
| var context = new ProductListFilterContext | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,12 @@ public virtual async Task<IEnumerable<ProductPart>> GetProductsAsync(IEnumerable | |
| { | ||
| var trimmedSkus = skus.Select(sku => sku.Split('-')[0]); | ||
|
|
||
| var utcNow = DateTime.UtcNow; | ||
| var contentItemIds = (await _session | ||
| .QueryIndex<ProductPartIndex>(index => index.Sku.IsIn(trimmedSkus)) | ||
| .QueryIndex<ProductPartIndex>(index => | ||
| index.Sku.IsIn(trimmedSkus) && | ||
| (index.StartTimeUtc == null || index.StartTimeUtc <= utcNow) && | ||
| (index.EndTimeUtc == null || index.EndTimeUtc >= utcNow)) | ||
|
Comment on lines
+43
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .ListAsync()) | ||
| .Select(idx => idx.ContentItemId) | ||
| .Distinct(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary. Content fields like
DateTimeFieldalready create an index on their own (in this caseDateTimeFieldIndex) which you can join in your query. Please revert the changes inProductPartIndexandProductMigrations