Skip to content

Commit

Permalink
VP-3582: Add outlines property to product for promotion evaluation (#484
Browse files Browse the repository at this point in the history
)

* VP-3582: Add outlines property to product for promotion evaluation

* VP-3582: Remove unnecessary import

* Revert "VP-3582: Remove unnecessary import"

This reverts commit d0faad2.

* VP-3582: Remove unnecessary import

* VP-3582: Make separate method for getting outlines path

* VP-3582: Get relative paths for specific catalog

* VP-3582: Change outlines description

Co-authored-by: Andrey Kozlov <[email protected]>
  • Loading branch information
ilyawzrd and yecli authored Jul 29, 2020
1 parent 36a4f3a commit 4504532
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions VirtoCommerce.Storefront.Model/Catalog/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public Product(Currency currency, Language language)
/// </summary>
public string Outline { get; set; }
/// <summary>
/// All relative product outlines for the given catalog
/// </summary>
public string Outlines { get; set; }
/// <summary>
/// Slug path e.g /camcorders/blue-win-camera
/// </summary>
public string SeoPath { get; set; }
Expand Down
3 changes: 2 additions & 1 deletion VirtoCommerce.Storefront/Domain/Cart/CartConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,8 @@ public static marketingDto.ProductPromoEntry ToProductPromoEntryDto(this LineIte
Price = (double)lineItem.SalePrice.Amount,
Quantity = lineItem.Quantity,
InStockQuantity = lineItem.InStockQuantity,
Outline = lineItem.Product.Outline,
// VP-3582: We need to pass all product outlines as 1 string to use them for promotion evaluation
Outline = lineItem.Product.Outlines,
Variations = null // TODO
};

Expand Down
5 changes: 4 additions & 1 deletion VirtoCommerce.Storefront/Domain/Catalog/CatalogConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ public static Product ToProduct(this catalogDto.Product productDto, Language cur
Length = (decimal?)productDto.Length,
Sku = productDto.Code,
Outline = productDto.Outlines.GetOutlinePath(store.Catalog),
// VP-3582: We need to store all product outlines to use them for promotion evaluation
Outlines = productDto.Outlines.GetOutlinePaths(store.Catalog),
SeoPath = productDto.Outlines.GetSeoPath(store, currentLanguage, null),
};
result.Url = "/" + (result.SeoPath ?? "product/" + result.Id);
Expand Down Expand Up @@ -434,7 +436,8 @@ public static marketingDto.ProductPromoEntry ToProductPromoEntryDto(this Product
{
CatalogId = product.CatalogId,
CategoryId = product.CategoryId,
Outline = product.Outline,
// VP-3582: We need to pass all product outlines as 1 string to use them for promotion evaluation
Outline = product.Outlines,
Code = product.Sku,
ProductId = product.Id,
Quantity = 1,
Expand Down
38 changes: 38 additions & 0 deletions VirtoCommerce.Storefront/Extensions/OutlineExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.Storefront.Model.Catalog;
using VirtoCommerce.Storefront.Model.Common;
using VirtoCommerce.Tools;
using catalogDto = VirtoCommerce.Storefront.AutoRestClients.CatalogModuleApi.Models;
using toolsDto = VirtoCommerce.Tools.Models;
Expand Down Expand Up @@ -40,5 +41,42 @@ public static string GetCategoryOutline(this Product product)

return result;
}

/// <summary>
/// Returns all concatinated relative outlines for the given catalog
/// </summary>
/// <param name="outlines"></param>
/// <param name="catalogId"></param>
/// <returns></returns>
public static string GetOutlinePaths(this IEnumerable<catalogDto.Outline> outlines, string catalogId)
{
var result = string.Empty;
var catalogOutlines = outlines?.Where(o => o.Items.Any(i => i.SeoObjectType == "Catalog" && i.Id == catalogId));
var outlinesList = catalogOutlines?
.Where(x => x != null)
.Select(x => x.ToCatalogRelativePath())
.ToList();

if (!outlinesList.IsNullOrEmpty())
{
result = string.Join(";", outlinesList);
}

return result;
}

/// <summary>s
/// Returns catalog's relative outline path
/// </summary>
/// <param name="outline"></param>
/// <returns></returns>
public static string ToCatalogRelativePath(this catalogDto.Outline outline)
{
return outline.Items == null ? null : string.Join("/",
outline.Items
.Where(x => x != null && x.SeoObjectType != "Catalog")
.Select(x => x.Id)
);
}
}
}

0 comments on commit 4504532

Please sign in to comment.