Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Tony Kiernan 278 posts 341 karma points
    Jul 25, 2011 @ 15:19
    Tony Kiernan
    0

    Custom Shipping Method: Show value in shipping methods

    I've built a simple custom shipping method. When I list the methods, I'd like to show how much it is calcualted to next to it.  Can anyone advise on how could be done?

    ALSO: In the meantime, I'm trying to output the Description to explain the calculation.  Using:

    @myShippingMethod.GetDescription("EN-US").Description

    This is returning nothing.  Am I calling this wrong?

  • Simon Osborne 108 posts 150 karma points
    Aug 02, 2011 @ 23:35
    Simon Osborne
    0

    I'm trying to do exaclty the same - help would be appreciated

  • Zac 223 posts 575 karma points
    Aug 12, 2011 @ 12:29
    Zac
    0

    I did this by creating an XSLT Extension in my App_Code, with a method that I can call from XSLT:

    [XsltExtension]
    public class Business
    {
        public Business() { } //required for the xslt extention
    
        public static decimal GetShippingCost(int shipmentMethodId)
        {
            Basket b = SiteContext.Current.OrderContext.GetBasket();
            OrderAddress shippingAddress = b.PurchaseOrder.OrderAddresses.ToList().Last();
            return GetShippingCost(shipmentMethodId, b.PurchaseOrder.OrderLines, shippingAddress);
        }
    ...

    public static decimal GetShippingCost(int shipmentMethodId, ICollection<OrderLine> orderLines, OrderAddress orderAddress)
    {
    //logic to calculate shipping cost. Call this method from your custom shipping method, e.g.
    //decimal shippingPrice = Business.GetShippingCost(shipment.ShippingMethodId, shipment.OrderLines, shipment.ShipmentAddress);
    //return new Money(shippingPrice, shipment.OrderLines.First().PurchaseOrder.BillingCurrency);
    }

    Then in your XSLT:

    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    xmlns:CommerceLibrary="urn:CommerceLibrary"
    xmlns:Business="urn:Business"
    exclude-result-prefixes="msxml umbraco.library CommerceLibrary">

    ...

    <xsl:template match="/">
    <form id="mainForm" method="post" action="...">
    <xsl:apply-templates select="CommerceLibrary:GetShippingMethods('Shipment')/shippingMethods/shippingMethod" />
    <input type="submit" value="Proceed to Payment" class="primary-action"></input>
    </form>
    </xsl:template>

    ...

    <xsl:template match="shippingMethod" >
    <input type="radio" name="shippingMethodInput" value="{@shippingMethodId}">
    <xsl:if test="@shippingMethodId = $shipment/@shippingMethodId">
    <xsl:attribute name="checked">checked</xsl:attribute>
    </xsl:if>
    <label for="{@shippingMethodId}">
    <xsl:variable name="shippingCost" select="Business:GetShippingCost(@shippingMethodId)"/>
    <xsl:value-of select="@displayName"/> - <xsl:value-of select="$shippingCost"/>
    </label>
    </input>
    </xsl:template>


    </xsl:stylesheet>

    Hope that makes sense.

    Zac

Please Sign in or register to post replies

Write your reply to:

Draft