using Nop.Core.Caching; using Nop.Core.Domain.Orders; using Nop.Services.Attributes; using Nop.Services.Stores; namespace Nop.Services.Orders; /// /// Checkout attribute service extensions /// public static partial class CheckoutAttributeServiceExtensions { /// /// Gets all checkout attributes /// /// Checkout attribute service /// Store identifier /// A value indicating whether we should exclude shippable attributes /// /// A task that represents the asynchronous operation /// The task result contains the checkout attributes /// public static async Task> GetAllAttributesAsync(this IAttributeService service, IStaticCacheManager staticCacheManager, IStoreMappingService storeMappingService, int storeId = 0, bool excludeShippableAttributes = false) { var key = staticCacheManager.PrepareKeyForDefaultCache(NopOrderDefaults.CheckoutAttributesAllCacheKey, storeId, excludeShippableAttributes); return await staticCacheManager.GetAsync(key, async () => { var checkoutAttributes = (await service.GetAllAttributesAsync()).ToAsyncEnumerable(); if (storeId > 0) //store mapping checkoutAttributes = checkoutAttributes.WhereAwait(async ca => await storeMappingService.AuthorizeAsync(ca, storeId)); if (excludeShippableAttributes) //remove attributes which require shippable products checkoutAttributes = checkoutAttributes.Where(x => !x.ShippableProductRequired); return await checkoutAttributes.ToListAsync(); }); } }