Copied to clipboard

Flag this post as spam?

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


  • Jesper Lauridsen 25 posts 84 karma points
    Nov 29, 2012 @ 12:01
    Jesper Lauridsen
    0

    Adding a "hidden" orderline

    Hi 

    I wan't to add an extra "hidden" orderline to my orders in order to give a total discount for the order.

    This orderline should of course not be counted as an tiem, and should not be shown as a part of the basket.
    I have created a "Product"-node for the product, which is hidden.

    Will I need to change the methods for counting the number of, and showing the items ind the basket - or can I do it differently?

     

    Regards
    Jesper Lauridsen

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 29, 2012 @ 12:36
    Rune Grønkjær
    0

    Hi Jesper,

    What you are trying to do has everything to do with how you choose to display your order lines. Just don't show your special discount orderline or show it somewhere of your own choice.

    So it's all about filtering your order lines in two piles.

    /Rune

  • Jesper Lauridsen 25 posts 84 karma points
    Nov 29, 2012 @ 13:06
    Jesper Lauridsen
    0

    Hi Rune

    Yes, that part is fairly easy to get around.

    Today my website shows the number of items in the basket with this
    <xsl:value-of select="$order/@totalQuantity" />

    Can I modify the value of this property in .NET for instance (when adding the orderlines)?

    Or perhsps I should simply add a new property on the order-object, and refer to that?

    Any suggestions?

    Regards
    Jesper Lauridsen 

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 29, 2012 @ 13:20
    Rune Grønkjær
    0

    Or you could just sum up the ordinary orderlines' quantities. What's important is only that the price is calculated correctly, everything else can be manipulated in you xslt/razor

    /Rune

  • Jesper Lauridsen 25 posts 84 karma points
    Dec 04, 2012 @ 09:44
    Jesper Lauridsen
    0

    After being sidetracked for a couple of days, I am still struggling with this issue.

    I cannot get my "mini"-cart to show the correct number of items in the cart.
    I have created a new property on the order 'RealItems', which I update in the AddOrderline-event, and I have changed the .XLST-file for the 'mini'-cart to refer to that property, but it keeps showing me the wrong number of items (TotalQuantity).
    Today I spotted the jQuery code which also seems to update the mini-cart (changing class'es and so on) and changed it like this;

    function updateMiniCartUI(miniCartorder{
      miniCart.find("#miniCartTotalPrice").text(order.TotalPriceWithoutFeesFormatted);
    /*  miniCart.find("#miniCartTotalQuantity").text(order.TotalQuantity); */
      miniCart.find("#miniCartTotalQuantity").text(order.attr('RealItems'));
    }

    But nothing seems to work.

    What am I missing?

    Regards
      Jesper Lauridsen 

  • Rune Grønkjær 1372 posts 3103 karma points
    Dec 04, 2012 @ 10:28
    Rune Grønkjær
    0

    Hi Jesper,

    Your order.attr('RealItems') won't work. The order properties is placed on the order as an array. You can get them by typing order.Properties.

    To get them you will need to find the correct property using it's Alias. You might want to check your order object by getting it in your browser console:
    TeaCommerce.getOrder()

    Then you will be able to inspect your order object and figure out how to get your property.

    /Rune

  • Jesper Lauridsen 25 posts 84 karma points
    Dec 04, 2012 @ 10:50
    Jesper Lauridsen
    0

    Hi Rine

    Thank you for your quick reply.

    OK, but my above codechanges did not have any effect at all (no errors and still showing the value of 'TotalQuantity'), so I suspect that the value does not gome from the jQuery code anyway.
    But I cannot determine where the mini-cart is getting its amount value from (XLST-file, jQuery script).

    I know there are so many different implementations of the TeaCommerce-library and you do not know how ours are implemented (we got it from TeaSolutions), but I was thinking that someone would be able to point me in the right direction.

    As far as I can determine the following code should show the number of items but my changes does not have any effekt.
    (copied from webshop_cart_miniCart.xslt) 

            <div id="miniCartNotEmpty">
              <href="{$cartPageUrl}" id="miniCartViewCart">
                <span id="miniCartTotalQuantity">
    <!--              <xsl:value-of select="$order/@totalQuantity" />-->
                  <xsl:value-of select="$order/@RealItems" />
                </span>&nbsp;
                <span id="miniCartSingleItem">
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('mcfItem')"/>
                </span>
                <span id="miniCartMultipleItem">
                  <xsl:value-of select="umbraco.library:GetDictionaryItem('mcfItems')"/>
                </span>
              </a>
              <href="{$cartPageUrl}"><img src="/css/gfx/webshop/minicart_icon.png" /></a>
            </div>

    Why does this not work?
    Even if the '@RealItems'-property cannot be found, it should not show the @totalQuantiry value.

    I am getting older faster :)

    Regards
      Jesper Lauridsen 

  • Rune Grønkjær 1372 posts 3103 karma points
    Dec 04, 2012 @ 10:56
    Rune Grønkjær
    0

    The minicart xslt should be the one that displays the order quantity. If your above changes to the file does nothing you should double check that that is the xslt used on your website!

    The code <xsl:value-of select="$order/@RealItems" /> will not work as the order properties is placed under a properties node. If you want to see what your xml looks like use:
    <xsl:copy-of select="$order" />
    And then check your page's source code.

    /Rune

  • Jesper Lauridsen 25 posts 84 karma points
    Dec 04, 2012 @ 11:41
    Jesper Lauridsen
    0

    Hi Rune

    I have double-, triple- and quardrouble-checked the reference from our templates, through the Macro and down to the XSLT-file, an as far as I can see it is the correct XSLT-file.

    That is why I started looking elsewhere (JQuery).

    I have now contacted TeaSolutions, they should be able to point me in the right direction.

    Thank you for your effort.

    Regards
      Jesper Lauridsen 

  • Rune Grønkjær 1372 posts 3103 karma points
    Dec 04, 2012 @ 12:41
    Rune Grønkjær
    0

    Cool that it's the right xslt file.

    A small explanation on the javascript and xslt's:

    - The xslt will render the first view of the mini cart.
    - The javascript will update the numbers whenever the order is changed by the javascript.

    If the xslt does not show you what you want you will need to debug it. Find out if you can change something and then work you way into your problem. Again, the <xsl:copy-of select="$order" /> is brilliant for getting an overview of what xml you have.

    /Rune

  • Jesper Lauridsen 25 posts 84 karma points
    Dec 04, 2012 @ 17:21
    Jesper Lauridsen
    0

    Hi (again)

    I thourght I had it working for a moment there - but now it no longer works.

    I have extended the TeaCommerce .NET api with the follwing code;

            void WebshopEvents_OrderLineRemoved(Data.Order order, Data.OrderLine orderline)
    {
    decimal iTotalQuantity = 0;
    foreach (TeaCommerce.Data.OrderLine line in order.OrderLines)
    {
                    if (line.NodeId != 18889)
                    {
                        iTotalQuantity += line.Quantity;
                    }
            }
           OrderProperty realItems = order.Properties.Single(p => p.Alias.Equals("RealItems"));
           if (realItems != null)
                   realItems.Value = iTotalQuantity.ToString();
                else
                    order.AddProperty(new OrderProperty("RealItems", iTotalQuantity.ToString()));
    order.Save();
            }

            void WebshopEvents_OrderCreated(TeaCommerce.Data.Order order)
            {
                // Add the DiscountAdded property
                order.AddProperty(new OrderProperty("DiscountAdded", "no"));
                order.AddProperty(new OrderProperty("RealItems", "0"));
                order.Save();
            }

    void WebshopEvents_OrderLineAdded(TeaCommerce.Data.Order order, TeaCommerce.Data.OrderLine orderLine)
            {
                umbraco.cms.businesslogic.member.Member currentUser = umbraco.cms.businesslogic.member.Member.GetCurrentMember();
                if (currentUser != null)
                {
                    String discount = order.GetPropertyValue("DiscountAdded");
                    if (discount != "yes")
                    {
                        SystemFactory.ForceMessageToDB("Kunde logget ind", "TeaCommerceExtension->OrderLineAdded");
                        Customer cust = Customer.GetCustomer(new Guid(currentUser.LoginName));
                        if (cust != null)
                        {
                            OrderProperty discProp = order.Properties.Single(p => p.Alias.Equals("DiscountAdded"));
                            discProp.Value = "yes";
                            int monthSpan = SystemFactory.GetMonthSpan(DateTime.FromOADate(cust.SignOnTime), DateTime.Now);
                            TeaCommerce.Data.OrderLine discountLine = order.CreateOrderLine(18889, 1);
                            discountLine.UnitPrice = orderLine.UnitPrice * (decimal)(7.5 / 100);
                            order.Save();
                        }
                    }
                }
                decimal iTotalQuantity = 0;
    //            iTotalQuantity = decimal.Parse(order.GetPropertyValue("RealItems"));
                OrderProperty realItems = order.Properties.Single(p => p.Alias.Equals("RealItems"));
                 foreach (TeaCommerce.Data.OrderLine line in order.OrderLines)
                {
                    if (line.NodeId != 18889)
                    {
                        iTotalQuantity += line.Quantity;
                    }
                }
                if (realItems == null)
                {
                    order.AddProperty(new OrderProperty("RealItems", iTotalQuantity.ToString()));
                }
                else
                {
                    realItems.Value = iTotalQuantity.ToString();
                }
                order.Save();
                SystemFactory.ForceMessageToDB(String.Format("Vi har {0} rigtige varer i kurven", iTotalQuantity), "TeaCommerceExtension->AddOrderline");
            }

    In the XSLT-file (webshop_cart_miniCart.xslt) I have the following code to get the number of items in the cart;
        <xsl:variable name="totalQuantity">
          <xsl:choose>
            <xsl:when test="$order != ''">
              <xsl:value-of select="$order/properties/RealItems" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>0</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
    and in the jQuery library I have modified the "updateMiniCartUI" like this;
    function updateMiniCartUI(miniCartorder{
      miniCart.find("#miniCartTotalPrice").text(order.TotalPriceWithoutFeesFormatted);
    /*  miniCart.find("#miniCartTotalQuantity").text(order.TotalQuantity); */
      miniCart.find("#miniCartTotalQuantity").text(order.properties.RealItems);
    }
    My debugcode (SystemFactory) tells me that "Realitems" is 1 (if I have added one product), but my basket tells me, that there are two products in the basket.
    I am obviously missing something, but I cannot figure out what.
    Regards
      Jesper Lauridsen 
  • Rune Grønkjær 1372 posts 3103 karma points
    Dec 05, 2012 @ 08:49
    Rune Grønkjær
    0

    Wauw, that's a lot of code. I really can't tell you what is wrong from that. Other than in your javascript you cannot get the property like this order.properties.RealItems (In Tea Commerce 2.0 you will be able to do it like that). Now you will have to loop through the properties, check their Alias and then you have the result.

    If your C# code does not do as you intend, you might want to debug it on your local IIS. Or you can use the Umbraco log like this Log.Add(...) which will log to the database.

    /Rune

Please Sign in or register to post replies

Write your reply to:

Draft