Programmatically add item to basket issue...

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
acuser777
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Sat May 16, 2009 8:39 pm

Programmatically add item to basket issue...

Post by acuser777 » Mon May 17, 2010 7:13 pm

If a customer applies certain coupon at checkout, I'm adding an item into cart using below code. It does add the item however, the item shows up in non-shipping items order confirmation and packing slip won't show this item either. Other items of the cart appears perfectly fine. Also, if this same item is added by customer from product page, it does appear just fine. Please advice why manually adding this item into basket is causing this problem... am i missing any code?

Code: Select all

CouponProduct cp = coupon.CouponProducts[0];
if (basket.ContainsProduct(cp.ProductId) == false)
{
    BasketItem basketItem = CommerceBuilder.Orders.BasketItemDataSource.CreateForProduct(cp.ProductId, 1);
    basketItem.BasketId = basket.BasketId;
    basket.Items.Add(basketItem);
    basket.Save();
    basket.Recalculate();
}

thanks.

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: Programmatically add item to basket issue...

Post by s_ismail » Tue May 18, 2010 3:08 am

It seems that you are missing basket.Package() method so give a try by calling

Code: Select all

 basket.Package(false, true);
method before calling

Code: Select all

 basket.Recalculate();
mathod.

acuser777
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Sat May 16, 2009 8:39 pm

Re: Programmatically add item to basket issue...

Post by acuser777 » Wed May 19, 2010 2:37 pm

ok. that did the trick.
now, i'm getting another issue during checkout

if I type in credit information and click on pay with card, i get following error message:
-----------------------------------------------------------------------------------------------------------
Your order has not been completed and payment was not processed.

Your cart appears to have been modified during checkout. Please verify the contents of your order and resubmit your payment
-------------------------------------------------------------------------------------------------------------

I've to click once more on pay with card to actually process the order. How can I avoid this?

thanks

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: Programmatically add item to basket issue...

Post by s_ismail » Thu May 20, 2010 5:50 am

I am unable to reproduce such type of error so i think you are missing something there. Match your current code with original OnePageCheckout.ascx.cs code.
One possibility is it can be reaction of your customization.

acuser777
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Sat May 16, 2009 8:39 pm

Re: Programmatically add item to basket issue...

Post by acuser777 » Thu May 20, 2010 7:41 pm

Since I'm adding an item into cart during checkout, its changing the basket hash... i'll need to put a flag in session somewhere in the coupon code and then check that flag in one page checkout control to trigger hash recalculation. Alternatively, i'm thinking to move coupon control in basket.aspx. that way i don't need to play with onepagecheckout and it would be much cleaner.

thanks

Post Reply