Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 7 of 7

Thread: Add to Cart Issue

  1. #1
    Fean0r is offline Senior Member
    Join Date
    Nov 2009
    Posts
    145

    Default Add to Cart Issue

    Hey,

    I tried using <xsl:value-of select="aspdnsf:AddtoCartForm(ProductID, VariantID, 1)" disable-output-escaping="yes"/> twice on my tabbed product page however once I have 2 add to cart button they both stopped working?

    Is this a known issue? Can I resolve it?

    Thanks
    Version: ML 8.0.1.2 and No Source Code.

  2. #2
    Fean0r is offline Senior Member
    Join Date
    Nov 2009
    Posts
    145

    Default

    I never resolved this issue and although we just stuck with 1 add to cart we are chaging the page design and now want 2 again however if I do this;

    <xsl:value-of select="aspdnsf:AddtoCartForm(ProductID, VariantID, 1)" disable-output-escaping="yes"/>

    <xsl:value-of select="aspdnsf:AddtoCartForm(ProductID, VariantID, 1)" disable-output-escaping="yes"/>

    Both button dont work... any ideas anyone?
    Version: ML 8.0.1.2 and No Source Code.

  3. #3
    Soulfire86 is offline Junior Member
    Join Date
    Jun 2010
    Posts
    11

    Default

    I don't know how to fix this, but I think I know why it's having problems, as this is similar to a problem I have.

    Each AddtoCartForm does a validation, and the name of the "form" is based off of the ProductID & VariantID, so if you try to add two for the same product, the validation fails and causes the button not to work.

    At least that's the case for me. On a CategoryCondensed page, there are a few products that are mapped to several of the categories, so when they are all on the same page, the validation fails because they are "duplicate" even though I want them on there more than once.

    Anyone else know how to get around this?
    8.0.1.1 ML C# - Production
    9.0.1.2 ML C# - Development

  4. #4
    Fean0r is offline Senior Member
    Join Date
    Nov 2009
    Posts
    145

    Default

    I've had no joy either, we're stucjk with 1 at the moment.
    Version: ML 8.0.1.2 and No Source Code.

  5. #5
    chrismartz is offline Senior Member
    Join Date
    Apr 2010
    Posts
    339

    Default

    Anyone find any solution to this?

  6. #6
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    This feels like the issue I'm having. Interestingly enough, I'm not getting any JavaScript errors or errors in the System Log. I've added the Add To Cart button on my search page and I've also added Product.js to my master page, so I can have the button everywhere and it will show up. However, I still can't figure out why it is posting back but nothing is actually added to the cart.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM

  7. #7
    cjbarth is offline Senior Member
    Join Date
    Oct 2008
    Posts
    392

    Default

    Ok, I've got this figured out. On any given XMLPackage page that you want to add the Add To Cart button to there are a few things that are needed.

    1. You must include something like
      Code:
      <xsl:value-of select="aspdnsf:AddtoCartForm(ProductID, VariantID, 0, 'left')" disable-output-escaping="yes" />
      in the xml.config page.
    2. The code-behind of the page that drives the XMLPackage that you are working with needs some coded added, so you must find out which on that is. You can look in the web.config in the <routeTable><routes> section for hints.
    3. Once you get to the code-behind page the Page_Load routine needed to have the following added to it:
      Code:
                  Dim scrptMgr As ScriptManager = Page.Master.FindControl(Of ScriptManager)("scrptMgr")
                  scrptMgr.Scripts.Add(New ScriptReference("~/jscripts/product.js"))
      
                  If Me.IsPostBack AndAlso IsAddToCartPostBack Then
                      HandleAddToCart()
                      Return
                  End If
    4. Then, you need to add the following to the same code-behind file:
      Code:
              Public ReadOnly Property IsAddToCartPostBack() As Boolean
                  Get
                      Return "AddToCart".Equals(CommonLogic.FormCanBeDangerousContent("__EVENTTARGET"), StringComparison.InvariantCultureIgnoreCase)
                  End Get
              End Property
      
              Private Sub HandleAddToCart()
                  ' extract the input parameters from the form post
                  Dim formInput As AddToCartInfo = AddToCartInfo.FromForm(ThisCustomer)
      
                  If formInput IsNot AddToCartInfo.INVALID_FORM_COMPOSITION Then
                      Dim success As Boolean = ShoppingCart.AddToCart(ThisCustomer, formInput)
                      AppLogic.eventHandler("AddToCart").CallEvent("&AddToCart=true&VariantID=" & formInput.VariantId.ToString() & "&ProductID=" & formInput.ProductId.ToString() & "&ChosenColor=" & formInput.ChosenColor.ToString() & "&ChosenSize=" & formInput.ChosenSize.ToString())
                      If success Then
                          Dim stayOnThisPage As Boolean = AppLogic.AppConfig("AddToCartAction").Equals("STAY", StringComparison.InvariantCultureIgnoreCase)
                          If stayOnThisPage Then
                              ' some tokens like the shoppingcart qty may already be rendered
                              ' we therefore need to re-display the page to display the correct qty
                              Response.Redirect(Me.Request.Url.ToString())
                          Else
                              Dim returnUrl As String = CommonLogic.GetThisPageName(False) & "?" & CommonLogic.ServerVariables("QUERY_STRING")
      
                              If formInput.CartType = CartTypeEnum.WishCart Then
                                  Response.Redirect(ResolveClientUrl("~/wishlist.aspx?ReturnUrl=" & Security.UrlEncode(returnUrl)))
                              End If
                              If formInput.CartType = CartTypeEnum.GiftRegistryCart Then
                                  Response.Redirect(ResolveClientUrl("~/giftregistry.aspx?ReturnUrl=" & Security.UrlEncode(returnUrl)))
                              End If
                              ' default
                              Response.Redirect(ResolveClientUrl("~/ShoppingCart.aspx?add=true&ReturnUrl=" & Security.UrlEncode(returnUrl)))
                          End If
                      End If
                  End If
      
                  Return
              End Sub


    These modifications were lifted from the showcategory.aspx.vb page, so you can reference that on your own if there are issues or if you are using a different version of ASPDNSF.
    ML9.3.1.1
    SQL 2012 Express
    VS 2010
    Azure VM