breakskater wrote:
If currentcart.products.count > 0, keep the cart the same. Don't add products the customer may have forgotten about.
Hi Darren, the previous products should still be added to the cart because we want to remind the customer about products they were thinking of buying before in hopes that they will purchase them. I do agree that the coupon code should be remembered after logging in though.
I think reminding them of products they once (could be months/years ago) added to their cart could be handled differently. Changing their current cart in this way won't be predicted by the customer and therefore will be annoying.
Perhaps this is a solution. It adds voucher codes and takes a mergeWithPreviousCart param. It would make customisation easier. Or a setting could even be created to allow the store owner to choose.
public virtual void MigrateShoppingCart(Customer fromCustomer, Customer toCustomer, bool mergeWithPreviousCart)
{
if (fromCustomer == null)
throw new ArgumentNullException("fromCustomer");
if (toCustomer == null)
throw new ArgumentNullException("toCustomer");
if (fromCustomer.Id == toCustomer.Id)
return; //the same customer
var fromCart = fromCustomer.ShoppingCartItems.ToList();
var toCart = toCustomer.ShoppingCartItems.ToList();
if (!mergeWithPreviousCart)
{
for (int i = 0; i < toCart.Count; i++)
{
var sci = toCart[i];
DeleteShoppingCartItem(sci);
}
}
for (int i = 0; i < fromCart.Count; i++)
{
var sci = fromCart[i];
AddToCart(toCustomer, sci.ProductVariant, sci.ShoppingCartType,
sci.AttributesXml, sci.CustomerEnteredPrice, sci.Quantity, false);
}
for (int i = 0; i < fromCart.Count; i++)
{
var sci = fromCart[i];
DeleteShoppingCartItem(sci);
}
//Transfer Voucher Code
toCustomer.DiscountCouponCode = _workContext.CurrentCustomer.DiscountCouponCode;
_customerService.UpdateCustomer(toCustomer);
}
one further thought. How are current gift cards (codes entered) handled when you log in?
Darren