November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi,
I'm not sure about your question, but to make the Profile_MigrateAnonymous run automatically, you need the ProfileModule registered as a module in web.config (it should be there in default installation):
in system.webServer/modules:
<add name="ProfileModule" type="EPiServer.Business.Commerce.HttpModules.ProfileModule, EPiServer.Business.Commerce" />
/Q
Hi Quan,
Yes I have the module registered in web.config.
Before I sign in the user "cartHelper.LineItems" contains 1 item, after signing in the user with "FormsAuthentication.SetAuthCookie(username, remember);" and a page reload "cartHelper.LineItems" contains 0 items.
cartHelper is an instance of "new CartHelper("CustomCartName")"
Hi,
I suggest to use this instead:
cartHelper = new CartHelper(Mediachase.Commerce.Orders.Cart.DefaultName);
"CustomCartName" is not a defined value in eCF API:s, is it your custom value? With the DefaultName cart, the cart will be automatically "bind" to current customer contact id.
Regards.
/Q
Hi,
Yes it is a custom value since we have multiple carts on the site and different checkout processes depending on where the user is at the site. Yhe carts cannot be mixed togeather. So you are saying that the cart only migrates if I use the Mediachase.Commerce.Orders.Cart.DefaultName constant?
Hi,
Currently, yes. But you can easily override/extend the behavior. Given you already register the event in Global.asax, you need to add a method like this:
static void MigrateCart(string cartName, Guid contactId, string anonymousId, IMarket market)
{
var cart = new CartHelper(cartName, contactId, market);
var anonymousCart = new CartHelper(cartName, new Guid(anonymousId), market);
// Only perform merge if cart is not empty
if (!anonymousCart.IsEmpty)
{
if (cart.IsEmpty)
{
cart.OrderForm.AuthorizedPaymentTotal = anonymousCart.OrderForm.AuthorizedPaymentTotal;
cart.OrderForm.CapturedPaymentTotal = anonymousCart.OrderForm.CapturedPaymentTotal;
}
// Merge cart
cart.Cart.Add(anonymousCart.Cart, true);
cart.Cart.BillingCurrency = anonymousCart.Cart.BillingCurrency;
cart.Cart.AcceptChanges();
// Delete anonymous cart
anonymousCart.Cart.Delete();
anonymousCart.Cart.AcceptChanges();
}
}
Then create an event handler which migrates the cart(s) you want and register it the login event
I agree that this approach should be included by default and we will seek if we can improve the situation.
Regards.
/Q
Hi again Quan,
Before migrating the OrderForms collection contains one item but after migration in the new cart the OrderForms collection contains two items and the tax calculation doesn't work.
If I remove the following lines the OrderForms collection just contains one item and the tax calculation works...
if (cart.IsEmpty)
{
cart.OrderForm.AuthorizedPaymentTotal = anonymousCart.OrderForm.AuthorizedPaymentTotal;
cart.OrderForm.CapturedPaymentTotal = anonymousCart.OrderForm.CapturedPaymentTotal;
}
is it a bug since the code looks the same as in EPiServer.Business.Commerce.HttpModules.ProfileModule?
Is it ok to remove these lines or will it mess up something else that I don't see right now?
Hi,
That sounds strange. That code is to assign AuthorizedPaymentTotal and CapturedPaymentTotal, which should not affect the processing of the cart, as those value should be calculated later when you run some workflows (such as CartPrepare, CartCheckout). I would say it's safe to remove those code - and my apology for showing some code without checking it carefully.
Regards,
/Q
When I set an authentication cookie the cart that an anonymous user created isn't migrated over to the logged in user.
I have a custom global.asax which inherits from EPiServer.Global. If I'm not misreading the documentation this should happen "automagically", or?
http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce1/751/Orders/Shopping-cart/
If an anonymous user adds items and then logs in, the previous cart associated with that logged-in user will be merged. This is done in the Global.asax, Profile_MigrateAnonymous event handler.