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 _productRepository; private readonly IProductAttributeService _productAttributeService; private readonly ILocalizationService _localizationService; private readonly IProductService _productService; public CustomPriceCalculationService( IRepository productRepository, // inject all base deps CatalogSettings catalogSettings, CurrencySettings currencySettings, ICategoryService categoryService, ICurrencyService currencyService, IManufacturerService manufacturerService, IProductAttributeParser productAttributeParser, IProductAttributeService productAttributeService, 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; _localizationService = localizationService; _productService = productService; } //decimal? overriddenProductPrice = null public override async Task<(decimal priceWithoutDiscounts, decimal finalPrice, decimal appliedDiscountAmount, List 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.GetProductAttributeMappingsByProductIdAsync(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()); } } } return await base.GetFinalPriceAsync(product, customer, store, 0, additionalCharge, includeDiscounts, quantity, rentalStartDate, rentalEndDate); } }