Adding to Shopping Cart from External Entity

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Adding to Shopping Cart from External Entity

Post by CASE » Fri May 08, 2009 7:59 am

I need to add to the shopping cart from an external entity. I've read the information at http://wiki.ablecommerce.com/index.php/ ... nal_entity. I understand the link piece but I am not sure where the referenced code needs to go - as a separate aspx page in ConLib? As part of the Basket Page? (I am not a programmer but am trying to make this work!).

If there is more information on this somewhere else, that would also be very helpful.

Thanks for your guidance!

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Adding to Shopping Cart from External Entity

Post by compunerdy » Fri May 08, 2009 8:37 am

I could not figure it out either but thanks to Joe @ solunar I have working code now..

AddToBasket.aspx

Code: Select all

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AddToBasket.aspx.vb" Inherits="AddToBasket" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

<% Response.Redirect("basket.aspx") %>

AddToBasket.aspx.vb

Code: Select all

Partial Class AddToBasket
    Inherits System.Web.UI.Page

    Dim _ProductId As Integer


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim _ProductIds As String() = Request.QueryString("ProductIds").Split(",")
        For Each _Param As String In _ProductIds
            _ProductId = AlwaysConvert.ToInt(_Param)
            AddToCart()
        Next

    End Sub

    Protected Sub AddToCart()
        'GET THE PRODUCT ID FROM THE URL
        Dim product As Product = ProductDataSource.Load(_ProductId)

        If product IsNot Nothing Then
            Dim lastShoppingUrl As String = NavigationHelper.GetLastShoppingUrl()




            If product.HasChoices Then
                'CANT ADD DIRECTLY TO BASKET, SKIP IT
                Return
            End If




            Dim basketItem As BasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1)
            If basketItem IsNot Nothing Then
                'ADD ITEM TO BASKET
                Dim basket As Basket = Token.Instance.User.Basket
                basket.Items.Add(basketItem)
                basket.Save()

                ' IF BASKET HAVE SOME VALIDATION PROBLEMS MOVE TO BASKET PAGE
                Dim basketMessages As List(Of String)
                If Not basket.Validate(basketMessages) Then
                    Session.Add("BasketMessage", basketMessages)
                    Response.Redirect(NavigationHelper.GetBasketUrl())
                End If
            End If
        End If
    End Sub

End Class


CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Adding to Shopping Cart from External Entity

Post by CASE » Fri May 08, 2009 9:55 am

Thanks! When I use this code, I get the error below on line 8. I am not sure what needs to be changed. Any suggestions? The product ID I used as a test in the link does exist in the database. http://cms.case.org/commerce/AddToBaske ... ductId=949.
_____________
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 6:
Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Line 8: Dim _ProductIds As String() = Request.QueryString("ProductIds").Split(",")
Line 9: For Each _Param As String In _ProductIds
Line 10: _ProductId = AlwaysConvert.ToInt(_Param)

Source File: D:\commerce\AddToBasket.aspx.vb Line: 8

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Adding to Shopping Cart from External Entity

Post by compunerdy » Fri May 08, 2009 10:42 am

http://cms.case.org/commerce/AddToBaske ... uctIds=949

ProductIds
not
ProductId

Also the redirect needs to be changed because of where you put the files..will work fine if you put them in the root directory for the site.

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Adding to Shopping Cart from External Entity

Post by CASE » Fri May 08, 2009 12:47 pm

Still no luck! I changed the several ProductID to ProductIDs, changed the location of the file and got the following error.

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30311: Value of type 'Integer' cannot be converted to '1-dimensional array of String'.

Source Error:

Line 8: Dim _ProductIds As String() = Request.QueryString("ProductIds").Split(",")
Line 9: For Each _Param As String In _ProductIds
Line 10: _ProductIds = AlwaysConvert.ToInt(_Param)
Line 11: AddToCart()
Line 12: Next

Source File: D:\commerce\AddToBasket.aspx.vb Line: 10

User avatar
compunerdy
Admiral (ADM)
Admiral (ADM)
Posts: 1283
Joined: Sun Nov 18, 2007 3:55 pm

Re: Adding to Shopping Cart from External Entity

Post by compunerdy » Fri May 08, 2009 12:52 pm

Ug..only change it in the URL..dont change the files at all.

CASE
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 49
Joined: Tue Jan 22, 2008 7:18 am

Re: Adding to Shopping Cart from External Entity

Post by CASE » Fri May 08, 2009 1:02 pm

Thanks for all your help! It worked!

byg22
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Wed Nov 18, 2009 3:38 pm

Re: Adding to Shopping Cart from External Entity

Post by byg22 » Wed Nov 18, 2009 3:57 pm

Will these files work on the Able 5.5 asp.net installation ?

Where should I put those files ?

I have put in the http://mycompanyURL/acb/stores/4/ called AddToBasket.aspx and AddToBasket.aspx.vb

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

Re: Adding to Shopping Cart from External Entity

Post by mazhar » Thu Nov 19, 2009 3:13 am

byg22 wrote:Will these files work on the Able 5.5 asp.net installation ?

Where should I put those files ?

I have put in the http://mycompanyURL/acb/stores/4/ called AddToBasket.aspx and AddToBasket.aspx.vb
No, this mod is for AbleCommerce 7 powered stores. I don't think that It will work on 5.5 cart.

byg22
Ensign (ENS)
Ensign (ENS)
Posts: 2
Joined: Wed Nov 18, 2009 3:38 pm

Re: Adding to Shopping Cart from External Entity

Post by byg22 » Thu Nov 19, 2009 7:04 am

Good to know.

So how can we do the same thing - add items to cart in Able 5.5 from external site ?

If this solution of directly adding items to cart isn't available then I was planning on just directing users to the product pages in the store from external site and then let them add to cart and go through the regular checkout process( good idea ? bad ? )

Please let me know as I have to make a decision whether to write my own mini ecommerce package or to forward the ecommerce process to Able 5.5.

Thanks a bunch
Gandhi

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

Re: Adding to Shopping Cart from External Entity

Post by AbleMods » Thu Nov 19, 2009 7:30 am

compunerdy wrote:I could not figure it out either but thanks to Joe @ solunar I have working code now..
Look at you giving all my secrets away :P
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: Adding to Shopping Cart from External Entity

Post by jmestep » Thu Nov 19, 2009 11:44 am

byg22:
I think there is code on the forums for Able 5, but it might be hard to find.
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

meer2005
Captain (CAPT)
Captain (CAPT)
Posts: 245
Joined: Wed Feb 09, 2005 2:00 pm

Re: Adding to Shopping Cart from External Entity

Post by meer2005 » Wed Feb 03, 2010 2:55 pm

this does not work with an affiliate ID at the end. Any way to make it possible to use this with the affiliate program?

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

Re: Adding to Shopping Cart from External Entity

Post by mazhar » Mon Mar 04, 2013 10:15 am

AddToBasket.aspx for AC Gold can be found here viewtopic.php?f=65&t=17169

Post Reply