Adding to cart via flash or other type of post method
Re: Adding to cart via flash or other type of post method
You can send multiple product ids via single URL and then load and them to basket similarly as WIKI post is doing for a single product.
Re: Adding to cart via flash or other type of post method
For example URL could be like
Then in control part you can update Page_Load method like
Regarding custom fields yes you I think its possible. Give a try and make your URL something like
Now in Page_Load you can first split on "," which will return you product id with fields. Then split each string on "-" which will give you one product id one list of custom fields. Finally split each list of custom fields to get each single custom field info
Code: Select all
http://yourstoreurl/AddToBasket.aspx?ProductIds=1,2,3,4,5,6,7,8
Code: Select all
protected void Page_Load(object sender, EventArgs e)
{
string[] productIds = Request.QueryString["ProductIds"].Split(',');
foreach(string productId in productIds)
{
_ProductId = AlwaysConvert.ToInt(productId);
if (_ProductId > 0)
AddToCart();
}
}
Code: Select all
http://yourstoreurl/AddToBasket.aspx?ProductIds=1-c1:c2,2,3,4,5,6,7,8
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I would love it if you could provide working code when you get this to work please. I also have a flash program I would like to us to add a string of items to a order.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I messed around with this just trying to add a single item to the cart via a URL using the WIKI code and couldnt get it to work. Can you provide a working sample of this?
Re: Adding to cart via flash or other type of post method
Once you are able to get text from URL you can try to add this text to customer input in some quite similar manner as ProductHelper methods are collecting customer input. Check App_Code/ProductHelper.cs class about how to manipulate product inputs.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Mazhar,
Thanks to Joe, I got the wiki code to work and I can add a string of simple items fine. Is there anyway to make it add kits? I have a lot of kits that DO NOT have choices that need to be made, is there anyway to make it add them to the cart correctly?
Thanks to Joe, I got the wiki code to work and I can add a string of simple items fine. Is there anyway to make it add kits? I have a lot of kits that DO NOT have choices that need to be made, is there anyway to make it add them to the cart correctly?
Re: Adding to cart via flash or other type of post method
Give a try and edit the code you got from WIKI, locate following code blockcompunerdy wrote:Mazhar,
Thanks to Joe, I got the wiki code to work and I can add a string of simple items fine. Is there anyway to make it add kits? I have a lot of kits that DO NOT have choices that need to be made, is there anyway to make it add them to the cart correctly?
Code: Select all
if (product.HasChoices)
{
//CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(p
Code: Select all
if (product.HasChoices)
{
if (product.KitStatus == KitStatus.Master)
{
bool addToCart = true;
KitComponentCollection kitComponents = KitComponentDataSource.LoadForProduct(_ProductId);
foreach (KitComponent kitComponent in kitComponents)
{
if (kitComponent.InputType == KitInputType.CheckBox || kitComponent.InputType == KitInputType.DropDown || kitComponent.InputType == KitInputType.RadioButton)
{
addToCart = false;
break;
}
}
if (!addToCart)
//CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(product.NavigateUrl);
}
else
{
//CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(product.NavigateUrl);
}
}
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Mazhar
Here is the code I am using. It will now add the parent item of a kit with 0 price but it still wont add the included/hidden sub items.
addtobasket.aspx
addtobasket.aspx.vb
Here is the code I am using. It will now add the parent item of a kit with 0 price but it still wont add the included/hidden sub items.
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") %>
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
If product.KitStatus = KitStatus.Master Then
Dim _addtocart As Boolean = True
Dim _kitcomponents As KitComponentCollection = KitComponentDataSource.LoadForProduct(product.ProductId)
For Each _KitComponent As KitComponent In _kitcomponents
If _KitComponent.InputType = KitInputType.CheckBox Or _KitComponent.InputType = KitInputType.DropDown Or _KitComponent.InputType = KitInputType.RadioButton Then
_addtocart = False
Exit For
End If
Next
If Not _addtocart Then
'CANT ADD DIRECTLY TO BASKET, SKIP IT
Return
End If
Else
'CANT ADD DIRECTLY TO BASKET, SKIP IT
Return
End If
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 cart via flash or other type of post method
Try following updated control file. Now the code will add Included-Hidden/Included-Shown kit components as well to basket.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Having trouble getting the new code to work at all. Maybe I am just not using it correctly as the code Joe got working for me (posted above) is in VB and yours is C#. If I try to access your new file directly it gives me a server error. Can you provide a working file set that I can just upload and use?
Re: Adding to cart via flash or other type of post method
Could you post server error that occurs if you directly use the file.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Can you mod this page to use the new user control?
addtobasket.aspx
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") %>
Re: Adding to cart via flash or other type of post method
Instead of using complete file just update the required part. Locate following code part
with below
Code: Select all
if (product.HasChoices)
{
//CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(product.NavigateUrl);
}
Code: Select all
if (product.HasChoices)
{
if (product.KitStatus == KitStatus.Master)
{
List<int> selectedKitProducts = new List<int>();
//COLLECT ANY KIT VALUES
foreach (ProductKitComponent pkc in product.ProductKitComponents)
{
// FIND THE CONTROL
KitComponent component = pkc.KitComponent;
if (component.InputType == KitInputType.IncludedHidden || component.InputType == KitInputType.IncludedShown)
{
foreach (KitProduct choice in component.KitProducts)
{
selectedKitProducts.Add(choice.KitProductId);
}
}
}
BasketItem kitBasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1, string.Empty, selectedKitProducts);
Token.Instance.User.Basket.Items.Add(kitBasketItem);
Token.Instance.User.Basket.Save();
//IF THERE IS NO REGISTERED BASKET CONTROL, WE MUST GO TO BASKET PAGE
if (!PageHelper.HasBasketControl(this.Page)) Response.Redirect(NavigationHelper.GetBasketUrl());
}
//CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(product.NavigateUrl);
}
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I updated my code above with your new code like this..
Now I get this error.
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
If product.KitStatus = KitStatus.Master Then
Dim selectedKitProducts As New List(Of Integer)()
'COLLECT ANY KIT VALUES
For Each pkc As ProductKitComponent In product.ProductKitComponents
' FIND THE CONTROL
Dim component As KitComponent = pkc.KitComponent
If component.InputType = KitInputType.IncludedHidden OrElse component.InputType = KitInputType.IncludedShown Then
For Each choice As KitProduct In component.KitProducts
selectedKitProducts.Add(choice.KitProductId)
Next
End If
Next
Dim kitBasketItem As BasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1, String.Empty, selectedKitProducts)
Token.Instance.User.Basket.Items.Add(kitBasketItem)
Token.Instance.User.Basket.Save()
'IF THERE IS NO REGISTERED BASKET CONTROL, WE MUST GO TO BASKET PAGE
If Not PageHelper.HasBasketControl(Me.Page) Then
Response.Redirect(NavigationHelper.GetBasketUrl())
End If
End If
'CANT ADD DIRECTLY TO BASKET, SEND TO MORE INFO
Response.Redirect(product.NavigateUrl)
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
Now I get this error.
Code: Select all
Compiler Error Message: BC30311: Value of type 'System.Collections.Generic.List(Of Integer)' cannot be converted to 'String'.
Source Error:
Line 38: Next
Line 39:
Line 40: Dim kitBasketItem As BasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1, String.Empty, selectedKitProducts)
Line 41:
Line 42: Token.Instance.User.Basket.Items.Add(kitBasketItem)
Re: Adding to cart via flash or other type of post method
That's strange I just created a VB page put all your code in it and its working great. Check attached file. What is your application version I have tested code on 7.0.2
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I just installed those files and I am still getting the same error as seen here..
http://www.thecustomsabershop.com/addto ... uctIds=183
Build 7.0.3
http://www.thecustomsabershop.com/addto ... uctIds=183
Build 7.0.3
Re: Adding to cart via flash or other type of post method
Yep just found that those files are not working on 7.0.3.
Re: Adding to cart via flash or other type of post method
Locate following line of code in your page
and replace it with following
save file and then try to add some kit products via URL.
Code: Select all
Dim kitBasketItem As BasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1, String.Empty, selectedKitProducts)
Code: Select all
Dim kitBasketItem As BasketItem = BasketItemDataSource.CreateForProduct(_ProductId, 1, String.Empty, AlwaysConvert.ToList(",", selectedKitProducts))
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Looks great so far..thanks Mazhar!!!
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I spoke too soon..
It works fine for a single item like this..
http://www.thecustomsabershop.com/addto ... uctIds=183
but not for a string like this
http://www.thecustomsabershop.com/addto ... ds=183,184
It only adds the first item.
It works fine for a single item like this..
http://www.thecustomsabershop.com/addto ... uctIds=183
but not for a string like this
http://www.thecustomsabershop.com/addto ... ds=183,184
It only adds the first item.
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I did some more testing. When adding items via the URL string...
If you have a kit item then all items (kit or regular) in the string after it will be ignored.
Example http://www.thecustomsabershop.com/addto ... 183,184,73
If you have a non kit item it is added to cart but the redirect to cart doesnt work.
Example http://www.thecustomsabershop.com/addto ... ductIds=73
You can have multiple non kit items and then a single kit item and it all works fine.
Example http://www.thecustomsabershop.com/addto ... 73,107,183
So.. kit items are not looping and regular items are stopping the code??? Something like that
If you have a kit item then all items (kit or regular) in the string after it will be ignored.
Example http://www.thecustomsabershop.com/addto ... 183,184,73
If you have a non kit item it is added to cart but the redirect to cart doesnt work.
Example http://www.thecustomsabershop.com/addto ... ductIds=73
You can have multiple non kit items and then a single kit item and it all works fine.
Example http://www.thecustomsabershop.com/addto ... 73,107,183
So.. kit items are not looping and regular items are stopping the code??? Something like that
Re: Adding to cart via flash or other type of post method
Tim thanks for detailed information about reproduction cases. I have seen the code and there were some things needs to be updated. Here is updated page
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
I had to make a change but now it works great. I had to move a else if as it wasnt processing normal items. Here is the final code that works perfectly (as far as I can tell so far)
AddToBasket.aspx.vb
AddToBasket.aspx
Anyone wanting to see this all in action can check out my flash program here
http://www.thecustomsabershop.com/mhsbuilder/
Just add some items to the screen and then click on "parts list" at the top and then "add to cart"
AddToBasket.aspx.vb
Code: Select all
Partial Class AddToBasket
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddToCart()
End Sub
Protected Sub AddToCart()
Dim productParams As String
productParams = Request.QueryString("ProductIds")
If (String.IsNullOrEmpty(productParams)) Then
Response.Redirect(Token.Instance.Store.StoreUrl)
End If
Dim productIds As String() = productParams.Split(",")
For Each id As String In productIds
Dim productId As Integer = AlwaysConvert.ToInt(id)
''GET THE PRODUCT ID FROM THE URL
Dim product As Product = ProductDataSource.Load(productId)
If product IsNot Nothing Then
If product.HasChoices Then
If product.KitStatus = KitStatus.Master Then
Dim selectedKitProducts As New List(Of Integer)
''COLLECT ANY KIT VALUES
For Each pkc As ProductKitComponent In product.ProductKitComponents
'' FIND THE CONTROL
Dim component As KitComponent = pkc.KitComponent
If component.InputType = KitInputType.IncludedHidden OrElse component.InputType = KitInputType.IncludedShown Then
For Each choice As KitProduct In component.KitProducts
selectedKitProducts.Add(choice.KitProductId)
Next
End If
Next
Dim kitBasketItem As BasketItem = BasketItemDataSource.CreateForProduct(productId, 1, String.Empty, AlwaysConvert.ToList(",", selectedKitProducts.ToArray()))
Token.Instance.User.Basket.Items.Add(kitBasketItem)
Token.Instance.User.Basket.Save()
Else
Dim basketItem As BasketItem = BasketItemDataSource.CreateForProduct(productId, 1)
Token.Instance.User.Basket.Items.Add(basketItem)
Token.Instance.User.Basket.Save()
End If
Else
Dim basketItem As BasketItem = BasketItemDataSource.CreateForProduct(productId, 1)
Token.Instance.User.Basket.Items.Add(basketItem)
Token.Instance.User.Basket.Save()
End If
End If
Next
Response.Redirect(NavigationHelper.GetBasketUrl())
End Sub
End Class
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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Anyone wanting to see this all in action can check out my flash program here
http://www.thecustomsabershop.com/mhsbuilder/
Just add some items to the screen and then click on "parts list" at the top and then "add to cart"
- compunerdy
- Admiral (ADM)
- Posts: 1283
- Joined: Sun Nov 18, 2007 3:55 pm
Re: Adding to cart via flash or other type of post method
Any idea as to why after upgrading to 7.0.7 and .net 4.0 the above code no longer works and gives the following error?
C:\Sites\thecustomsabershop\AddToBasket.aspx.vb(47): error BC32206: The project currently contains references to more than one version of CommerceBuilder.Configuration, a direct reference to version 7.7.14421.0 and an indirect reference (through 'CommerceBuilder.Common.Token') to version 7.7.14567.0. Change the direct reference to use version 7.7.14567.0 (or higher) of CommerceBuilder.Configuration.
C:\Sites\thecustomsabershop\AddToBasket.aspx.vb(47): error BC32206: The project currently contains references to more than one version of CommerceBuilder.Configuration, a direct reference to version 7.7.14421.0 and an indirect reference (through 'CommerceBuilder.Common.Token') to version 7.7.14567.0. Change the direct reference to use version 7.7.14567.0 (or higher) of CommerceBuilder.Configuration.