Affiliate Add to Cart?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
DFresh
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 33
Joined: Fri Jan 04, 2008 11:12 am

Affiliate Add to Cart?

Post by DFresh » Wed Apr 23, 2008 9:27 am

Is there a way for an affiliate or an external entity to allow customers to add products to the cart from their website? For instance, a customer wants to buy a product that I carry but they are on an affiliate's website. When they click add to cart, it takes them to my shopping cart.

Thanks in advance!

User avatar
m_plugables
Commander (CMDR)
Commander (CMDR)
Posts: 149
Joined: Tue Mar 11, 2008 12:44 am
Contact:

Re: Affiliate Add to Cart?

Post by m_plugables » Mon May 05, 2008 2:48 am

I don't think so that currently any page is providing this facility. But this can be incorporated into ac7 very easily with some small changes. You can create some user control which can handle this type of functionality when placed over some page.
Image
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com

User avatar
m_plugables
Commander (CMDR)
Commander (CMDR)
Posts: 149
Joined: Tue Mar 11, 2008 12:44 am
Contact:

Re: Affiliate Add to Cart?

Post by m_plugables » Mon May 05, 2008 2:57 am

Create a new file ConLib/AddToCartEx.ascx and put the following code in it.

Code: Select all

<%@ Control Language="C#" ClassName="AddToCartEx" %>
<script runat="server">
    private int _ProductId;

    protected void Page_Load(object sender, EventArgs e)
    {
        _ProductId = PageHelper.GetProductId();
        if (_ProductId > 0)
            AddToCart();
    }

    protected void AddToCart()
    {
        //GET THE PRODUCT ID FROM THE URL
        Product product = ProductDataSource.Load(_ProductId);
        if (product != null)
        {
            string lastShoppingUrl = NavigationHelper.GetLastShoppingUrl();
            if (product.HasChoices || product.UseVariablePrice)
            {
                //CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
                Response.Redirect(product.NavigateUrl);
            }
            BasketItem basketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1);
            if (basketItem != null)
            {
                // DETERMINE IF THE LICENSE AGREEMENT MUST BE REQUESTED
                BasketItemLicenseAgreementCollection basketItemLicenseAgreements = new BasketItemLicenseAgreementCollection(basketItem, LicenseAgreementMode.OnAddToBasket);
                if ((basketItemLicenseAgreements.Count > 0))
                {
                    // THESE AGREEMENTS MUST BE ACCEPTED TO ADD TO BASKET
                    List<BasketItem> basketItems = new List<BasketItem>();
                    basketItems.Add(basketItem);
                    string guidKey = Guid.NewGuid().ToString("N");
                    Cache.Add(guidKey, basketItems, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), System.Web.Caching.CacheItemPriority.NotRemovable, null);
                    string acceptUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("~/Basket.aspx"));
                    string declineUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Page.ResolveClientUrl(product.NavigateUrl)));
                    Response.Redirect("~/BuyWithAgreement.aspx?Items=" + guidKey + "&AcceptUrl=" + acceptUrl + "&DeclineUrl=" + declineUrl);
                }

                //ADD ITEM TO BASKET
                Basket basket = Token.Instance.User.Basket;
                basket.Items.Add(basketItem);
                basket.Save();

                //Determine if there are associated Upsell products
                if (basketItem.Product.GetUpsellProducts(basket).Count > 0)
                {
                    //redirect to upsell page
                    string returnUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Request.Url.ToString()));
                    Response.Redirect("~/ProductAccessories.aspx?ProductId=" + basketItem.ProductId + "&ReturnUrl=" + returnUrl);
                }

                // IF BASKET HAVE SOME VALIDATION PROBLEMS MOVE TO BASKET PAGE
                List<string> basketMessages;
                if (!basket.Validate(out basketMessages))
                {
                    Session.Add("BasketMessage", basketMessages);
                    Response.Redirect(NavigationHelper.GetBasketUrl());
                }

                //IF THERE IS NO REGISTERED BASKET CONTROL, WE MUST GO TO BASKET PAGE
                if (!PageHelper.HasBasketControl(this.Page)) Response.Redirect(NavigationHelper.GetBasketUrl());
            }
        }
    }
</script>

<asp:Label ID="Label1" runat="server" Text="Add products to cart from affliates site." Font-Bold="true"></asp:Label>
Now place this control on some page like any normal ConLib control. And place the URL of this page on the site from where you want to send the product to cart. The URL must be contain the Product Id of the desired product. For example

Code: Select all

http://www.somesite.com/mypage.aspx?ProductId
I hope so this sample will help you.
Image
Visit the links below to Download Plugins for your AC7 Store
http://www.plugables.com
http://blog.plugables.com

dtr18c
Ensign (ENS)
Ensign (ENS)
Posts: 7
Joined: Mon Aug 25, 2008 5:05 pm

Re: Affiliate Add to Cart?

Post by dtr18c » Mon Aug 25, 2008 5:18 pm

Hi,

I'm new to AbleCommerce and am trying to make use of the external add to cart functionality.
I've added the user control and added the conlib referenc on a page but when i visit the page it redirects me to the product page and doesn't add anything to the basket.

I'm not quite sure what additional information I should provide in this case.
If anybody has gotten this to work or can help out let me know what other information I can provide to troubleshoot this.

Thanks,
Chad

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

Re: Affiliate Add to Cart?

Post by jmestep » Mon Aug 25, 2008 6:31 pm

Do your products have options? It won't work in that case.
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

dtr18c
Ensign (ENS)
Ensign (ENS)
Posts: 7
Joined: Mon Aug 25, 2008 5:05 pm

Re: Affiliate Add to Cart?

Post by dtr18c » Tue Aug 26, 2008 9:53 am

Thanks for pointing me in the right direction Judy.
I was originally testing this with a kit product.

Is there any way paramaters could be constructed for kit/option items?

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

Re: Affiliate Add to Cart?

Post by jmestep » Tue Aug 26, 2008 1:09 pm

There probably are, since it could be done in Able 5. I just haven't experimented, but you could try adding a kit to the basket from the normal product page and putting code on the basket page to display the parameters it is using.
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