Skip to content

Commit fa9ed8e

Browse files
committed
Fixed: Base price in product list ignored PriceDisplayType (catalog settings) and possibly displayed the wrong base price info. f2a904a related
1 parent 93958b1 commit fa9ed8e

4 files changed

Lines changed: 52 additions & 16 deletions

File tree

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
* Copied product must not share sample download of source product. Could produce "The DELETE statement conflicted with the REFERENCE constraint 'FK_dbo.Product_dbo.Download_SampleDownloadId'".
4949
* #921 Specification attribute options with single quotation marks are causing a Javascript error
5050
* #971 Product is added to cart automatically if it has a non-required file upload attribute
51-
* #973 Bundle item upload is nowhere linked
51+
* #973 Bundle item upload is nowhere linked
52+
* Base price in product list ignored PriceDisplayType (catalog settings) and possibly displayed the wrong base price info
5253

5354

5455
## SmartStore.NET 2.5

src/Libraries/SmartStore.Services/Catalog/PriceCalculationService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ protected virtual decimal GetPreselectedPrice(Product product, PriceCalculationC
251251
if (selectedCombination != null && selectedCombination.IsActive && selectedCombination.Price.HasValue)
252252
{
253253
product.MergedDataValues = new Dictionary<string, object> { { "Price", selectedCombination.Price.Value } };
254+
255+
if (selectedCombination.BasePriceAmount.HasValue)
256+
product.MergedDataValues.Add("BasePriceAmount", selectedCombination.BasePriceAmount.Value);
257+
258+
if (selectedCombination.BasePriceBaseAmount.HasValue)
259+
product.MergedDataValues.Add("BasePriceBaseAmount", selectedCombination.BasePriceBaseAmount.Value);
254260
}
255261
}
256262

