Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > can i add to shopping cart using AJAX ? View modes: 
User avatar
Member
Member
gujju121-31-yahoo - 3/16/2010 11:17:44 PM
   
can i add to shopping cart using AJAX ?
im using portal engine and the CartItemSelector control to generate my ' add to cart' links

<uc1:CartItemSelector id="cartItemSelector" runat="server" SKUID='12' SKUEnabled="true"
AddToCartImageButton="AddToCart.gif" ShowUnitsTextBox="true"
ShowProductOptions="true" AddToCartLinkText="Add to Cart" ShowPriceIncludingTax="true" OnOnAddToShoppingCart />

whenever the 'add to cart' button is pressed the user is redirected to the shopping cart. I want them to remain on the product page - the shopping cart insertion should take place in the back ground.

How can this be done ?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 3/17/2010 6:39:37 AM
   
RE:can i add to shopping cart using AJAX ?
Hi,

If you add product to shopping cart you are redirected to shopping cart content control. So, in Page_Load method of this control

~\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartContent.ascx.cs

You can use following example code to redirect back to original page:

// Try to find the Previeous page in session
string prevPage = ValidationHelper.GetString(SessionHelper.GetValue("ShoppingCartUrlReferrer"), "");

if (!String.IsNullOrEmpty(prevPage))
{
UrlHelper.Redirect(prevPage);
}
else
{
UrlHelper.Redirect(this.ShoppingCartControl.PreviousPageUrl);
}


However, then you will be redirected all the time back to the page which you have added the product from, so you will not be able to access shopping cart directly. So, you would also need to modify

~/CMSModules/Ecommerce/Controls/ProductOptions/ShoppingCartItemSelector.ascx.cs

control which is responsible for redirecting to shipping cart content control. In this control you can for example add additional query string parameter to posted URL and in shopping cart content control you will redirect back only if such query string is in current URL. In this way if someone access shopping cart, he/she will not be redirected back (since of your condition) and if someone tried to add product to the shopping cart he/she will be redirected back to the same page.

Otherwise, you need to modify

~/CMSModules/Ecommerce/Controls/ProductOptions/ShoppingCartItemSelector.ascx.cs

in such a way that it will add the products to shopping cart in code according to following KB article.

Best regards,
Juraj Ondrus