85 lines
3.5 KiB
C#
85 lines
3.5 KiB
C#
using Nop.Core.Caching;
|
|
using Nop.Core.Domain.Catalog;
|
|
using Nop.Core.Domain.Customers;
|
|
using Nop.Core;
|
|
using Nop.Data;
|
|
using Nop.Services.Catalog;
|
|
using Nop.Services.Customers;
|
|
using Nop.Services.Discounts;
|
|
using Nop.Services.Localization;
|
|
using Nop.Services.Logging;
|
|
using Nop.Core.Domain.Directory;
|
|
using Nop.Services.Directory;
|
|
using Nop.Core.Domain.Discounts;
|
|
using Nop.Core.Domain.Stores;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
|
|
|
public class CustomPriceCalculationService : PriceCalculationService
|
|
{
|
|
private readonly IRepository<Product> _productRepository;
|
|
private readonly IProductAttributeService _productAttributeService;
|
|
private readonly ISpecificationAttributeService _specificationAttributeService;
|
|
private readonly ILocalizationService _localizationService;
|
|
private readonly IProductService _productService;
|
|
|
|
public CustomPriceCalculationService(
|
|
IRepository<Product> productRepository,
|
|
// inject all base deps
|
|
CatalogSettings catalogSettings,
|
|
CurrencySettings currencySettings,
|
|
ICategoryService categoryService,
|
|
ICurrencyService currencyService,
|
|
IManufacturerService manufacturerService,
|
|
IProductAttributeParser productAttributeParser,
|
|
IProductAttributeService productAttributeService,
|
|
ISpecificationAttributeService specificationAttributeService,
|
|
IProductService productService,
|
|
ICustomerService customerService,
|
|
IDiscountService discountService,
|
|
IDiscountPluginManager discountPluginManager,
|
|
ILocalizationService localizationService,
|
|
IStaticCacheManager cacheManager,
|
|
IWorkContext workContext,
|
|
ILogger logger)
|
|
: base(catalogSettings, currencySettings, categoryService, currencyService, customerService, discountService, manufacturerService,
|
|
productAttributeParser, productService,
|
|
cacheManager)
|
|
{
|
|
_productRepository = productRepository;
|
|
// assign all base deps to local private vars if needed
|
|
_productAttributeService = productAttributeService;
|
|
_specificationAttributeService = specificationAttributeService;
|
|
_localizationService = localizationService;
|
|
_productService = productService;
|
|
}
|
|
|
|
|
|
//decimal? overriddenProductPrice = null
|
|
|
|
public override async Task<(decimal priceWithoutDiscounts, decimal finalPrice, decimal appliedDiscountAmount, List<Discount> appliedDiscounts)> GetFinalPriceAsync(
|
|
Product product, Customer customer, Store store, decimal? overriddenProductPrice, decimal additionalCharge = 0, bool includeDiscounts = true,
|
|
int quantity = 1, DateTime? rentalStartDate = null, DateTime? rentalEndDate = null)
|
|
{
|
|
|
|
var productAttributeMappings = await _productAttributeService.GetAllProductAttributesAsync(product.Id);
|
|
//Product Attributes
|
|
foreach (var pam in productAttributeMappings)
|
|
{
|
|
var attributes = await _productAttributeService.GetProductAttributeValuesAsync(pam.Id);
|
|
foreach (var attr in attributes)
|
|
{
|
|
// you can check for specific attribute by its name or id
|
|
if (attr.Name == "NeedsToBeMeasured" && attr.IsPreSelected)
|
|
{
|
|
return (0m, 0m, 0m, new List<Discount>());
|
|
}
|
|
}
|
|
}
|
|
|
|
return await base.GetFinalPriceAsync(product, customer, store, overriddenProductPrice, additionalCharge, includeDiscounts, quantity, rentalStartDate, rentalEndDate);
|
|
}
|
|
|
|
|
|
}
|