src/Libraries/SmartStore.Services/Catalog/ProductExtensions.cs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace SmartStore.Services.Catalog
1616
{
17-
public static class ProductExtensions
17+
public static class ProductExtensions
1818
{
1919
public static ProductVariantAttributeCombination MergeWithCombination(this Product product, string selectedAttributes)
2020
{
@@ -299,7 +299,7 @@ public static int[] ParseRequiredProductIds(this Product product)
299299
}
300300

301301
/// <summary>
302-
/// Gets the base price
302+
/// Gets the base price info
303303
/// </summary>
304304
/// <param name="product">Product</param>
305305
/// <param name="localizationService">Localization service</param>
@@ -310,7 +310,7 @@ public static int[] ParseRequiredProductIds(this Product product)
310310
/// <param name="currency">Target currency</param>
311311
/// <param name="priceAdjustment">Price adjustment</param>
312312
/// <param name="languageIndependent">Whether the result string should be language independent</param>
313-
/// <returns>The base price</returns>
313+
/// <returns>The base price info</returns>
314314
public static string GetBasePriceInfo(this Product product, ILocalizationService localizationService, IPriceFormatter priceFormatter,
315315
ICurrencyService currencyService, ITaxService taxService, IPriceCalculationService priceCalculationService,
316316
Currency currency, decimal priceAdjustment = decimal.Zero, bool languageIndependent = false)
@@ -331,8 +331,33 @@ public static string GetBasePriceInfo(this Product product, ILocalizationService
331331

332332
price = currencyService.ConvertFromPrimaryStoreCurrency(price, currency);
333333

334-
var value = Convert.ToDecimal((price / product.BasePriceAmount) * product.BasePriceBaseAmount);
335-
var valueFormatted = priceFormatter.FormatPrice(value, true, currency);
334+
return product.GetBasePriceInfo(price, localizationService, priceFormatter, currency, languageIndependent);
335+
}
336+
337+
return "";
338+
}
339+
340+
/// <summary>
341+
/// Gets the base price info
342+
/// </summary>
343+
/// <param name="product">Product</param>
344+
/// <param name="productPrice">The calculated product price</param>
345+
/// <param name="localizationService">Localization service</param>
346+
/// <param name="priceFormatter">Price formatter</param>
347+
/// <param name="currency">Target currency</param>
348+
/// <param name="languageIndependent">Whether the result string should be language independent</param>
349+
/// <returns>The base price info</returns>
350+
public static string GetBasePriceInfo(this Product product,
351+
decimal productPrice,
352+
ILocalizationService localizationService,
353+
IPriceFormatter priceFormatter,
354+
Currency currency,
355+
bool languageIndependent = false)
356+
{
357+
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
358+
{
359+
var value = Convert.ToDecimal((productPrice / product.BasePriceAmount) * product.BasePriceBaseAmount);
360+
var valueFormatted = priceFormatter.FormatPrice(value, true, currency);
336361
var amountFormatted = Math.Round(product.BasePriceAmount.Value, 2).ToString("G29");
337362

338363
var result = "{0} {1} ({2} / {3} {1})".FormatInvariant(
@@ -351,7 +376,7 @@ public static string GetBasePriceInfo(this Product product, ILocalizationService
351376
}
352377

353378
return "";
354-
}
379+
}
355380

356381
public static string GetProductTypeLabel(this Product product, ILocalizationService localizationService)
357382
{

src/Presentation/SmartStore.Web/Controllers/CatalogHelper.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ public IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(
11081108
foreach (var product in products)
11091109
{
11101110
var contextProduct = product;
1111+
var finalPrice = decimal.Zero;
11111112

11121113
var model = new ProductOverviewModel
11131114
{
@@ -1188,7 +1189,7 @@ public IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(
11881189
decimal taxRate = decimal.Zero;
11891190
decimal oldPriceBase = _taxService.GetProductPrice(contextProduct, contextProduct.OldPrice, out taxRate);
11901191
decimal finalPriceBase = _taxService.GetProductPrice(contextProduct, displayPrice.Value, out taxRate);
1191-
decimal finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, workingCurrency);
1192+
finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, workingCurrency);
11921193

11931194
priceModel.OldPrice = null;
11941195

@@ -1256,7 +1257,7 @@ public IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(
12561257
decimal finalPriceBase = _taxService.GetProductPrice(product, displayPrice, out taxRate);
12571258

12581259
decimal oldPrice = _currencyService.ConvertFromPrimaryStoreCurrency(oldPriceBase, workingCurrency);
1259-
decimal finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, workingCurrency);
1260+
finalPrice = _currencyService.ConvertFromPrimaryStoreCurrency(finalPriceBase, workingCurrency);
12601261

12611262
priceModel.HasDiscount = (finalPriceBase != oldPriceBase && oldPriceBase != decimal.Zero);
12621263

@@ -1396,16 +1397,19 @@ from a in colorAttribute.ProductVariantAttributeValues.Take(50)
13961397
model.Manufacturers = PrepareManufacturersOverviewModel(_manufacturerService.GetProductManufacturersByProductId(product.Id), cachedManufacturerModels, false);
13971398
}
13981399

1399-
if (_catalogSettings.ShowBasePriceInProductLists || isCompareList)
1400+
if (finalPrice != decimal.Zero && (_catalogSettings.ShowBasePriceInProductLists || isCompareList))
14001401
{
1401-
model.BasePriceInfo = contextProduct.GetBasePriceInfo(_localizationService, _priceFormatter, _currencyService, _taxService, _priceCalculationService, workingCurrency);
1402+
model.BasePriceInfo = contextProduct.GetBasePriceInfo(finalPrice, _localizationService, _priceFormatter, workingCurrency);
14021403
}
14031404

1404-
var addShippingPrice = _currencyService.ConvertCurrency(contextProduct.AdditionalShippingCharge, currentStore.PrimaryStoreCurrency, workingCurrency);
1405-
1406-
if (addShippingPrice > 0 && displayPrices)
1405+
if (displayPrices)
14071406
{
1408-
model.TransportSurcharge = res["Common.AdditionalShippingSurcharge"].Text.FormatWith(_priceFormatter.FormatPrice(addShippingPrice, true, false));
1407+
var addShippingPrice = _currencyService.ConvertCurrency(contextProduct.AdditionalShippingCharge, currentStore.PrimaryStoreCurrency, workingCurrency);
1408+
1409+
if (addShippingPrice > 0)
1410+
{
1411+
model.TransportSurcharge = res["Common.AdditionalShippingSurcharge"].Text.FormatCurrent(_priceFormatter.FormatPrice(addShippingPrice, true, false));
1412+
}
14091413
}
14101414

14111415
if (contextProduct.Weight > 0)
@@ -1416,7 +1420,7 @@ from a in colorAttribute.ProductVariantAttributeValues.Take(50)
14161420
// IsNew
14171421
if (_catalogSettings.LabelAsNewForMaxDays.HasValue)
14181422
{
1419-
model.IsNew = (DateTime.UtcNow - product.CreatedOnUtc).Days <= _catalogSettings.LabelAsNewForMaxDays.Value;
1423+
model.IsNew = ((DateTime.UtcNow - product.CreatedOnUtc).Days <= _catalogSettings.LabelAsNewForMaxDays.Value);
14201424
}
14211425

14221426
models.Add(model);

0 commit comments

Comments
 (0)