Page 1 of 1

Admin placing an order - error with Volume Discounts

Posted: Mon Jul 27, 2009 7:41 am
by niall08
When an admin uses the "FIND" button in PlaceOrder2.aspx, everything is usually OK.

In one order, however, clicking on this button takes the admin back to the order default.aspx and no order is created. This one order has a volume discount applied to one of the items.

The email address is for an existing user.

Code: Select all

protected void CustomerLookupButton_Click(object sender, EventArgs e)
    {
        int userId = UserDataSource.GetUserIdByEmail(CustomerEmail.Text);
        if (userId > 0)
        {
            //_Basket.UserId = userId;
            User user = UserDataSource.Load(userId);
            Basket.Transfer(_Basket.UserId, userId);
            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
    }
Any ideas? Happened to anyone else??

v.7.0.1

Re: Admin placing an order - error with Volume Discounts

Posted: Mon Jul 27, 2009 8:18 am
by niall08
The setup for the volume discount is shown in the attachment.

Thanks,
Niall

Re: Admin placing an order - error with Volume Discounts

Posted: Mon Jul 27, 2009 8:48 am
by niall08
Anyone else experienced similar issues with volume discounts in the admin "place order" functionality??

Any fixes?

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 12:35 am
by niall08
Any feedback from the development team?

Is this a bug?

Please, some sort of feedback is needed here..

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 5:10 am
by mazhar
Unable to reproduce it on 7.0.1, I am able to place order with described volume discount without any problem. It may be something due to any customization in page.

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 5:28 am
by niall08
Hi Mazhar - thanks for looking at this..

The only customisation around the button click that I have is:

Code: Select all

protected void CustomerLookupButton_Click(object sender, EventArgs e)
    {
        int userId = UserDataSource.GetUserIdByEmail(CustomerEmail.Text);
        if (userId > 0)
        {
            //_Basket.UserId = userId;
            User user = UserDataSource.Load(userId);
            Basket.Transfer(_Basket.UserId, user.UserId);
            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
        else
        {
            String tempPassword = "tempPassword";
            MembershipCreateStatus status;
            User newUser = UserDataSource.CreateUser(CustomerEmail.Text, tempPassword, string.Empty, string.Empty, true, 0, out status);
            newUser.IsApproved = true;
            newUser.Save();
            newUser.PrimaryAddress.FirstName = "TempFirstName";
            newUser.PrimaryAddress.LastName = "TempLastName";
            newUser.PrimaryAddress.Save();
            User user = UserDataSource.Load(newUser.UserId);
            Basket.Transfer(_Basket.UserId, newUser.UserId);
            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
    }
And the only other customisation on the page is the one prompted by Logan's feedback - from: viewtopic.php?f=42&t=11057

Line 71 reads:

Code: Select all

if (_Basket == null) Response.Redirect("Default.aspx");
which tallys with the fact that no order has been created, and the admin is redirected to the order default page.

Any ideas? Could I attach the whole code-behind page?

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 7:12 am
by niall08
I can't see any customisation that could have caused the problem Mazhar - for line 501:

Code: Select all

Basket.Transfer(_Basket.UserId, user.UserId);
Both the current basketId and the retrieved UserId are being passed correctly - but no basket is being assigned to that user in the database - so when we redirect to the page and line 71 checks to see if the basket is null, we get redirected to the default Order screen.

Can you help??

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 7:59 am
by niall08
At the least could you send me the original, out-of-the-box codebehind for PlaceOrder2.aspx so I can test the functionality with my 7.0.1 setup?

It would allow me the rule out any customisation..

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 9:12 am
by mazhar
niall08 wrote:At the least could you send me the original, out-of-the-box codebehind for PlaceOrder2.aspx so I can test the functionality with my 7.0.1 setup?

It would allow me the rule out any customisation..
PlaceOrder2.aspx and PlaceOrder2.aspx.cs files

Re: Admin placing an order - error with Volume Discounts

Posted: Tue Jul 28, 2009 9:21 am
by niall08
Thanks Mazhar - appreciate that..

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 1:12 am
by niall08
Mazhar - I've substituted my customised PlaceOrder2.aspx file (and code-behind) with the ones that you supplied - and the bug still occurs.

The problem occurs at the basket.transfer stage - nothing is being created against the "found" user - which is outside any customisation that I had done. This is borne out by the fact that, when using the files that you supplied, the same bug is triggered.

In short:
1. An order is built;
2. In the PlaceOrder2.aspx page, when an existing email address is added and the "FIND" button clicked, the admin is redirected to the default Orders page.

Have you tested the functionality with an existing email address/account?

Again, I'm on 7.0.1

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 6:55 am
by jmestep
Could it be because there is no maximum in one of the discount levels per your screen shot?

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 7:40 am
by niall08
Hi Judy,
Thanks for your interest in this.

I had my hopes raised and dashed there..

I've added a maximum figure and tested the functionality, and the same happened. I also changed from percentage to fixed amount, and no dice.

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 8:04 am
by niall08
Does anyone have any ideas?

I'm at a complete loss here.. The fact that the problem occurs with the basket transfer means theres not much I can do about the problem..

Dev team?

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 8:51 am
by niall08
Maybe someone on the Dev team can tell me what happens during the basket transfer?

I need help here

Re: Admin placing an order - error with Volume Discounts

Posted: Wed Jul 29, 2009 10:33 am
by sohaib
Basket transfer is simple. I don't see why it should be causing any issues.

Code: Select all

        public static void Transfer(int sourceId, int targetId, bool transferEmptyBasket)
        {
            if (sourceId != targetId)
            {
                //GET THE DEFAULT BASKET FOR THE SOURCE USER
                BasketCollection sourceBaskets = BasketDataSource.LoadForUser(sourceId);
                if (sourceBaskets.Count == 0) return;
                Basket sourceBasket = sourceBaskets[0];
                if (!transferEmptyBasket)
                {
                    //WE SHOULD NOT TRANSFER EMPTY BASKETS, COUNT THE SOURCE ITEMS
                    int sourceCount = BasketItemDataSource.CountForBasket(sourceBasket.BasketId);
                    if (sourceCount == 0) return;
                }
                //MAKE SURE TARGET USER HAS NO BASKETS
                Database database = Token.Instance.Database;
                DbCommand command = database.GetSqlStringCommand("DELETE FROM ac_Baskets WHERE UserId = @targetId");
                database.AddInParameter(command, "@targetId", System.Data.DbType.Int32, targetId);
                database.ExecuteNonQuery(command);
                //RESET SHIPMENT ASSIGNMENTS FOR SOURCE ITEMS
                database = Token.Instance.Database;
                command = database.GetSqlStringCommand("UPDATE ac_BasketItems SET BasketShipmentId = NULL WHERE BasketId = @sourceId");
                database.AddInParameter(command, "@sourceId", System.Data.DbType.Int32, sourceBasket.BasketId);
                database.ExecuteNonQuery(command);
                //NOW REMOVE SHIPMENTS FROM SOURCE BASKET (bug 5598)
                database = Token.Instance.Database;
                command = database.GetSqlStringCommand("DELETE FROM ac_BasketShipments WHERE BasketId = @sourceId");
                database.AddInParameter(command, "@sourceId", System.Data.DbType.Int32, sourceBasket.BasketId);
                database.ExecuteNonQuery(command);
                //NOW MOVE SOURCE BASKET TO TARGET USER
                database = Token.Instance.Database;
                command = database.GetSqlStringCommand("UPDATE ac_Baskets SET UserId = @targetId WHERE BasketId = @sourceId");
                database.AddInParameter(command, "@targetId", System.Data.DbType.Int32, targetId);
                database.AddInParameter(command, "@sourceId", System.Data.DbType.Int32, sourceBasket.BasketId);
                database.ExecuteNonQuery(command);
            }
        }

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 1:19 am
by niall08
Thanks Sohaib.

That's the code from the "Transfer" method that takes three parameters - is there another method with two parameters that has different functionality (i.e. no "transferEmptyBasket" boolean parameter)?

Using the code that you provided, I've been able to output: sourceID, basketID, sourceBasket.Count and sourceBasket.BasketId - and everything reads as it should - it's just not doing the SQL update(!?) but it is definitely hitting that segment of the code.

Bizarre.

This is obviously where the problem is - rather than Basket.Repackage or Basket.Calculate

Is the overriding method very different?

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 1:51 am
by sohaib
method with two parameters is just this

Code: Select all

        public static void Transfer(int sourceId, int targetId)
        {
            Transfer(sourceId, targetId, false);
        }

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 6:14 am
by niall08
Sohaib..

In an effort to try and isolate the problem, I used your code for the Transfer method and created my own class, calling my own Transfer method rather than the one packaged in your Basket class - the same behaviour occurred.

So the basket is transferred at this point in your code.

Commenting out the "Recalculate" method allows the basket to remain transferred to the found users - so this is where the problem is arising.

Is there anything in this method that would cause the basket to revert to the sourceId (rather than the targetId)??

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 6:22 am
by sohaib
I think what you need to do is something like this

Code: Select all

protected void CustomerLookupButton_Click(object sender, EventArgs e)
    {
        int userId = UserDataSource.GetUserIdByEmail(CustomerEmail.Text);
        if (userId > 0)
        {
            //_Basket.UserId = userId;
            User user = UserDataSource.Load(userId);
            Basket.Transfer(_Basket.UserId, user.UserId);
            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
        else
        {
            String tempPassword = "tempPassword";
            MembershipCreateStatus status;
            User newUser = UserDataSource.CreateUser(CustomerEmail.Text, tempPassword, string.Empty, string.Empty, true, 0, out status);
            newUser.IsApproved = true;
            newUser.Save();
            newUser.PrimaryAddress.FirstName = "TempFirstName";
            newUser.PrimaryAddress.LastName = "TempLastName";
            newUser.PrimaryAddress.Save();
            User user = UserDataSource.Load(newUser.UserId);
            Basket.Transfer(_Basket.UserId, newUser.UserId);

            //make sure that basket for new user is loaded
            _Basket = user.Basket;

            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
    }

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 6:54 am
by niall08
Hi Sohaib

The problem isn't in the "else" clause - the problem is triggered by the call to recalculate the basket after it's been transferred

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 6:58 am
by sohaib

Code: Select all

protected void CustomerLookupButton_Click(object sender, EventArgs e)
    {
        int userId = UserDataSource.GetUserIdByEmail(CustomerEmail.Text);
        if (userId > 0)
        {
            //_Basket.UserId = userId;
            User user = UserDataSource.Load(userId);
            Basket.Transfer(_Basket.UserId, user.UserId);

            //make sure that basket for new user is loaded
            _Basket = user.Basket;

            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
        else
        {
            String tempPassword = "tempPassword";
            MembershipCreateStatus status;
            User newUser = UserDataSource.CreateUser(CustomerEmail.Text, tempPassword, string.Empty, string.Empty, true, 0, out status);
            newUser.IsApproved = true;
            newUser.Save();
            newUser.PrimaryAddress.FirstName = "TempFirstName";
            newUser.PrimaryAddress.LastName = "TempLastName";
            newUser.PrimaryAddress.Save();
            User user = UserDataSource.Load(newUser.UserId);
            Basket.Transfer(_Basket.UserId, newUser.UserId);

            //make sure that basket for new user is loaded
            _Basket = user.Basket;

            _Basket.Package();
            _Basket.Recalculate();
            Response.Redirect("PlaceOrder2.aspx?BasketId=" + user.Basket.BasketId);
        }
    }

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 7:16 am
by niall08
Sorry Sohaib - I missed that before.

That has it working - explicitly assigning the user.Basket to the _Basket object - very straightforward, but I wouldn't have thought of it.

Thanks!!

So.. was it a bug?

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 7:31 am
by sohaib
So.. was it a bug?
No. Your basket object was referring to old object. You had to have a reference of the new basket.

Re: Admin placing an order - error with Volume Discounts

Posted: Thu Jul 30, 2009 7:35 am
by niall08
I won't labour the point as it's working now, which is a big relief, but it wasn't updating the Basket object from the code that was unchanged from the out-of-the-box version.

There's something deeper here as the code worked for every other instance, but failed to update the basket object only when there was a volume discount in place.

Anyway, it's working now.

Thanks,
Niall