Issue #9 resolved

shoppingcart.js mini cart ajax bug

manudea
created an issue

Scenario:

  • put a cart widget in a page
  • add product to cart
  • when cart is empty all is ok

if you click add again

  • expected behavior is "another product is added to cart"
  • but instead no product is added, and if you refresh page you see that all product are removed from cart

reproduce live here: http://jacopo.cms.duemetri.com/product-categories/category-1

Reason:

on first call is called

Nwazet.Commerce/ShoppingCart/Add/{product}

all is ok

on second call is called

/Nwazet.Commerce/ShoppingCart/AjaxUpdate

inspecting the ajax call you see that the second product has missing product id

I have narrowed the problem to this row of shopping cart

shoppingcart.js, row 77: productId = addForm.data("productid"),

it is null....

Comments (8)

  1. manudea reporter

    I just take it from repository, latest version... on 2 different machines. My local orchard source code and on server downloaded orchard zip and put the latest hg (staging link: http://jacopo.cms.duemetri.com/product-categories/category-2 )

    This is what is sent to Add action first time

    productattributes[0].Key=23 productattributes[0].Value=L quantity=1

    This is what is sent to Ajax (inspecting with fiddler)

    items[0].AttributeIdsToValues[0].Key=23 items[0].AttributeIdsToValues[0].Value=L items[0].ProductId=21 items[0].Quantity=1 items[1].ProductId
    items[1].Quantity=1 items[1].AttributeIdsToValues[0].Key=23 items[1].AttributeIdsToValues[0].Value=L

    note that items[1].ProductId is empty... ajax then fails with a 500 error and makes cart invalid subsequent calls to cart fails with error 500

  2. manudea reporter

    More insights:

    compare this form form nwatez site: <form action="/Nwazet.Commerce/ShoppingCart/Add/16165" class="addtocart" data-productid="16165" method="post">

    with one of mine: <form action="/OrchardLocal/nwazet.commerce/ShoppingCart/Add/42" class="addtocart" method="post" shape-id="12">

    the data-productid is missing on mine! and the code is the one from repository...

    fix is change one line in Product.AddButton.cshtml

    from:

    q w (Html.BeginFormAntiForgeryPost(Url.Action("Add", "ShoppingCart", new { area = "Nwazet.Commerce", id = productId}), FormMethod.Post, new {class = "addtocart" })) {

    to

    q w (Html.BeginFormAntiForgeryPost(Url.Action("Add", "ShoppingCart", new { area = "Nwazet.Commerce", id = productId}), FormMethod.Post, new Dictionary<string, object>{ {"class", "addtocart"}, { "data-productid", productId }}))

  3. Log in to comment