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!
Programatically add products to basket
-
- Lieutenant, Jr. Grade (LT JG)
- Posts: 21
- Joined: Tue Mar 03, 2009 10:49 am
Re: Programatically add products to basket
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
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
-
- Lieutenant, Jr. Grade (LT JG)
- Posts: 21
- Joined: Tue Mar 03, 2009 10:49 am
Re: Programatically add products to basket
Excellent!!!
That works perfectly! Thanks!
That works perfectly! Thanks!