Forum

The forum is a free service supported by community members. Please consider opening a support ticket if you need timely help.

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 27 Oct 2010 03:10 PM by  rob tracy
Shipping calculation
 4 Replies
Sort:
You are not authorized to post a reply.
Author Messages


New Member


Posts:
New Member


--
25 Oct 2010 07:44 PM
    Hi,
    I was looking to do 2 things for shipping, basically have a scale .. ie if total order is $0-$100 - Shipping is $10, if total order is 100.01 - 200 then shipping is $15, ifthe total order is over 200.01 then shipping is free. Plus then per item if it is a big item, charging freight, but I'm not sure where to impliment either since the one is not per item, but rather total order and the other is adding a freight charge for certain heavy items. Settign me in the right direction would be appreciated!

    -rob
    0


    Veteran Member


    Posts:2956
    Veteran Member


    --
    26 Oct 2010 12:24 PM

    Hi Rob,

    This is quite do-able. I'm pasting some sample code below. You may need to add additional logic to handle the large item but I hope this sets you in the right direction. So you can calculate against the subTotalAmount for your base charge. For the large item, you need to find them in the in/salesOrder/salesOrderDetails/ nodes. You can paste the code in your Rate field and use the Test Run tab to help you adjust. You can also change the Sample Input in the Test Run tab to simulate the different values.

    Here's a good XSL reference http://www.w3schools.com/xsl/

    <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:template match="/">
    <out>
    <shippingAmount>
    <xsl:variable name="baseShippingAmount">
    <xsl:choose>
    <xsl:when test="in/salesOrder/subTotalAmount >= 0 and in/salesOrder/subTotalAmount <= 100">
    10.00
    </xsl:when>
    <xsl:when test="in/salesOrder/subTotalAmount > 100 and in/salesOrder/subTotalAmount <= 200">
    15.00
    </xsl:when>
    <xsl:otherwise>
    0.00
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>


    <!-- Now add more logic to handle freight cost for large items below...
    You may have to find all large items in order detail items under in/salesOrder/salesOrderDetails/...
    -->
    <xsl:variable name="largeItemShippingAmount">
    0.00
    </xsl:variable>

    <!-- Generate the sum of the two charges. This is the final shipping calculation charge -->
    <xsl:value-of select="$baseShippingAmount + $largeItemShippingAmount" />

    </shippingAmount>
    </out>
    </xsl:template>
    </xsl:transform>

    0


    New Member


    Posts:
    New Member


    --
    26 Oct 2010 04:29 PM
    Good deal, that was the direction I was going, but the sample go it working in about 2 minutes! The only part I'm still stuck on is with the largeitemshipping, assigning cost per item I'm assuming I would add it as an extention per item or item varient? If so, how do I get to that info in the xslt? (I couldn't find a sample using it and have guessed wrong on my paths)
    0


    Veteran Member


    Posts:2956
    Veteran Member


    --
    26 Oct 2010 11:34 PM

    You can just keep adding more test logic to the same shipping rate calculation. For example, let's say in addition to the base rate, you want to charge an extra $3 surcharge for every large item over 10 grams, you can do so like this:

    <xsl:transform version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:template match="/">
    <out>
    <shippingAmount>
    <xsl:variable name="baseShippingAmount">
    <xsl:choose>
    <xsl:when test="in/salesOrder/subTotalAmount >= 0 and in/salesOrder/subTotalAmount <= 100">
    10.00
    </xsl:when>
    <xsl:when test="in/salesOrder/subTotalAmount > 100 and in/salesOrder/subTotalAmount <= 200">
    15.00
    </xsl:when>
    <xsl:otherwise>
    0.00
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>


    <!-- Count the number of large item order detail items -->
    <xsl:variable name="numLargeItems" select="count(in/salesOrder/salesOrderDetails/salesOrderDetail[string(weight) and weight >= 10])" />

    <!-- Generate the sum of the two charges. This is the final shipping calculation charge -->
    <xsl:value-of select="$baseShippingAmount + ($numLargeItems * 3.00)" />

    </shippingAmount>
    </out>
    </xsl:template>
    </xsl:transform>

    0


    New Member


    Posts:
    New Member


    --
    27 Oct 2010 03:10 PM
    I can certainly work with that for now, thank you!
    0
    You are not authorized to post a reply.