Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Moran 285 posts 934 karma points
    Feb 11, 2014 @ 11:35
    Moran
    0

    Update mini cart javascript

    My miniCart is not updating.

    the "updateMiniCart()" is called and I get no errors in the console but the "totalQuantity' equals 0 every time.

    this is the "updateMiniCart" function

    function updateMiniCart() {
        var order = TC.getCurrentOrder();
        var miniCart = jQuery('#miniCart');
    
        if (miniCart[0]) {
            var totalQuantity = getOrderTotalQuantity(order);
            //miniCart.find('#miniCartTotalPrice').text(order.subtotalPrice.withVatFormatted);
            miniCart.find('#miniCartTotalQuantity').text(totalQuantity);
            miniCart.attr('class', 'items' + totalQuantity);
        }
    }

    and this is the order object

     {id: "b7af2434-d051-419e-884d-da7e4fd08785", storeId: 1, copiedFromOrderId: "", currencyId: 2, orderStatusId: 1…}
    cartNumber: "CART-5"
    copiedFromOrderId: ""
    currencyId: 2
    customerId: ""
    dateCreated: Tue Feb 11 2014 10:21:03 GMT+0200 (Jerusalem Standard Time)
    dateFinalized: null
    dateModified: Tue Feb 11 2014 10:21:03 GMT+0200 (Jerusalem Standard Time)
    id: "b7af2434-d051-419e-884d-da7e4fd08785"
    isFinalized: false
    languageId: null
    orderLines: Array[0]
    length: 0
    __proto__: Array[0]
    orderNumber: ""
    orderStatusId: 1
    paymentInformation: Object
    properties: Object
    shipmentInformation: Object
    storeId: 1
    subtotalPrice: Object
    subtotalPrices: Array[3]
    0: Object
    1: Object
    2: Object
    length: 3
    __proto__: Array[0]
    totalPrice: Object
    totalPrices: Array[3]
    totalQuantity: 0
    transactionInformation: Object
    vatGroupId: 1
    vatRate: Object
    __proto__: Object

    I am using umbraco version 6.1.6 and teaCommerce 2.2.2

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 11, 2014 @ 11:49
    Rune Grønkjær
    0

    Hi Moran,

    Have you doublechecked that you have an element with id="miniCart" and an element inside that with the id="miniCartTotalQuantity"

    Otherwise it won't work.

    Maybe try using your browsers developer tools to debug the javascript and check the values and what happens.

    /Rune

  • Moran 285 posts 934 karma points
    Feb 11, 2014 @ 12:39
    Moran
    0

    Hi rune

    This is my html code

    <div id="miniCart" class="@cssClass">
        <a href="/">
            <span class="cart-heading">
                @Dictionary["YourCart"]
            </span>
            <span class="cart-count" id="miniCartTotalQuantity">
                @totalQuantity.ToString("0.####")
            </span>
        </a>
    </div>
  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 11, 2014 @ 12:54
    Rune Grønkjær
    0

    That looks fine. What is the value of totalQuantity?

    /Rune

  • Moran 285 posts 934 karma points
    Feb 11, 2014 @ 14:06
    Moran
    0

    It always show "0" even if the parametr "order" has value like I attached to the post above.

  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 11, 2014 @ 15:07
    Rune Grønkjær
    0

    AAAH. I see it now. Your order has no order lines: orderLines:Array[0]

    That's why :)

    /Rune

  • Moran 285 posts 934 karma points
    Feb 11, 2014 @ 16:10
    Moran
    0

    How do I add order lines? did I forgot to include a script or call some function?

     

  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 11, 2014 @ 16:57
    Rune Grønkjær
    0

    Don't you have a product page, with some add to cart functionality?

    /Rune

  • Moran 285 posts 934 karma points
    Feb 11, 2014 @ 17:14
    Moran
    0

    I only have a "featured products" widget in the home page, this is where I added the "add to cart" functionality.

  • Moran 285 posts 934 karma points
    Feb 12, 2014 @ 07:12
    Moran
    0

    Rune

    I think I am missing this two lines: 

    <div class="@cssClass" refreshwithtemplate="product/list-view.cshtml" productid="@product.Id" itemprop="itemListElement" itemscope="" itemtype="http://schema.org/Product">
    <form action="/base/TC/FormPost.aspx" method="post" class="ajaxForm">

    Does those line have any effect on my issue? do I really need all these attributes in the div class? refreshwithtemplate, productid, itemprop, itemscope, itemtype

  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 12, 2014 @ 09:25
    Rune Grønkjær
    100

    The line with the form tag is the most important line. That's the one that makes the add to cart possible. Heres a link to how that works:
    http://documentation.teacommerce.net/html-api/order-line/addorupdateorderline/

    If you want to do an add to cart with only javascript you can have a look at this page:
    http://documentation.teacommerce.net/javascript-api/order-lines/addorupdateorderline/

    The div is just for styling, and if you have variants  you can use the refreshwithtemplate attribute to change the content of the div, when changing the variant. To see how that works, you need to look at our starter kit.

    /Rune

  • Moran 285 posts 934 karma points
    Feb 12, 2014 @ 09:47
    Moran
    0

    Thanks

    Will this work also with the MVC scheme? I had some issues with form tags before :) 

  • Rune Grønkjær 1372 posts 3103 karma points
    Feb 13, 2014 @ 09:23
    Rune Grønkjær
    0

    Yes. That is just simple forms and javascript not bound to a server side tech. So no problems in that :)

    /Rune

  • Moran 285 posts 934 karma points
    Feb 15, 2014 @ 20:02
    Moran
    0

    Ok thanks

    I will take a look at that.

  • Moran 285 posts 934 karma points
    Feb 16, 2014 @ 19:02
    Moran
    0

    Thanks for the help :)

     

Please Sign in or register to post replies

Write your reply to:

Draft