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 ISpecificationAttributeService _specificationAttributeService; 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, 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 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 _specificationAttributeService.GetProductSpecificationAttributesAsync(product.Id); //Product Attributes foreach (var pam in productAttributeMappings) { //get option var attributeOtion = await _specificationAttributeService.GetSpecificationAttributeOptionByIdAsync(pam.SpecificationAttributeOptionId); //get attribute var attribute = await _specificationAttributeService.GetSpecificationAttributeByIdAsync(attributeOtion.SpecificationAttributeId); // you can check for specific attribute by its name or id if (attribute.Name == "Needs to be measured for price") { return (0m, 0m, 0m, new List()); } } return await base.GetFinalPriceAsync(product, customer, store, overriddenProductPrice, additionalCharge, includeDiscounts, quantity, rentalStartDate, rentalEndDate); } }