Copy a basket, but leave items in original basket

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Copy a basket, but leave items in original basket

Post by jmestep » Fri Jun 19, 2009 1:12 pm

Has anyone found a method to copy the items in a basket and leave the items in the old basket also?
Basket.Transfer deletes them from the first basket and in a situation where you are emailing a basket to a friend or friends, it works fine according a post from mazhar earlier, but we need to keep the contents of the original basket for the potentiality of another friend viewing it.
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

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Copy a basket, but leave items in original basket

Post by AbleMods » Fri Jun 19, 2009 9:33 pm

Have you tried making a new basket instance and doing Token.Instance.User.Baskets.Add(_NewBasket)?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

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

Re: Copy a basket, but leave items in original basket

Post by jmestep » Sat Jun 20, 2009 6:46 am

I'll look at that. I make a new basket, new user, access code in the code to send a basket email, then another new basket as a result of clicking the link in the email and going to the basket page.
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

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Copy a basket, but leave items in original basket

Post by AbleMods » Sat Jun 20, 2009 7:48 am

I'm pretty sure baskets is another class just like all the others. You can make a new instance and .add(_new).

The question would be what Able considers "the basket" when the user has multiple baskets. Is it the most recently saved basket? Or is it the first basket?
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

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

Re: Copy a basket, but leave items in original basket

Post by mazhar » Mon Jun 22, 2009 6:32 am

jmestep wrote:Has anyone found a method to copy the items in a basket and leave the items in the old basket also?
Basket.Transfer deletes them from the first basket and in a situation where you are emailing a basket to a friend or friends, it works fine according a post from mazhar earlier, but we need to keep the contents of the original basket for the potentiality of another friend viewing it.
Try to accomplish it as below, the key point is to call basket.Save before assigning any basket item to it. The reason is basket items are attached to basket depending upon basket it, so in order to put items in to new basket first you need to have a basket with new id.

Code: Select all

Basket basket = new Basket();
        basket.UserId = Token.Instance.UserId;
        basket.Save();
        foreach (BasketItem bi in Token.Instance.User.Basket.Items)
            basket.Items.Add(bi);
        basket.Save();

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

Re: Copy a basket, but leave items in original basket

Post by jmestep » Mon Jun 22, 2009 7:04 am

OK, I will try that. Thanks.
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

Post Reply