Programatically add products to basket

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
cgreathouse
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 21
Joined: Tue Mar 03, 2009 10:49 am

Programatically add products to basket

Post by cgreathouse » Thu May 21, 2009 10:46 am

Hello,

I'm looking for some guidance on how to pragmatically add a product to the basket. For example I have some products that depend on other products.

So if...

ProductA is ordered, products ProductB, ProductC and ProductD must also be ordered.

I already have a mapping of dependent products to products, I just need to pragmatically add products (ProductA, ProductC & ProductD) to the basket. Can anyone give me any pointers?

Thanks!

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: Programatically add products to basket

Post by heinscott » Thu May 21, 2009 11:00 am

If your ProductId is _ProductId, then, to add a qty 1 of that product to the basket:

Basket _basket = Token.Instance.User.Basket;
BasketItem bi = BasketItemDataSource.CreateForProduct(_ProductId, 1));
_basket.Items.Add(bi);
_basket.Save();

(gets a bit more confusing if you are adding a kit).

Scott

cgreathouse
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 21
Joined: Tue Mar 03, 2009 10:49 am

Re: Programatically add products to basket

Post by cgreathouse » Thu May 21, 2009 12:51 pm

Excellent!!!

That works perfectly! Thanks!

Post Reply