Page 1 of 1

Programmatically add item to basket issue...

Posted: Mon May 17, 2010 7:13 pm
by acuser777
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.

Re: Programmatically add item to basket issue...

Posted: Tue May 18, 2010 3:08 am
by s_ismail
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.

Re: Programmatically add item to basket issue...

Posted: Wed May 19, 2010 2:37 pm
by acuser777
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

Re: Programmatically add item to basket issue...

Posted: Thu May 20, 2010 5:50 am
by s_ismail
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.

Re: Programmatically add item to basket issue...

Posted: Thu May 20, 2010 7:41 pm
by acuser777
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