Skip to content

Commit

Permalink
VCST-2305: Update ApplyRewards() (#24)
Browse files Browse the repository at this point in the history
* Update ApplyRewards()

* Update dependencies

* Update dependencies

* Fix naming

* Update dependencies
  • Loading branch information
artem-dudarev authored Dec 19, 2024
1 parent fee6a09 commit dbef59a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void ApplyRewards(this List<ProductPrice> productPrices, CatalogIt
var rewardsMap = productPrices
.Select(x => x.Currency)
.Distinct()
.ToDictionary(x => x, x => rewards);
.ToDictionary(x => x, _ => rewards);

foreach (var productPrice in productPrices)
{
Expand All @@ -45,7 +45,7 @@ public static void ApplyRewards(this List<ProductPrice> productPrices, CatalogIt

var discount = new Discount
{
DiscountAmount = reward.GetRewardAmount(priceAmount, 1),
DiscountAmount = reward.GetTotalAmount(priceAmount, 1, productPrice.Currency),
Description = reward.Promotion.Description,
Coupon = reward.Coupon,
PromotionId = reward.Promotion.Id
Expand All @@ -59,7 +59,7 @@ public static void ApplyRewards(this List<ProductPrice> productPrices, CatalogIt

foreach (var tierPrice in productPrice.TierPrices)
{
tierPrice.DiscountAmount += reward.GetRewardAmount(tierPrice.Price.Amount, 1);
tierPrice.DiscountAmount += reward.GetTotalAmount(tierPrice.Price.Amount, 1, productPrice.Currency);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/VirtoCommerce.XCatalog.Core/Models/ExpProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public virtual void ApplyRewards(CatalogItemAmountReward[] allRewards)
var rewardsMap = AllPrices
.Select(x => x.Currency)
.Distinct()
.ToDictionary(x => x, x => productRewards);
.ToDictionary(x => x, _ => productRewards);

foreach (var productPrice in AllPrices)
{
Expand All @@ -146,7 +146,7 @@ public virtual void ApplyRewards(CatalogItemAmountReward[] allRewards)

var discount = new Discount
{
DiscountAmount = reward.GetRewardAmount(priceAmount, 1),
DiscountAmount = reward.GetTotalAmount(priceAmount, 1, productPrice.Currency),
Description = reward.Promotion.Description,
Coupon = reward.Coupon,
PromotionId = reward.Promotion.Id
Expand All @@ -160,7 +160,7 @@ public virtual void ApplyRewards(CatalogItemAmountReward[] allRewards)

foreach (var tierPrice in productPrice.TierPrices)
{
tierPrice.DiscountAmount += reward.GetRewardAmount(tierPrice.ActualPrice.Amount, 1);
tierPrice.DiscountAmount += reward.GetTotalAmount(tierPrice.ActualPrice.Amount, 1, productPrice.Currency);
}
}
}
Expand All @@ -172,11 +172,11 @@ public virtual void ApplyStoreInventories(IEnumerable<InventoryInfo> inventories
ArgumentNullException.ThrowIfNull(inventories);
ArgumentNullException.ThrowIfNull(store);

var availFullfilmentCentersIds = (store.AdditionalFulfillmentCenterIds ?? Array.Empty<string>()).Concat(new[] { store.MainFulfillmentCenterId });
var availFulfilmentCentersIds = (store.AdditionalFulfillmentCenterIds ?? Array.Empty<string>()).Concat([store.MainFulfillmentCenterId]);

AllInventories.Clear();
Inventory = null;
AllInventories = inventories.Where(x => x.ProductId == Id && availFullfilmentCentersIds.Contains(x.FulfillmentCenterId)).ToList();
AllInventories = inventories.Where(x => x.ProductId == Id && availFulfilmentCentersIds.Contains(x.FulfillmentCenterId)).ToList();

Inventory = AllInventories.OrderByDescending(x => Math.Max(0, x.InStockQuantity - x.ReservedQuantity)).FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.815.0" />
<PackageReference Include="VirtoCommerce.CatalogModule.Core" Version="3.830.0" />
<PackageReference Include="VirtoCommerce.InventoryModule.Core" Version="3.805.0" />
<PackageReference Include="VirtoCommerce.MarketingModule.Core" Version="3.812.0" />
<PackageReference Include="VirtoCommerce.MarketingModule.Core" Version="3.815.0" />
<PackageReference Include="VirtoCommerce.PricingModule.Core" Version="3.809.0" />
<PackageReference Include="VirtoCommerce.Tools" Version="3.808.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/VirtoCommerce.XCatalog.Web/module.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<version>3.820.0</version>
<version-tag></version-tag>

<platformVersion>3.853.0</platformVersion>
<platformVersion>3.867.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Catalog" version="3.830.0" />
<dependency id="VirtoCommerce.Inventory" version="3.805.0" optional="true" />
<dependency id="VirtoCommerce.Marketing" version="3.812.0" optional="true" />
<dependency id="VirtoCommerce.Marketing" version="3.815.0" optional="true" />
<dependency id="VirtoCommerce.Pricing" version="3.809.0" optional="true" />
<dependency id="VirtoCommerce.Xapi" version="3.815.0" />
</dependencies>
Expand Down

0 comments on commit dbef59a

Please sign in to comment.