Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
merge from dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarincev committed Jul 5, 2016
2 parents ea226d8 + 48401eb commit dfe48ce
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static ShopifyThemeWorkContext ToShopifyModel(this storefrontModel.WorkCo
result.RequestUrl = workContext.RequestUrl.ToString();
//Populate current page number
var qs = HttpUtility.ParseQueryString(workContext.RequestUrl.Query);
result.CurrentPage = Convert.ToInt32(qs.Get("page") ?? 1.ToString());
result.CurrentPage = workContext.PageNumber ?? 1;
result.PageSize = workContext.PageSize ?? 0;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class ShopifyThemeWorkContext : ILiquidizable
public Collections Collections { get; set; }

public int CurrentPage { get; set; }
public int PageSize { get; set; }

public TagCollection CurrentTags { get; set; }

Expand Down
5 changes: 3 additions & 2 deletions VirtoCommerce.LiquidThemeEngine/Tags/PaginateTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ public override void Render(Context context, TextWriter result)
Uri requestUrl;
Uri.TryCreate(context["request_url"] as string, UriKind.RelativeOrAbsolute, out requestUrl);
var pageNumber = (int)context["current_page"];

var pageSize = (int)context["page_size"];

if (mutablePagedList != null)
{
mutablePagedList.Slice(pageNumber, _pageSize > 0 ? _pageSize : 20);
mutablePagedList.Slice(pageNumber, pageSize > 0 ? pageSize : _pageSize);
pagedList = mutablePagedList;
}
else if (collection != null)
Expand Down
12 changes: 8 additions & 4 deletions VirtoCommerce.Storefront.Model/Cart/LineItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,17 @@ public Money DiscountTotalWithTax

public void ApplyTaxRates(IEnumerable<TaxRate> taxRates)
{
var lineItemTaxRates = taxRates.Where(x => x.Line.Id == Id);
ListPriceWithTax = ListPrice;
SalePriceWithTax = SalePrice;

//Because TaxLine.Id may contains composite string id & extra info
var lineItemTaxRates = taxRates.Where(x => x.Line.Id.SplitIntoTuple('&').Item1 == Id);
TaxTotal = new Money(Currency);
if (lineItemTaxRates.Any())
{
var extendedPriceRate = lineItemTaxRates.First(x => x.Line.Code.EqualsInvariant("extended"));
var listPriceRate = lineItemTaxRates.First(x => x.Line.Code.EqualsInvariant("list"));
var salePriceRate = lineItemTaxRates.FirstOrDefault(x => x.Line.Code.EqualsInvariant("sale"));
var extendedPriceRate = lineItemTaxRates.First(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("extended"));
var listPriceRate = lineItemTaxRates.First(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("list"));
var salePriceRate = lineItemTaxRates.FirstOrDefault(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("sale"));
if (salePriceRate == null)
{
salePriceRate = listPriceRate;
Expand Down
11 changes: 7 additions & 4 deletions VirtoCommerce.Storefront.Model/Cart/Shipment.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using VirtoCommerce.Storefront.Model.Cart.Services;
using VirtoCommerce.Storefront.Model.Cart.ValidationErrors;
Expand Down Expand Up @@ -215,12 +216,14 @@ public Money SubtotalWithTax

public void ApplyTaxRates(IEnumerable<TaxRate> taxRates)
{
var shipmentTaxRates = taxRates.Where(x=>x.Line.Id == Id);
ShippingPriceWithTax = ShippingPrice;
//Because TaxLine.Id may contains composite string id & extra info
var shipmentTaxRates = taxRates.Where(x => x.Line.Id.SplitIntoTuple('&').Item1 == Id);
TaxTotal = new Money(Currency);
if(shipmentTaxRates.Any())
{
var totalTaxRate = shipmentTaxRates.First(x => x.Line.Code.EqualsInvariant("total"));
var priceTaxRate = shipmentTaxRates.First(x => x.Line.Code.EqualsInvariant("price"));
var totalTaxRate = shipmentTaxRates.First(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("total"));
var priceTaxRate = shipmentTaxRates.First(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("price"));
TaxTotal += totalTaxRate.Rate;
ShippingPriceWithTax = ShippingPrice + priceTaxRate.Rate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public CatalogSearchCriteria(Language language, Currency currency, NameValueColl
: base(queryString)
{
Language = language;
Currency = currency;
ResponseGroup = CatalogSearchResponseGroup.WithProducts | CatalogSearchResponseGroup.WithCategories | CatalogSearchResponseGroup.WithProperties | CatalogSearchResponseGroup.WithOutlines;
Currency = currency;
SearchInChildren = true;

Parse(queryString);
Expand Down Expand Up @@ -66,6 +65,7 @@ private void Parse(NameValueCollection queryString)
//TODO move this code to Parse or Converter method
// tags=name1:value1,value2,value3;name2:value1,value2,value3
SearchInChildren = Convert.ToBoolean(queryString.Get("deep_search") ?? SearchInChildren.ToString());
ResponseGroup = EnumUtility.SafeParse(queryString.Get("resp_group"), CatalogSearchResponseGroup.WithProducts | CatalogSearchResponseGroup.WithCategories | CatalogSearchResponseGroup.WithProperties | CatalogSearchResponseGroup.WithOutlines);
SortBy = queryString.Get("sort_by");
Terms = (queryString.GetValues("terms") ?? new string[0])
.SelectMany(s => s.Split(';'))
Expand Down
12 changes: 8 additions & 4 deletions VirtoCommerce.Storefront.Model/Catalog/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,16 @@ public void ApplyPrices(IEnumerable<ProductPrice> prices, Currency currentCurren

public void ApplyTaxRates(IEnumerable<TaxRate> taxRates)
{
var productTaxRates = taxRates.Where(x => x.Line.Id == Id);
Price.ListPriceWithTax = Price.ListPrice;
Price.SalePriceWithTax = Price.SalePrice;

//Because TaxLine.Id may contains composite string id & extra info
var productTaxRates = taxRates.Where(x => x.Line.Id.SplitIntoTuple('&').Item1 == Id);
TaxTotal = new Money(Currency);
if (productTaxRates.Any())
{
var listPriceRate = productTaxRates.First(x => x.Line.Code.EqualsInvariant("list"));
var salePriceRate = productTaxRates.FirstOrDefault(x => x.Line.Code.EqualsInvariant("sale"));
var listPriceRate = productTaxRates.First(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("list"));
var salePriceRate = productTaxRates.FirstOrDefault(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant("sale"));
if(salePriceRate == null)
{
salePriceRate = listPriceRate;
Expand All @@ -327,7 +331,7 @@ public void ApplyTaxRates(IEnumerable<TaxRate> taxRates)
//Apply tax for tier prices
foreach (var tierPrice in Price.TierPrices)
{
var tierPriceTaxRate = productTaxRates.FirstOrDefault(x => x.Line.Code.EqualsInvariant(tierPrice.Quantity.ToString()));
var tierPriceTaxRate = productTaxRates.FirstOrDefault(x => x.Line.Id.SplitIntoTuple('&').Item2.EqualsInvariant(tierPrice.Quantity.ToString()));
if(tierPrice != null)
{
tierPrice.Tax = tierPriceTaxRate.Rate;
Expand Down
5 changes: 3 additions & 2 deletions VirtoCommerce.Storefront.Model/Common/PagedSearchCriteria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
namespace VirtoCommerce.Storefront.Model.Common
{
public class PagedSearchCriteria
{
{
public PagedSearchCriteria(NameValueCollection queryString)
{
PageNumber = Convert.ToInt32(queryString.Get("page") ?? 1.ToString());
PageSize = Convert.ToInt32(queryString.Get("count") ?? 10.ToString());
PageSize = Convert.ToInt32(queryString.Get("count") ?? queryString.Get("page_size") ?? 20.ToString());
}

public int Start
{
get
Expand Down
22 changes: 22 additions & 0 deletions VirtoCommerce.Storefront.Model/Common/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -45,5 +46,26 @@ public static bool FitsMask(this string fileName, string fileMask)
var mask = new Regex(fileMask.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."), RegexOptions.IgnoreCase);
return mask.IsMatch(fileName);
}

public static int? ToNullableInt(this string str)
{
int retVal;
if (int.TryParse(str, out retVal))
{
return retVal;
}
return null;
}

public static Tuple<string, string> SplitIntoTuple(this string input, char separator)
{
if(input == null)
{
throw new ArgumentNullException("input");
}

var pieces = input.Split(separator);
return Tuple.Create(pieces.FirstOrDefault(), pieces.Skip(1).FirstOrDefault());
}
}
}
2 changes: 1 addition & 1 deletion VirtoCommerce.Storefront.Model/ShippingMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Money DiscountTotalWithTax

public void ApplyTaxRates(IEnumerable<TaxRate> taxRates)
{
var shippingMethodTaxRates = taxRates.Where(x => x.Line.Id == ShipmentMethodCode);
var shippingMethodTaxRates = taxRates.Where(x => x.Line.Id.SplitIntoTuple('&').Item1 == ShipmentMethodCode && x.Line.Id.SplitIntoTuple('&').Item2 == OptionName);
TaxTotal = new Money(Currency);

var shippingMethodTaxRate = shippingMethodTaxRates.FirstOrDefault();
Expand Down
13 changes: 13 additions & 0 deletions VirtoCommerce.Storefront.Model/WorkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public SeoInfo CurrentPageSeo
/// Current search catalog criterias
/// </summary>
public CatalogSearchCriteria CurrentCatalogSearchCriteria { get; set; }
/// <summary>
/// Current product response group
/// </summary>
public ItemResponseGroup CurrentProductResponseGroup { get; set; }

#endregion

Expand Down Expand Up @@ -194,6 +198,15 @@ public DateTime StorefrontUtcNow
/// </summary>
public IDictionary<string, object> ApplicationSettings { get; set; }

/// <summary>
/// Current page number
/// </summary>
public int? PageNumber { get; set; }
/// <summary>
/// Current page size
/// </summary>
public int? PageSize { get; set; }

#region IDisposable Implementation

public void Dispose()
Expand Down
1 change: 0 additions & 1 deletion VirtoCommerce.Storefront/Builders/CartBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ public virtual async Task<ICollection<ShippingMethod>> GetAvailableShippingMetho
}
//Evaluate tax for shipping methods
var taxEvalContext = _cart.ToTaxEvalContext();
taxEvalContext.Lines.Clear();
taxEvalContext.Lines.AddRange(availableShippingMethods.Select(x => x.ToTaxLine()));
var taxResult = await _commerceApi.CommerceEvaluateTaxesAsync(_cart.StoreId, taxEvalContext);
if (taxResult != null)
Expand Down
7 changes: 1 addition & 6 deletions VirtoCommerce.Storefront/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ public ProductController(WorkContext context, IStorefrontUrlBuilder urlBuilder,
[HttpGet]
public async Task<ActionResult> ProductDetails(string productId)
{
var product = (await _catalogSearchService.GetProductsAsync(new[] { productId },
Model.Catalog.ItemResponseGroup.Variations |
Model.Catalog.ItemResponseGroup.ItemProperties |
Model.Catalog.ItemResponseGroup.ItemSmall |
Model.Catalog.ItemResponseGroup.ItemWithPrices |
Model.Catalog.ItemResponseGroup.ItemAssociations)).FirstOrDefault();
var product = (await _catalogSearchService.GetProductsAsync(new[] { productId }, WorkContext.CurrentProductResponseGroup)).FirstOrDefault();
WorkContext.CurrentProduct = product;

if(product.CategoryId != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static coreModel.TaxLine ToTaxLine(this ShippingMethod shipmentMethod)
{
var retVal = new coreModel.TaxLine
{
Id = shipmentMethod.ShipmentMethodCode,
Code = shipmentMethod.ShipmentMethodCode,
Name = shipmentMethod.ShipmentMethodCode,
Id = string.Join("&", shipmentMethod.ShipmentMethodCode, shipmentMethod.OptionName),
Code = string.Join("&", shipmentMethod.ShipmentMethodCode, shipmentMethod.OptionName),
Name = string.Join("&", shipmentMethod.Name, shipmentMethod.OptionDescription),
TaxType = shipmentMethod.TaxType,
Amount = (double)shipmentMethod.Price.Amount
};
Expand All @@ -28,8 +28,8 @@ public static coreModel.TaxLine[] ToListAndSaleTaxLines(this Product product)
{
new coreModel.TaxLine
{
Id = product.Id,
Code = "list",
Id = product.Id + "&list",
Code = product.Sku,
Name = product.Name,
TaxType = product.TaxType,
Amount = (double) product.Price.ListPrice.Amount
Expand All @@ -41,8 +41,8 @@ public static coreModel.TaxLine[] ToListAndSaleTaxLines(this Product product)
{
retVal.Add(new coreModel.TaxLine
{
Id = product.Id,
Code = "sale",
Id = product.Id + "&sale",
Code = product.Sku,
Name = product.Name,
TaxType = product.TaxType,
Amount = (double)product.Price.SalePrice.Amount
Expand All @@ -54,8 +54,8 @@ public static coreModel.TaxLine[] ToListAndSaleTaxLines(this Product product)
{
retVal.Add(new coreModel.TaxLine
{
Id = product.Id,
Code = tierPrice.Quantity.ToString(),
Id = product.Id + "&" + tierPrice.Quantity.ToString(),
Code = product.Sku,
Name = product.Name,
TaxType = product.TaxType,
Amount = (double)tierPrice.Price.Amount
Expand Down Expand Up @@ -101,8 +101,8 @@ public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart
{
var extendedTaxLine = new coreModel.TaxLine
{
Id = lineItem.Id,
Code = "extended",
Id = lineItem.Id + "&extended",
Code = lineItem.Sku,
Name = lineItem.Name,
TaxType = lineItem.TaxType,
Amount = (double)lineItem.ExtendedPrice.Amount
Expand All @@ -111,8 +111,8 @@ public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart

var listTaxLine = new coreModel.TaxLine
{
Id = lineItem.Id,
Code = "list",
Id = lineItem.Id + "&list",
Code = lineItem.Sku,
Name = lineItem.Name,
TaxType = lineItem.TaxType,
Amount = (double)lineItem.ListPrice.Amount
Expand All @@ -123,8 +123,8 @@ public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart
{
var saleTaxLine = new coreModel.TaxLine
{
Id = lineItem.Id,
Code = "sale",
Id = lineItem.Id + "&sale",
Code = lineItem.Sku,
Name = lineItem.Name,
TaxType = lineItem.TaxType,
Amount = (double)lineItem.SalePrice.Amount
Expand All @@ -137,17 +137,17 @@ public static coreModel.TaxEvaluationContext ToTaxEvalContext(this ShoppingCart
{
var totalTaxLine = new coreModel.TaxLine
{
Id = shipment.Id,
Code = "total",
Id = shipment.Id + "&total",
Code = shipment.ShipmentMethodCode,
Name = shipment.ShipmentMethodCode,
TaxType = shipment.TaxType,
Amount = (double)shipment.Total.Amount
};
retVal.Lines.Add(totalTaxLine);
var priceTaxLine = new coreModel.TaxLine
{
Id = shipment.Id,
Code = "price",
Id = shipment.Id + "&price",
Code = shipment.ShipmentMethodCode,
Name = shipment.ShipmentMethodCode,
TaxType = shipment.TaxType,
Amount = (double)shipment.ShippingPrice.Amount
Expand Down
5 changes: 5 additions & 0 deletions VirtoCommerce.Storefront/Owin/WorkContextOwinMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public override async Task Invoke(IOwinContext context)
{
CatalogId = workContext.CurrentStore.Catalog
};
//Initialize product response group
workContext.CurrentProductResponseGroup = EnumUtility.SafeParse(qs.Get("resp_group"), ItemResponseGroup.ItemLarge);

workContext.PageNumber = qs.Get("page").ToNullableInt();
workContext.PageSize = qs.Get("count").ToNullableInt() ?? qs.Get("page_size").ToNullableInt();

//This line make delay categories loading initialization (categories can be evaluated on view rendering time)
workContext.Categories = new MutablePagedList<Category>((pageNumber, pageSize) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@ public CatalogSearchServiceImpl(Func<WorkContext> workContextFactory, IVirtoComm
}

#region ICatalogSearchService Members
public async Task<Product[]> GetProductsAsync(string[] ids, ItemResponseGroup responseGroup = ItemResponseGroup.ItemInfo)
public async Task<Product[]> GetProductsAsync(string[] ids, ItemResponseGroup responseGroup = ItemResponseGroup.None)
{
var workContext = _workContextFactory();
if(responseGroup == ItemResponseGroup.None)
{
responseGroup = workContext.CurrentProductResponseGroup;
}

var retVal = (await _catalogModuleApi.CatalogModuleProductsGetProductByIdsAsync(ids.ToList(), ((int)responseGroup).ToString())).Select(x => x.ToWebModel(workContext.CurrentLanguage, workContext.CurrentCurrency, workContext.CurrentStore)).ToArray();

Expand Down

0 comments on commit dfe48ce

Please sign in to comment.