in

dashCommerce

An ASP.NET Open Source e-Commerce Application

Lost the cart item when user register

Last post 08-15-2008 11:13 AM by rialb. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 02-13-2008 10:50 AM

    Lost the cart item when user register

    Hi All,

     I am using the Ver 2.2 and when the user register then they lost the item in the cart. I have seen in the old forum that there is someone gave solution for this issue. I am not able to find the old posts. Anyone have the corrected version of migratecart method?

    Thanks for your help.

    Thanks 

     

     

    Filed under: ,
  • 02-13-2008 11:12 AM In reply to

    Re: Lost the cart item when user register

    Answer

    Hi,

    You need to modify the Basket.aspx.cs and the Module/MiniCart.ascx.cs

    Firts : Basket.aspx.cs

    OrderItemCollection orderItemCollection = currentOrder.Items;

    //****ADD HERE*** 

    ///Check Cart Items FIX FOR BUG CADDY TO ZERO

    if (orderItemCollection.Count == 0)

    {

    ///Cart Empty Bug - this variable is used control loop. just 3 times enough

    int i = 0; while (orderItemCollection.Count == 0 && i < 3)

    {

    ///Cart Empty Bug - While item count is 0 we delete currentorder and call GetNewOrder() metod

    currentOrder.DeletePermanent();

    ///Cart Empty Bug - Get new order for authenticated user

    if (HttpContext.Current.User.Identity.IsAuthenticated)

    {

    currentOrder =
    OrderController.GetCurrentOrder(HttpContext.Current.User.Identity.Name);

    }

    else

    {

    currentOrder =
    OrderController.GetCurrentOrder();

    }

    ///Cart Empty Bug - Get new Cart

    orderItemCollection = OrderController.GetCartItems();

    ////

    i += 1;

    }

    }

    ////*****************************finish step1

    foreach (OrderItem currentItem in orderItemCollection)

    {

     ************************************************

    AFTER The MiniCart CS file  - STEP2

    *********************************************** 

     

    OrderItemCollection orderItemCollection = OrderController.GetCartItems();

    //// HERE///

    //********FIX zero Caddy

    ///Cart Empty Bug - Call this to check if cart is empty

    CheckItems();

    ///*********

    foreach (OrderItem currentItem in orderItemCollection)

    {

    if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))

    {

    currentItem.ImageFile =
    "images/ProductImages/no_image_available_small.gif";

    }

    }

    rptMiniBasket.DataSource = orderItemCollection;

    rptMiniBasket.DataBind();

    decimal dTotal = 0;foreach (OrderItem item in orderItemCollection)

    {

    dTotal += item.LineTotal;

    }

    lblSubtotal.Text = dTotal.ToString(
    "n");

    }

    ///********************************FIX ZERO CADDY

    ///Cart Empty Bug - Add orderItemCollection variable out of metods

     

    After That you are the losted shopping carts and you can delete. Then works fine. Regards

     

  • 02-13-2008 2:31 PM In reply to

    Re: Lost the cart item when user register

    Thanks. I will try this now

  • 02-13-2008 5:53 PM In reply to

    • tafs7
    • Top 150 Contributor
    • Joined on 02-12-2008
    • Dallas, TX
    • Posts 7

    Re: Lost the cart item when user register

    thanks for the code sample.  I'll try it...but I do have one question:

     The method "CheckItems()" that I add to the MiniCart.aspx.cs file, does it have the same logic that inserted into the Basket.aspx.cs file?

    Thanks

    Regards,
    Thiago Silva
  • 02-16-2008 12:26 PM In reply to

    Re: Lost the cart item when user register

     Sorry...The CheckItems is giving me an error...where is it defined ?? ?

     

    Thanks for your post !!

     

  • 02-16-2008 3:43 PM In reply to

    Re: Lost the cart item when user register

    Hi, Hola,

    Here is the complete codebehing of my Minicart

     using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Commerce.Common;

    public partial class Modules_MiniCart : System.Web.UI.UserControl
    {
        protected Order currentOrder;
        protected void Page_Load(object sender, EventArgs e)
        {
            //currentOrder = OrderController.GetCurrentOrder();

            OrderItemCollection orderItemCollection = OrderController.GetCartItems();
            //********FIX zero Caddy
            ///Cart Empty Bug - Call this to check if cart is empty

            CheckItems();

            ///*********
            foreach (OrderItem currentItem in orderItemCollection)
            {
                if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))
                {
                    currentItem.ImageFile = "images/ProductImages/no_image_available_small.gif";
                }
            }

            rptMiniBasket.DataSource = orderItemCollection;
            rptMiniBasket.DataBind();

            decimal dTotal = 0;
            foreach (OrderItem item in orderItemCollection)
            {
                dTotal += item.LineTotal;
            }

            lblSubtotal.Text = dTotal.ToString("n");
        }
        ///********************************FIX ZERO CADDY
        ///Cart Empty Bug - Add orderItemCollection variable out of metods

        protected OrderItemCollection orderItemCollection;
        ///Cart Empty Bug - Method called after get currentorder

        private void CheckItems()
        {

            ///Cart Empty Bug - Check if cart is empty

            //if (orderItemCollection.Count == 0)
            //{

            ///Cart Empty Bug - set current order

            currentOrder = OrderController.GetCurrentOrder();
            ///Cart Empty Bug - set orderitemcollection

            orderItemCollection = OrderController.GetCartItems();
            ///Cart Empty Bug - this variable is used control loop. just 3 times enough

            int i = 0;


            while (orderItemCollection.Count == 0 && i < 3)
            {

                ///Cart Empty Bug - While item count is 0 we delete currentorder and call GetNewOrder() metod

                currentOrder.DeletePermanent();

                GetNewOrder();

                i += 1;

            }

            //}

        }
        protected void GetNewOrder()
        {

            ///Cart Empty Bug - Get new order for authenticated user

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {

                currentOrder = OrderController.GetCurrentOrder(HttpContext.Current.User.Identity.Name);
            }

            else
            {

                currentOrder = OrderController.GetCurrentOrder();
            }

            ///Cart Empty Bug - Get new Cart

            orderItemCollection = OrderController.GetCartItems();
        }

        ///***************************************
    }

    Buena Suerte, Lucky

     

  • 02-16-2008 4:58 PM In reply to

    Re: Lost the cart item when user register

     Moltes grĂ cies !! Muchas Gracias !! Thanks !!!

     

    Frank 

  • 03-05-2008 9:33 AM In reply to

    Re: Lost the cart item when user register

    Hi, Thanks for the code.

    Does yours work for when a user registers or just logs in ?

    Works fine for login, still having issues with register. Time for some more fun.

    Also, does anyone know of the use of the method: LogInUser  in the Login.aspx.cs file ? I can't seem to find anywhere that uses it.

     

    Back to bug hunting,

    DashCommerce is pretty funky, sort out some bugs and it should be good to go. Thanks Chris!
    Stu

    Filed under: , ,
  • 03-06-2008 5:56 PM In reply to

    Re: Lost the cart item when user register

    ok so what I found was happening, the user was given a temporary username on load and the cart order was assigned to that username, then once the user registered the order items were not transfered to the new username.

    To correct this I used the OrderController.MigrateCart() method to move the order from the temporary username to the new registered username.

    I have the registration form on the login page also so the user can register there without clicking register so I have this implemented in 2 locations, but for standard dashcommerce 2.2 in register.aspx.cs do the following:

    protected void Page_Load(object sender, EventArgs e)

    {

    .....

    if (OrderController.GetCartItemCount() > 0)

    Session.Add("beforeRegisterID", Utility.GetUserName());

    }

     

    Then create a new event from the CreateUserWizard1 for the event Created User and add the following code:

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)

    {

    if ((string)Session["beforeRegisterID"] != Utility.GetUserName())

    OrderController.MigrateCart((string)Session["beforeRegisterID"], Utility.GetUserName());

    }

     

    How this works: When the user goes to the register.aspx page, if there are any items in the cart then the old username is stored in a session variable.

    When the user has created their new account the Created User event is fired and the session variable is compared to the currently logged in user, if they are not the same then the cart is merged with the new account (which will be empty) therefore moving over the products and appearing to have never left :)

    I hope this helps,

    have fun,

     

    Stu

    Filed under: ,
  • 08-15-2008 11:13 AM In reply to

    • rialb
    • Top 500 Contributor
    • Joined on 08-14-2008
    • Posts 2

    Re: Lost the cart item when user register

    Stu, thanks for the debugging work.  You saved me a bunch of time!

Page 1 of 1 (10 items)