Skip to content
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

VCST-1811: Extend Product schema with PackSize #12

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/VirtoCommerce.XCatalog.Core/Schemas/ProductType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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. Quantity step for your product's.");

FieldAsync<StringGraphType>("outline", resolve: async context =>
{
Expand Down
6 changes: 6 additions & 0 deletions src/VirtoCommerce.XCatalog.Core/Schemas/VariationType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public VariationType(IMediator mediator)
resolve: context => context.Source.IndexedProduct.MaxQuantity
);

Field<IntGraphType>(
"packSize",
description: "Defines the number of items in a package. Quantity step for your product's.",
resolve: context => context.Source.IndexedProduct.PackSize
);

ExtendableField<NonNullGraphType<AvailabilityDataType>>(
"availabilityData",
"Availability data",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.807.0" />
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.820.0" />
<PackageReference Include="VirtoCommerce.InventoryModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.MarketingModule.Core" Version="3.800.0" />
<PackageReference Include="VirtoCommerce.PricingModule.Core" Version="3.800.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SearchProductResponse>
{
public Task Run(SearchProductResponse parameter, Func<SearchProductResponse, Task> 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);
}
}
}
2 changes: 1 addition & 1 deletion src/VirtoCommerce.XCatalog.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<platformVersion>3.841.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Xapi" version="3.800.0" />
<dependency id="VirtoCommerce.Catalog" version="3.800.0" />
<dependency id="VirtoCommerce.Catalog" version="3.820.0" />
<dependency id="VirtoCommerce.Inventory" version="3.800.0" optional="true" />
<dependency id="VirtoCommerce.Marketing" version="3.800.0" optional="true" />
<dependency id="VirtoCommerce.Pricing" version="3.800.0" optional="true" />
Expand Down
Loading