Admin placing an order - error with Volume Discounts

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Admin placing an order - error with Volume Discounts

Post by niall08 » Mon Jul 27, 2009 7:41 am

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

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Mon Jul 27, 2009 8:18 am

The setup for the volume discount is shown in the attachment.

Thanks,
Niall

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Mon Jul 27, 2009 8:48 am

Anyone else experienced similar issues with volume discounts in the admin "place order" functionality??

Any fixes?

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Tue Jul 28, 2009 12:35 am

Any feedback from the development team?

Is this a bug?

Please, some sort of feedback is needed here..

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Admin placing an order - error with Volume Discounts

Post by mazhar » Tue Jul 28, 2009 5:10 am

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.

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Tue Jul 28, 2009 5:28 am

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?

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Tue Jul 28, 2009 7:12 am

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??

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Tue Jul 28, 2009 7:59 am

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..

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Admin placing an order - error with Volume Discounts

Post by mazhar » Tue Jul 28, 2009 9:12 am

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

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Tue Jul 28, 2009 9:21 am

Thanks Mazhar - appreciate that..

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Wed Jul 29, 2009 1:12 am

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

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Admin placing an order - error with Volume Discounts

Post by jmestep » Wed Jul 29, 2009 6:55 am

Could it be because there is no maximum in one of the discount levels per your screen shot?
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Wed Jul 29, 2009 7:40 am

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.

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Wed Jul 29, 2009 8:04 am

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?

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Wed Jul 29, 2009 8:51 am

Maybe someone on the Dev team can tell me what happens during the basket transfer?

I need help here

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Admin placing an order - error with Volume Discounts

Post by sohaib » Wed Jul 29, 2009 10:33 am

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);
            }
        }

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Thu Jul 30, 2009 1:19 am

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?

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Admin placing an order - error with Volume Discounts

Post by sohaib » Thu Jul 30, 2009 1:51 am

method with two parameters is just this

Code: Select all

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

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Thu Jul 30, 2009 6:14 am

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)??

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Admin placing an order - error with Volume Discounts

Post by sohaib » Thu Jul 30, 2009 6:22 am

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);
        }
    }

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Thu Jul 30, 2009 6:54 am

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

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Admin placing an order - error with Volume Discounts

Post by sohaib » Thu Jul 30, 2009 6:58 am

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);
        }
    }

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Thu Jul 30, 2009 7:16 am

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?

User avatar
sohaib
Developer
Developer
Posts: 1079
Joined: Fri Jan 23, 2004 1:38 am

Re: Admin placing an order - error with Volume Discounts

Post by sohaib » Thu Jul 30, 2009 7:31 am

So.. was it a bug?
No. Your basket object was referring to old object. You had to have a reference of the new basket.

niall08
Commander (CMDR)
Commander (CMDR)
Posts: 175
Joined: Tue Dec 09, 2008 10:29 am

Re: Admin placing an order - error with Volume Discounts

Post by niall08 » Thu Jul 30, 2009 7:35 am

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

Post Reply