From ee6f45f130635f73d4f8ec5988204baec10b38fc Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Mon, 16 Sep 2024 17:49:29 +0200 Subject: [PATCH 1/3] VCST-1811: Extend Product schema with PackSize feat: Extends Product schema with PackSize --- src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs | 1 + src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs | 6 ++++++ .../VirtoCommerce.XCatalog.Core.csproj | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs b/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs index 6ef8bd5..2dccca3 100644 --- a/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs +++ b/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs @@ -74,6 +74,7 @@ public ProductType(IMediator mediator, IDataLoaderContextAccessor dataLoader) Field(d => d.IndexedProduct.ProductType, nullable: true).Description("The type of product"); Field(d => d.IndexedProduct.MinQuantity, nullable: true).Description("Min. quantity"); Field(d => d.IndexedProduct.MaxQuantity, nullable: true).Description("Max. quantity"); + Field(d => d.IndexedProduct.PackSize, nullable: false).Description("Defines the number of items in a package."); FieldAsync("outline", resolve: async context => { diff --git a/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs b/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs index 77291c1..dce0536 100644 --- a/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs +++ b/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs @@ -53,6 +53,12 @@ public VariationType(IMediator mediator) resolve: context => context.Source.IndexedProduct.MaxQuantity ); + Field( + "packSize", + description: "Defines the number of items in a package.", + resolve: context => context.Source.IndexedProduct.PackSize + ); + ExtendableField>( "availabilityData", "Availability data", diff --git a/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj b/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj index 4592d55..4ddf758 100644 --- a/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj +++ b/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj @@ -11,7 +11,7 @@ - + From e59b1636d3ddbc76eb1e81e773b0ab9ed0c17132 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Tue, 17 Sep 2024 13:22:16 +0200 Subject: [PATCH 2/3] VCST-1811: Add Validators for PackSize feat: Quantity should be is a multiple of PackSize. feat: Ensures that minQuantity is a multiple of PackSize. --- .../Schemas/ProductType.cs | 2 +- .../Schemas/VariationType.cs | 2 +- .../Extensions/ServiceCollectionExtensions.cs | 1 + .../Middlewares/PackSizeResolveMiddleware.cs | 29 +++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/VirtoCommerce.XCatalog.Data/Middlewares/PackSizeResolveMiddleware.cs diff --git a/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs b/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs index 2dccca3..1f9e842 100644 --- a/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs +++ b/src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs @@ -74,7 +74,7 @@ public ProductType(IMediator mediator, IDataLoaderContextAccessor dataLoader) Field(d => d.IndexedProduct.ProductType, nullable: true).Description("The type of product"); Field(d => d.IndexedProduct.MinQuantity, nullable: true).Description("Min. quantity"); Field(d => d.IndexedProduct.MaxQuantity, nullable: true).Description("Max. quantity"); - Field(d => d.IndexedProduct.PackSize, nullable: false).Description("Defines the number of items in a package."); + Field(d => d.IndexedProduct.PackSize, nullable: false).Description("Defines the number of items in a package. Quantity step for your product's."); FieldAsync("outline", resolve: async context => { diff --git a/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs b/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs index dce0536..0d53fac 100644 --- a/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs +++ b/src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs @@ -55,7 +55,7 @@ public VariationType(IMediator mediator) Field( "packSize", - description: "Defines the number of items in a package.", + description: "Defines the number of items in a package. Quantity step for your product's.", resolve: context => context.Source.IndexedProduct.PackSize ); diff --git a/src/VirtoCommerce.XCatalog.Data/Extensions/ServiceCollectionExtensions.cs b/src/VirtoCommerce.XCatalog.Data/Extensions/ServiceCollectionExtensions.cs index 1574406..c5628bb 100644 --- a/src/VirtoCommerce.XCatalog.Data/Extensions/ServiceCollectionExtensions.cs +++ b/src/VirtoCommerce.XCatalog.Data/Extensions/ServiceCollectionExtensions.cs @@ -21,6 +21,7 @@ public static IServiceCollection AddXCatalog(this IServiceCollection services, I { builder.AddMiddleware(typeof(EnsureCatalogProductLoadedMiddleware)); builder.AddMiddleware(typeof(RemoveNullCatalogProductsMiddleware)); + builder.AddMiddleware(typeof(PackSizeResolveMiddleware)); builder.AddMiddleware(typeof(EvalProductsPricesMiddleware)); builder.AddMiddleware(typeof(EvalProductsDiscountsMiddleware)); builder.AddMiddleware(typeof(EvalProductsTaxMiddleware)); diff --git a/src/VirtoCommerce.XCatalog.Data/Middlewares/PackSizeResolveMiddleware.cs b/src/VirtoCommerce.XCatalog.Data/Middlewares/PackSizeResolveMiddleware.cs new file mode 100644 index 0000000..f862de0 --- /dev/null +++ b/src/VirtoCommerce.XCatalog.Data/Middlewares/PackSizeResolveMiddleware.cs @@ -0,0 +1,29 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using PipelineNet.Middleware; +using VirtoCommerce.XCatalog.Core.Models; + +namespace VirtoCommerce.XCatalog.Data.Middlewares +{ + public class PackSizeResolveMiddleware : IAsyncMiddleware + { + public Task Run(SearchProductResponse parameter, Func next) + { + var productsWithPackSize = parameter.Results.Where(expProduct => expProduct.IndexedProduct.PackSize > 1).Select(x => x.IndexedProduct); + + foreach (var product in productsWithPackSize) + { + var minQuantity = Math.Max(product.MinQuantity ?? 1, product.PackSize); + // Ensure minQuantity is a multiple of PackSize + if (minQuantity % product.PackSize > 0) + { + minQuantity = (minQuantity / product.PackSize + 1) * product.PackSize; + } + product.MinQuantity = minQuantity; + } + + return next(parameter); + } + } +} From 0b10e670d2e57f6f2a8cdb143cff22c2ac58c8a9 Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Fri, 20 Sep 2024 18:20:44 +0200 Subject: [PATCH 3/3] Bump VirtoCommerce.Catalog to 3.820.0. --- .../VirtoCommerce.XCatalog.Core.csproj | 2 +- src/VirtoCommerce.XCatalog.Web/module.manifest | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj b/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj index 4ddf758..ef5257d 100644 --- a/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj +++ b/src/VirtoCommerce.XCatalog.Core/VirtoCommerce.XCatalog.Core.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/VirtoCommerce.XCatalog.Web/module.manifest b/src/VirtoCommerce.XCatalog.Web/module.manifest index 275c28a..896c947 100644 --- a/src/VirtoCommerce.XCatalog.Web/module.manifest +++ b/src/VirtoCommerce.XCatalog.Web/module.manifest @@ -7,7 +7,7 @@ 3.841.0 - +