diff --git a/changelog.md b/changelog.md index 13db42f67b..2b93b75d58 100644 --- a/changelog.md +++ b/changelog.md @@ -44,6 +44,7 @@ * Added options for alternating price display (in badges). * #1515 Poll: Add result tab with a list of answers and customers for a poll * BMEcat: Added export and import of product tags. +* Santander instalment purchase. ### Improvements * (Perf) Significantly increased query performance for products with a lot of category assignments (> 10). diff --git a/src/Libraries/SmartStore.Services/Discounts/DiscountService.cs b/src/Libraries/SmartStore.Services/Discounts/DiscountService.cs index 666c53dfdb..660e5f23a1 100644 --- a/src/Libraries/SmartStore.Services/Discounts/DiscountService.cs +++ b/src/Libraries/SmartStore.Services/Discounts/DiscountService.cs @@ -1,19 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using SmartStore.Collections; using SmartStore.Core; using SmartStore.Core.Caching; using SmartStore.Core.Data; using SmartStore.Core.Domain.Customers; using SmartStore.Core.Domain.Discounts; -using SmartStore.Core.Events; -using SmartStore.Core.Plugins; using SmartStore.Core.Domain.Orders; -using SmartStore.Services.Customers; +using SmartStore.Core.Plugins; using SmartStore.Services.Common; -using SmartStore.Services.Configuration; -using SmartStore.Collections; -using SmartStore.Core.Data.Hooks; +using SmartStore.Services.Customers; namespace SmartStore.Services.Discounts { @@ -28,21 +25,16 @@ public partial class DiscountService : IDiscountService private readonly IRequestCache _requestCache; private readonly IStoreContext _storeContext; private readonly IGenericAttributeService _genericAttributeService; - private readonly IPluginFinder _pluginFinder; - private readonly IEventPublisher _eventPublisher; - private readonly ISettingService _settingService; private readonly IProviderManager _providerManager; private readonly IDictionary _discountValidityCache; - public DiscountService(IRequestCache requestCache, + public DiscountService( + IRequestCache requestCache, IRepository discountRepository, IRepository discountRequirementRepository, IRepository discountUsageHistoryRepository, IStoreContext storeContext, IGenericAttributeService genericAttributeService, - IPluginFinder pluginFinder, - IEventPublisher eventPublisher, - ISettingService settingService, IProviderManager providerManager) { _requestCache = requestCache; @@ -51,9 +43,6 @@ public DiscountService(IRequestCache requestCache, _discountUsageHistoryRepository = discountUsageHistoryRepository; _storeContext = storeContext; _genericAttributeService = genericAttributeService; - _pluginFinder = pluginFinder; - _eventPublisher = eventPublisher; - _settingService = settingService; _providerManager = providerManager; _discountValidityCache = new Dictionary(); } @@ -207,7 +196,6 @@ public virtual Discount GetDiscountByCouponCode(string couponCode, bool showHidd return discount; } - private System.Diagnostics.Stopwatch _watch = new System.Diagnostics.Stopwatch(); public virtual bool IsDiscountValid(Discount discount, Customer customer) { var couponCodeToValidate = ""; diff --git a/src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperAdminProfile.cs b/src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperAdminProfile.cs index 068081f3dd..7833616bb4 100644 --- a/src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperAdminProfile.cs +++ b/src/Presentation/SmartStore.Web/Administration/Infrastructure/AutoMapperAdminProfile.cs @@ -431,16 +431,19 @@ public AutoMapperAdminProfile() CreateMap() .ForMember(dest => dest.CreatedOnUtc, mo => mo.Ignore()) .ForMember(dest => dest.NewsLetterSubscriptionGuid, mo => mo.Ignore()) - .ForMember(dest => dest.StoreId, mo => mo.Ignore()); - //forums - CreateMap() - .ForMember(dest => dest.Locales, mo => mo.Ignore()) - .ForMember(dest => dest.SeName, mo => mo.MapFrom(src => src.GetSeName(0, true, false))) - .ForMember(dest => dest.AvailableStores, mo => mo.Ignore()) - .ForMember(dest => dest.SelectedStoreIds, mo => mo.Ignore()) - .ForMember(dest => dest.CreatedOn, mo => mo.Ignore()) - .ForMember(dest => dest.ForumModels, mo => mo.Ignore()); - CreateMap() + .ForMember(dest => dest.StoreId, mo => mo.Ignore()) + .ForMember(dest => dest.WorkingLanguageId, mo => mo.Ignore()); + //forums + CreateMap() + .ForMember(dest => dest.Locales, mo => mo.Ignore()) + .ForMember(dest => dest.SeName, mo => mo.MapFrom(src => src.GetSeName(0, true, false))) + .ForMember(dest => dest.AvailableStores, mo => mo.Ignore()) + .ForMember(dest => dest.SelectedStoreIds, mo => mo.Ignore()) + .ForMember(dest => dest.AvailableCustomerRoles, mo => mo.Ignore()) + .ForMember(dest => dest.SelectedCustomerRoleIds, mo => mo.Ignore()) + .ForMember(dest => dest.CreatedOn, mo => mo.Ignore()) + .ForMember(dest => dest.ForumModels, mo => mo.Ignore()); + CreateMap() .ForMember(dest => dest.CreatedOnUtc, mo => mo.Ignore()) .ForMember(dest => dest.UpdatedOnUtc, mo => mo.Ignore()) .ForMember(dest => dest.Forums, mo => mo.Ignore()); @@ -499,6 +502,7 @@ public AutoMapperAdminProfile() .ForMember(dest => dest.EndDate, mo => mo.Ignore()) .ForMember(dest => dest.AvailableStores, mo => mo.Ignore()) .ForMember(dest => dest.SelectedStoreIds, mo => mo.Ignore()) + .ForMember(dest => dest.AvailableLanguages, mo => mo.Ignore()) .ForMember(dest => dest.UsernamesEnabled, mo => mo.Ignore()) .ForMember(dest => dest.GridPageSize, mo => mo.Ignore()); CreateMap() diff --git a/src/Tests/SmartStore.Services.Tests/Discounts/DiscountServiceTests.cs b/src/Tests/SmartStore.Services.Tests/Discounts/DiscountServiceTests.cs index 5c3fb0e389..44368552fb 100644 --- a/src/Tests/SmartStore.Services.Tests/Discounts/DiscountServiceTests.cs +++ b/src/Tests/SmartStore.Services.Tests/Discounts/DiscountServiceTests.cs @@ -1,21 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; +using NUnit.Framework; +using Rhino.Mocks; +using SmartStore.Core; using SmartStore.Core.Caching; using SmartStore.Core.Data; using SmartStore.Core.Domain.Customers; using SmartStore.Core.Domain.Discounts; -using SmartStore.Core.Plugins; +using SmartStore.Core.Domain.Stores; +using SmartStore.Services.Common; using SmartStore.Services.Discounts; -using SmartStore.Core.Events; using SmartStore.Tests; -using NUnit.Framework; -using Rhino.Mocks; -using SmartStore.Core; -using SmartStore.Services.Common; -using SmartStore.Core.Domain.Common; -using SmartStore.Services.Configuration; -using SmartStore.Core.Domain.Stores; namespace SmartStore.Services.Tests.Discounts { @@ -25,11 +21,9 @@ public class DiscountServiceTests : ServiceTest IRepository _discountRepo; IRepository _discountRequirementRepo; IRepository _discountUsageHistoryRepo; - IEventPublisher _eventPublisher; IGenericAttributeService _genericAttributeService; IDiscountService _discountService; IStoreContext _storeContext; - ISettingService _settingService; [SetUp] public new void SetUp() @@ -62,9 +56,6 @@ public class DiscountServiceTests : ServiceTest _discountRepo.Expect(x => x.Table).Return(new List() { discount1, discount2 }.AsQueryable()); - _eventPublisher = MockRepository.GenerateMock(); - _eventPublisher.Expect(x => x.Publish(Arg.Is.Anything)); - _storeContext = MockRepository.GenerateMock(); _storeContext.Expect(x => x.CurrentStore).Return(new Store { @@ -72,17 +63,12 @@ public class DiscountServiceTests : ServiceTest Name = "MyStore" }); - _settingService = MockRepository.GenerateMock(); - - var cacheManager = new NullCache(); _discountRequirementRepo = MockRepository.GenerateMock>(); _discountUsageHistoryRepo = MockRepository.GenerateMock>(); - var pluginFinder = new PluginFinder(); _genericAttributeService = MockRepository.GenerateMock(); _discountService = new DiscountService(NullRequestCache.Instance, _discountRepo, _discountRequirementRepo, - _discountUsageHistoryRepo, _storeContext, _genericAttributeService, pluginFinder, _eventPublisher, - _settingService, base.ProviderManager); + _discountUsageHistoryRepo, _storeContext, _genericAttributeService, ProviderManager); } [Test] @@ -133,17 +119,8 @@ public void Should_accept_valid_discount_code() LastActivityDateUtc = new DateTime(2010, 01, 02) }; - _genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer")) - .Return(new List() - { - new GenericAttribute() - { - EntityId = customer.Id, - Key = SystemCustomerAttributeNames.DiscountCouponCode, - KeyGroup = "Customer", - Value = "CouponCode 1" - } - }); + _genericAttributeService.Expect(x => x.GetAttribute(nameof(Customer), customer.Id, SystemCustomerAttributeNames.DiscountCouponCode, 0)) + .Return("CouponCode 1"); var result1 = _discountService.IsDiscountValid(discount, customer); result1.ShouldEqual(true); @@ -174,29 +151,30 @@ public void Should_not_accept_wrong_discount_code() LastActivityDateUtc = new DateTime(2010, 01, 02) }; - _genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer")) - .Return(new List() - { - new GenericAttribute() - { - EntityId = customer.Id, - Key = SystemCustomerAttributeNames.DiscountCouponCode, - KeyGroup = "Customer", - Value = "CouponCode 2" - } - }); - - var result2 = _discountService.IsDiscountValid(discount, customer); + _genericAttributeService.Expect(x => x.GetAttribute(nameof(Customer), customer.Id, SystemCustomerAttributeNames.DiscountCouponCode, 0)) + .Return("CouponCode 2"); + + var result2 = _discountService.IsDiscountValid(discount, customer); result2.ShouldEqual(false); } [Test] public void Can_validate_discount_dateRange() { - var discount = new Discount + var customer = new Customer + { + CustomerGuid = Guid.NewGuid(), + AdminComment = "", + Active = true, + Deleted = false, + CreatedOnUtc = new DateTime(2010, 01, 01), + LastActivityDateUtc = new DateTime(2010, 01, 02) + }; + + var discount1 = new Discount { DiscountType = DiscountType.AssignedToSkus, - Name = "Discount 2", + Name = "Discount 1", UsePercentage = false, DiscountPercentage = 0, DiscountAmount = 5, @@ -206,21 +184,23 @@ public void Can_validate_discount_dateRange() DiscountLimitation = DiscountLimitationType.Unlimited, }; - var customer = new Customer + var discount2 = new Discount { - CustomerGuid = Guid.NewGuid(), - AdminComment = "", - Active = true, - Deleted = false, - CreatedOnUtc = new DateTime(2010, 01, 01), - LastActivityDateUtc = new DateTime(2010, 01, 02) + DiscountType = DiscountType.AssignedToSkus, + Name = "Discount 2", + UsePercentage = false, + DiscountPercentage = 0, + DiscountAmount = 5, + StartDateUtc = DateTime.UtcNow.AddDays(1), + EndDateUtc = DateTime.UtcNow.AddDays(2), + RequiresCouponCode = false, + DiscountLimitation = DiscountLimitationType.Unlimited, }; - var result1 = _discountService.IsDiscountValid(discount, customer); + var result1 = _discountService.IsDiscountValid(discount1, customer); result1.ShouldEqual(true); - discount.StartDateUtc = DateTime.UtcNow.AddDays(1); - var result2 = _discountService.IsDiscountValid(discount, customer); + var result2 = _discountService.IsDiscountValid(discount2, customer); result2.ShouldEqual(false); } } diff --git a/src/Tests/SmartStore.Services.Tests/Helpers/DateTimeHelperTests.cs b/src/Tests/SmartStore.Services.Tests/Helpers/DateTimeHelperTests.cs index 29160fe4b9..ed5a793f53 100644 --- a/src/Tests/SmartStore.Services.Tests/Helpers/DateTimeHelperTests.cs +++ b/src/Tests/SmartStore.Services.Tests/Helpers/DateTimeHelperTests.cs @@ -1,16 +1,15 @@ using System; using System.Collections.Generic; +using NUnit.Framework; +using Rhino.Mocks; using SmartStore.Core; +using SmartStore.Core.Domain.Common; using SmartStore.Core.Domain.Customers; using SmartStore.Core.Domain.Stores; -using SmartStore.Core.Domain.Common; +using SmartStore.Services.Common; using SmartStore.Services.Configuration; -using SmartStore.Services.Customers; using SmartStore.Services.Helpers; -using SmartStore.Services.Common; using SmartStore.Tests; -using NUnit.Framework; -using Rhino.Mocks; namespace SmartStore.Services.Tests.Helpers { @@ -33,18 +32,17 @@ public class DateTimeHelperTests : ServiceTest _workContext = MockRepository.GenerateMock(); - _store = new Store() { Id = 1 }; + _store = new Store { Id = 1 }; _storeContext = MockRepository.GenerateMock(); _storeContext.Expect(x => x.CurrentStore).Return(_store); - _dateTimeSettings = new DateTimeSettings() + _dateTimeSettings = new DateTimeSettings { AllowCustomersToSetTimeZone = false, DefaultStoreTimeZoneId = "" }; - _dateTimeHelper = new DateTimeHelper(_workContext, _genericAttributeService, - _settingService, _dateTimeSettings); + _dateTimeHelper = new DateTimeHelper(_workContext, _genericAttributeService, _settingService, _dateTimeSettings); } [Test] @@ -67,25 +65,16 @@ public void Can_get_all_systemTimeZones() public void Can_get_customer_timeZone_with_customTimeZones_enabled() { _dateTimeSettings.AllowCustomersToSetTimeZone = true; - _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; //(GMT+02:00) Minsk; + _dateTimeSettings.DefaultStoreTimeZoneId = "E. Europe Standard Time"; // (GMT+02:00) Minsk; - var customer = new Customer() + var customer = new Customer { Id = 10 }; - _genericAttributeService.Expect(x => x.GetAttributesForEntity(customer.Id, "Customer")) - .Return(new List() - { - new GenericAttribute() - { - StoreId = 0, - EntityId = customer.Id, - Key = SystemCustomerAttributeNames.TimeZoneId, - KeyGroup = "Customer", - Value = "Russian Standard Time" //(GMT+03:00) Moscow, St. Petersburg, Volgograd - } - }); + _genericAttributeService + .Expect(x => x.GetAttribute(nameof(Customer), customer.Id, SystemCustomerAttributeNames.TimeZoneId, 0)) + .Return("Russian Standard Time"); // (GMT+03:00) Moscow, St. Petersburg, Volgograd var timeZone = _dateTimeHelper.GetCustomerTimeZone(customer); timeZone.ShouldNotBeNull();