Skip to content

Commit 6f849cc

Browse files
author
Markus Falk
committed
PrepareProductOverviewPriceModel: Display set price
1 parent 0e2a5e3 commit 6f849cc

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/Presentation/Nop.Web/Factories/ProductModelFactory.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
using Nop.Web.Models.Catalog;
3131
using Nop.Web.Models.Common;
3232
using Nop.Web.Models.Media;
33+
using Nop.Services.Discounts;
3334

3435
namespace Nop.Web.Factories
3536
{
3637
public partial class ProductModelFactory : IProductModelFactory
3738
{
3839
#region Fields
39-
40+
4041
private readonly ISpecificationAttributeService _specificationAttributeService;
4142
private readonly ICategoryService _categoryService;
4243
private readonly IManufacturerService _manufacturerService;
@@ -239,7 +240,7 @@ protected virtual ProductOverviewModel.ProductPriceModel PrepareProductOverviewP
239240
if (associatedProduct.HasTierPrices)
240241
{
241242
//calculate price for the maximum quantity if we have tier prices, and choose minimal
242-
tmpMinPossiblePrice = Math.Min(tmpMinPossiblePrice,
243+
tmpMinPossiblePrice = Math.Min(tmpMinPossiblePrice,
243244
_priceCalculationService.GetFinalPrice(associatedProduct, _workContext.CurrentCustomer, quantity: int.MaxValue));
244245
}
245246

@@ -341,10 +342,44 @@ protected virtual ProductOverviewModel.ProductPriceModel PrepareProductOverviewP
341342
if (product.HasTierPrices)
342343
{
343344
//calculate price for the maximum quantity if we have tier prices, and choose minimal
344-
minPossiblePrice = Math.Min(minPossiblePrice,
345+
minPossiblePrice = Math.Min(minPossiblePrice,
345346
_priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, quantity: int.MaxValue));
346347
}
347348

349+
//attributes "set"
350+
string attributesXml = "";
351+
var attributes = _productAttributeService.GetProductAttributeMappingsByProductId(product.Id);
352+
foreach (var attribute in attributes)
353+
{
354+
if (attribute.ShouldHaveValues())
355+
{
356+
//values
357+
var attributeValues = _productAttributeService.GetProductAttributeValues(attribute.Id);
358+
359+
//creating XML for "read-only checkboxes" attributes
360+
foreach (var selectedAttributeId in attributeValues
361+
.Where(v => v.IsPreSelected)
362+
.Select(v => v.Id)
363+
.ToList())
364+
{
365+
attributesXml = _productAttributeParser.AddProductAttribute(attributesXml,
366+
attribute, selectedAttributeId.ToString());
367+
}
368+
}
369+
370+
}
371+
//Get final price using attributes
372+
if (!string.IsNullOrEmpty(attributesXml))
373+
{
374+
List<DiscountForCaching> scDiscounts;
375+
decimal discountAmount;
376+
minPossiblePrice = _priceCalculationService.GetUnitPrice(product,
377+
_workContext.CurrentCustomer,
378+
ShoppingCartType.ShoppingCart,
379+
1, ref attributesXml, 0,
380+
null, null,
381+
true, out discountAmount, out scDiscounts);
382+
}
348383
decimal taxRate;
349384
decimal oldPriceBase = _taxService.GetProductPrice(product, product.OldPrice, out taxRate);
350385
decimal finalPriceBase = _taxService.GetProductPrice(product, minPossiblePrice, out taxRate);
@@ -1230,7 +1265,7 @@ public virtual ProductDetailsModel PrepareProductDetailsModel(Product product,
12301265
{
12311266
model.ProductTags = PrepareProductTagModels(product);
12321267
}
1233-
1268+
12341269
//pictures
12351270
model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled;
12361271
var pictureModels = PrepareProductDetailsPictureModel(product, isAssociatedProduct);
@@ -1271,7 +1306,8 @@ public virtual ProductDetailsModel PrepareProductDetailsModel(Product product,
12711306

12721307
//product attributes
12731308
model.ProductAttributes = PrepareProductAttributeModels(product, updatecartitem);
1274-
1309+
1310+
12751311
//product specifications
12761312
//do not prepare this model for the associated products. anyway it's not used
12771313
if (!isAssociatedProduct)
@@ -1365,7 +1401,7 @@ public virtual ProductReviewsModel PrepareProductReviewsModel(ProductReviewsMode
13651401

13661402
return model;
13671403
}
1368-
1404+
13691405
public virtual CustomerProductReviewsModel PrepareCustomerProductReviewsModel(int? page)
13701406
{
13711407
var pageSize = _catalogSettings.ProductReviewsPageSizeOnAccountPage;
@@ -1446,7 +1482,6 @@ public virtual ProductEmailAFriendModel PrepareProductEmailAFriendModel(ProductE
14461482

14471483
return model;
14481484
}
1449-
14501485
#endregion
14511486
}
14521487
}

0 commit comments

Comments
 (0)