|
30 | 30 | using Nop.Web.Models.Catalog; |
31 | 31 | using Nop.Web.Models.Common; |
32 | 32 | using Nop.Web.Models.Media; |
| 33 | +using Nop.Services.Discounts; |
33 | 34 |
|
34 | 35 | namespace Nop.Web.Factories |
35 | 36 | { |
36 | 37 | public partial class ProductModelFactory : IProductModelFactory |
37 | 38 | { |
38 | 39 | #region Fields |
39 | | - |
| 40 | + |
40 | 41 | private readonly ISpecificationAttributeService _specificationAttributeService; |
41 | 42 | private readonly ICategoryService _categoryService; |
42 | 43 | private readonly IManufacturerService _manufacturerService; |
@@ -239,7 +240,7 @@ protected virtual ProductOverviewModel.ProductPriceModel PrepareProductOverviewP |
239 | 240 | if (associatedProduct.HasTierPrices) |
240 | 241 | { |
241 | 242 | //calculate price for the maximum quantity if we have tier prices, and choose minimal |
242 | | - tmpMinPossiblePrice = Math.Min(tmpMinPossiblePrice, |
| 243 | + tmpMinPossiblePrice = Math.Min(tmpMinPossiblePrice, |
243 | 244 | _priceCalculationService.GetFinalPrice(associatedProduct, _workContext.CurrentCustomer, quantity: int.MaxValue)); |
244 | 245 | } |
245 | 246 |
|
@@ -341,10 +342,44 @@ protected virtual ProductOverviewModel.ProductPriceModel PrepareProductOverviewP |
341 | 342 | if (product.HasTierPrices) |
342 | 343 | { |
343 | 344 | //calculate price for the maximum quantity if we have tier prices, and choose minimal |
344 | | - minPossiblePrice = Math.Min(minPossiblePrice, |
| 345 | + minPossiblePrice = Math.Min(minPossiblePrice, |
345 | 346 | _priceCalculationService.GetFinalPrice(product, _workContext.CurrentCustomer, quantity: int.MaxValue)); |
346 | 347 | } |
347 | 348 |
|
| 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 | + } |
348 | 383 | decimal taxRate; |
349 | 384 | decimal oldPriceBase = _taxService.GetProductPrice(product, product.OldPrice, out taxRate); |
350 | 385 | decimal finalPriceBase = _taxService.GetProductPrice(product, minPossiblePrice, out taxRate); |
@@ -1230,7 +1265,7 @@ public virtual ProductDetailsModel PrepareProductDetailsModel(Product product, |
1230 | 1265 | { |
1231 | 1266 | model.ProductTags = PrepareProductTagModels(product); |
1232 | 1267 | } |
1233 | | - |
| 1268 | + |
1234 | 1269 | //pictures |
1235 | 1270 | model.DefaultPictureZoomEnabled = _mediaSettings.DefaultPictureZoomEnabled; |
1236 | 1271 | var pictureModels = PrepareProductDetailsPictureModel(product, isAssociatedProduct); |
@@ -1271,7 +1306,8 @@ public virtual ProductDetailsModel PrepareProductDetailsModel(Product product, |
1271 | 1306 |
|
1272 | 1307 | //product attributes |
1273 | 1308 | model.ProductAttributes = PrepareProductAttributeModels(product, updatecartitem); |
1274 | | - |
| 1309 | + |
| 1310 | + |
1275 | 1311 | //product specifications |
1276 | 1312 | //do not prepare this model for the associated products. anyway it's not used |
1277 | 1313 | if (!isAssociatedProduct) |
@@ -1365,7 +1401,7 @@ public virtual ProductReviewsModel PrepareProductReviewsModel(ProductReviewsMode |
1365 | 1401 |
|
1366 | 1402 | return model; |
1367 | 1403 | } |
1368 | | - |
| 1404 | + |
1369 | 1405 | public virtual CustomerProductReviewsModel PrepareCustomerProductReviewsModel(int? page) |
1370 | 1406 | { |
1371 | 1407 | var pageSize = _catalogSettings.ProductReviewsPageSizeOnAccountPage; |
@@ -1446,7 +1482,6 @@ public virtual ProductEmailAFriendModel PrepareProductEmailAFriendModel(ProductE |
1446 | 1482 |
|
1447 | 1483 | return model; |
1448 | 1484 | } |
1449 | | - |
1450 | 1485 | #endregion |
1451 | 1486 | } |
1452 | 1487 | } |
0 commit comments