diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e50d3d..cd41081 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -122,6 +122,9 @@ ## Kentico.Ecommerce +### 2.0.1 (2018-02-07) +#### Fixed +* Fixed licensing errors that occurred when saving a shopping cart on sites with a lower license edition than EMS. ### 2.0.0 (2017-12-11) #### Release notes diff --git a/src/Kentico.Ecommerce/Models/ShoppingCart.cs b/src/Kentico.Ecommerce/Models/ShoppingCart.cs index bd1ad0d..08b8b77 100644 --- a/src/Kentico.Ecommerce/Models/ShoppingCart.cs +++ b/src/Kentico.Ecommerce/Models/ShoppingCart.cs @@ -3,6 +3,7 @@ using System.Linq; using CMS.ContactManagement; +using CMS.ContactManagement.Internal; using CMS.Core; using CMS.DataEngine; using CMS.Ecommerce; @@ -19,6 +20,7 @@ public class ShoppingCart { private readonly EcommerceActivityLogger mActivityLogger; private readonly ICurrentContactProvider mCurrentContactProvider; + private readonly IContactProcessingChecker mContactProcessingChecker; private IEnumerable mItems; private Customer mCustomer; private CustomerAddress mBillingAddress; @@ -217,12 +219,12 @@ public CustomerAddress ShippingAddress /// /// object representing an original Kentico shopping cart info object from which the model is created. public ShoppingCart(ShoppingCartInfo originalCart) - :this(originalCart, new EcommerceActivityLogger(), Service.Resolve()) + :this(originalCart, new EcommerceActivityLogger(), Service.Resolve(), Service.Resolve()) { } - internal ShoppingCart(ShoppingCartInfo originalCart, EcommerceActivityLogger activityLogger, ICurrentContactProvider currentContactProvider) + internal ShoppingCart(ShoppingCartInfo originalCart, EcommerceActivityLogger activityLogger, ICurrentContactProvider currentContactProvider, IContactProcessingChecker contactProcessingChecker) { if (originalCart == null) { @@ -232,6 +234,7 @@ internal ShoppingCart(ShoppingCartInfo originalCart, EcommerceActivityLogger act OriginalCart = originalCart; mActivityLogger = activityLogger; mCurrentContactProvider = currentContactProvider; + mContactProcessingChecker = contactProcessingChecker; } @@ -492,7 +495,12 @@ private CustomerInfo CreateCustomerFromUser() private void SetCustomerRelationAndUpdateContact(CustomerInfo customerInfo) { - if (mCurrentContactProvider == null) + if (mCurrentContactProvider == null || mContactProcessingChecker == null) + { + return; + } + + if (!mContactProcessingChecker.CanProcessContactInCurrentContext()) { return; } diff --git a/src/Kentico.Ecommerce/Properties/AssemblyInfo.cs b/src/Kentico.Ecommerce/Properties/AssemblyInfo.cs index 1631eeb..485d942 100644 --- a/src/Kentico.Ecommerce/Properties/AssemblyInfo.cs +++ b/src/Kentico.Ecommerce/Properties/AssemblyInfo.cs @@ -14,5 +14,5 @@ [assembly: Guid("5047a2a8-707c-49f0-995b-15bd5456ab2f")] [assembly: AssemblyVersion("2.0.0.0")] [assembly: AssemblyFileVersion("2.0.0.0")] -[assembly: AssemblyInformationalVersion("2.0.0")] +[assembly: AssemblyInformationalVersion("2.0.1")] [assembly: InternalsVisibleTo("Kentico.Ecommerce.Tests")] diff --git a/test/Kentico.Ecommerce.Tests/EcommerceTestsBase.cs b/test/Kentico.Ecommerce.Tests/EcommerceTestsBase.cs index 032da41..1461cc5 100644 --- a/test/Kentico.Ecommerce.Tests/EcommerceTestsBase.cs +++ b/test/Kentico.Ecommerce.Tests/EcommerceTestsBase.cs @@ -1,4 +1,5 @@ using CMS.ContactManagement; +using CMS.ContactManagement.Internal; using CMS.DataEngine; using CMS.Ecommerce; using CMS.SiteProvider; @@ -132,7 +133,7 @@ public ShoppingCart CreateCartWithItem(int skuId, int units = 1) } - public ShoppingCart CreateCartWithCustomerInfo(CustomerInfo customer, AddressInfo address = null, ICurrentContactProvider currentContactProvider = null) + public ShoppingCart CreateCartWithCustomerInfo(CustomerInfo customer, AddressInfo address = null, ICurrentContactProvider currentContactProvider = null, IContactProcessingChecker contactProcessingChecker = null) { var cartInfo = ShoppingCartFactory.CreateCart(SiteID); cartInfo.ShoppingCartCurrencyID = Factory.MainCurrency.CurrencyID; @@ -142,7 +143,7 @@ public ShoppingCart CreateCartWithCustomerInfo(CustomerInfo customer, AddressInf ShoppingCartInfoProvider.SetShoppingCartInfo(cartInfo); - return new ShoppingCart(cartInfo, new EcommerceActivitiesLoggerFake(), currentContactProvider); + return new ShoppingCart(cartInfo, new EcommerceActivitiesLoggerFake(), currentContactProvider, contactProcessingChecker); } @@ -152,7 +153,7 @@ public ShoppingCart CreateEmptyShoppingCart() ShoppingCartInfoProvider.SetShoppingCartInfo(originalCart); - return new ShoppingCart(originalCart, new EcommerceActivitiesLoggerFake(), null); + return new ShoppingCart(originalCart, new EcommerceActivitiesLoggerFake(), null, null); } diff --git a/test/Kentico.Ecommerce.Tests/OrderTests.cs b/test/Kentico.Ecommerce.Tests/OrderTests.cs index 5d11439..5289505 100644 --- a/test/Kentico.Ecommerce.Tests/OrderTests.cs +++ b/test/Kentico.Ecommerce.Tests/OrderTests.cs @@ -93,7 +93,7 @@ private Order CreateOrderFromNewCart() cartInfo.Evaluate(); cartInfo.Insert(); - var cart = new ShoppingCart(cartInfo, mEcommerceActivitiesLogger, null); + var cart = new ShoppingCart(cartInfo, mEcommerceActivitiesLogger, null, null); return mService.CreateOrder(cart); } diff --git a/test/Kentico.Ecommerce.Tests/ShoppingCartTests.cs b/test/Kentico.Ecommerce.Tests/ShoppingCartTests.cs index 4e7f062..7a72299 100644 --- a/test/Kentico.Ecommerce.Tests/ShoppingCartTests.cs +++ b/test/Kentico.Ecommerce.Tests/ShoppingCartTests.cs @@ -4,6 +4,7 @@ using CMS.Activities; using CMS.Base; using CMS.ContactManagement; +using CMS.ContactManagement.Internal; using CMS.Core; using CMS.Ecommerce; using CMS.SiteProvider; @@ -532,6 +533,25 @@ public void AddItem_LogsActivity() } + [Test] + public void CartSave_ContactProcessingNotAllowed_ContactNotCreated() + { + SiteContext.CurrentSite = SiteInfo; + var customer = Factory.CustomerAnonymous; + + var currentContactProvider = Substitute.For(); + + var contactProcessingChecker = Substitute.For(); + contactProcessingChecker.CanProcessContactInCurrentContext().Returns(false); + + var cart = CreateCartWithCustomerInfo(customer, null, currentContactProvider, contactProcessingChecker); + + cart.Save(); + + currentContactProvider.DidNotReceive().GetCurrentContact(Arg.Any(), Arg.Any()); + } + + [Test] public void CartSave_UpdateContactRelations_ContactIsUpdated() { @@ -542,7 +562,10 @@ public void CartSave_UpdateContactRelations_ContactIsUpdated() var currentContactProvider = Substitute.For(); currentContactProvider.GetCurrentContact(Arg.Any(), Arg.Any()).Returns(contact); - var cart = CreateCartWithCustomerInfo(customer, null, currentContactProvider); + var contactProcessingChecker = Substitute.For(); + contactProcessingChecker.CanProcessContactInCurrentContext().Returns(true); + + var cart = CreateCartWithCustomerInfo(customer, null, currentContactProvider, contactProcessingChecker); cart.Save();