Adding to Shopping Cart from External Entity
Adding to Shopping Cart from External Entity
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!
If there is more information on this somewhere else, that would also be very helpful.
Thanks for your guidance!
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to Shopping Cart from External Entity
I could not figure it out either but thanks to Joe @ solunar I have working code now..
AddToBasket.aspx
AddToBasket.aspx.vb
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
Re: Adding to Shopping Cart from External Entity
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
_____________
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
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to Shopping Cart from External Entity
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.
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.
Re: Adding to Shopping Cart from External Entity
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
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
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to Shopping Cart from External Entity
Ug..only change it in the URL..dont change the files at all.
Re: Adding to Shopping Cart from External Entity
Thanks for all your help! It worked!
Re: Adding to Shopping Cart from External Entity
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
Where should I put those files ?
I have put in the http://mycompanyURL/acb/stores/4/ called AddToBasket.aspx and AddToBasket.aspx.vb
Re: Adding to Shopping Cart from External Entity
No, this mod is for AbleCommerce 7 powered stores. I don't think that It will work on 5.5 cart.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
Re: Adding to Shopping Cart from External Entity
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
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
Re: Adding to Shopping Cart from External Entity
Look at you giving all my secrets awaycompunerdy wrote:I could not figure it out either but thanks to Joe @ solunar I have working code now..

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
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
- 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
byg22:
I think there is code on the forums for Able 5, but it might be hard to find.
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
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
Re: Adding to Shopping Cart from External Entity
this does not work with an affiliate ID at the end. Any way to make it possible to use this with the affiliate program?
Re: Adding to Shopping Cart from External Entity
AddToBasket.aspx for AC Gold can be found here viewtopic.php?f=65&t=17169