VirtueMart Forum

VirtueMart 2 + 3 => General Questions => Topic started by: jbenes on July 19, 2012, 18:55:51 pm

Title: Undefined was added to your cart
Post by: jbenes on July 19, 2012, 18:55:51 pm
Hi. I am having a problem with my Virtuemart site. When I add a product to the cart, the popup appears telling me the product was added, however, instead of displaying the product name, it says "Undefined was added to your cart." When I view the cart, the correct item is there, but I would rather it say the name of the item rather than just undefined.

I am using Virtuemart 2.0.8c with J 2.5. My site is https://www.survivorssupply.com.

Thanks for your help!
Title: Re: Undefined was added to your cart
Post by: ivus on July 20, 2012, 07:05:01 am
Hi jbenes,

This is a very simple error to fix. At first I thought perhaps all the social networking plugins you installed was killing the AJAX script, but then I realised that the form was bring submitted and returned, so that wasn't the problem. Then I looked a bit deeper and noticed that you had an incomplete form setup.

Here's the code block for each product's ADD TO CART that you had created:


  <div style="padding-top:25px;">
    <form method="post" class="product" action="index.php" id="addtocartproduct65">
      <div class="addtocart-bar">
        <!-- <label for="quantity65" class="quantity_box">Quantity: </label> -->
        <span class="quantity-box">
          <input type="text" class="quantity-input" name="quantity[]" value="1">
        </span>

        <span class="quantity-controls">
          <input type="button" class="quantity-controls quantity-plus">
          <input type="button" class="quantity-controls quantity-minus">
        </span>

        <span class="addtocart-button">
          <input type="submit" name="addtocart" class="addtocart-button" value="Add to Cart" title="Add to Cart">
        </span>

      </ div>
      <div class="clear"></ div>
    </form>

  </ div>
  <input type="hidden" class="pname" value="Ancient Grains Preparedness Seeds">
  <input type="hidden" name="option" value="com_virtuemart">
  <input type="hidden" name="view" value="cart">
  <noscript>
  &lt;input type="hidden" name="task" value="add" /&gt;
  </noscript>
  <input type="hidden" name="virtuemart_product_id[]" value="65">
  <input type="hidden" name="virtuemart_manufacturer_id" value="1">
  <input type="hidden" name="virtuemart_category_id[]" value="6">

  <div class="clear"></ div>


Pay particular attention to the form (highlighted in blue), and then see the hidden fields (highlighted in red).

The hidden fields is what tells the AJAX script what to put into the cart, but because it's been placed outside of the form block, it never gets submitted.

To fix it, simply put the blue field within your form block and it should work.

I hope this helps.
Title: Re: Undefined was added to your cart
Post by: jbenes on July 24, 2012, 06:53:28 am
Thanks! Sorry about such a late reply, this helped a lot.  ;D