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.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jun 11, 2012 @ 09:32
    Simon Dingley
    0

    Apply Default Shipping Fee Before Address Selection

    Is it possible for the checkout/cart to apply the default shipping charge before the user enters their address so that when they review their cart before checking out they can see the total including shipping? The site will only offer one shipping option or if over a certain amount the shipping is free if that makes any difference?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 18, 2012 @ 13:54
    Søren Spelling Lund
    0

    Sure.

    XSLT or Razor?

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jun 18, 2012 @ 13:56
    Simon Dingley
    0

    Both would be useful please as I am working on on one of each at the moment :)

    Thanks Søren

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 18, 2012 @ 14:20
    Søren Spelling Lund
    0

    For XSLT the idea is to provide a dummy address because the API requires it. For Razor on the other hand you can get away with less.

    Just remember to update the order with the shipping address once you have it.

    The following is not exactly production code, but should give you a starting point to work with:

    For XSLT:

    CommerceLibrary:EditOrderAddress("DummyAddress", "", ""...etc)
    <!-- 1 is the shipping method you want to use as a default -->
    CommerceLibary:CreateShipment(1, "DummyAddress", true())
    CommerceLibrary:ExecuteBasketPipeline()

    For Razor:

    var myShippingMethod = ShippingMethod.All().Single(x => x.Name == "My Default Shipping Method");
    var purchaseOrder = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
    var shipment = new Shipment { ShippingMethod = myShippingMethod };
    purchaseOrder.OrderLines.ForEach(shipment.AddOrderLine(x));
    purchaseOrder.AddShipment(shipment);
    Library.ExecuteBasketPipeline();

     

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Jun 18, 2012 @ 14:35
    Simon Dingley
    0

    Will this be the case in v3? It feels like a bit of a hack taking this approach, like you say it is not exactly production code but I can't see any alternative other than writing an extension to force it which may have knock on effects elsewhere.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 18, 2012 @ 15:05
    Søren Spelling Lund
    0

    Actually now that I think about it there is a simpler way. In Razor at least:

    var shippingMethod = ShippingMethod.All().Single(x => x.Name == "My Default Shipping Method");
    var shipment = new Shipment { ShippingMethod = shippingMethod };
    purchaseOrder.OrderLines.ForEach(x => shipment.AddOrderLine(x));

    Money shippingPrice = shippingMethod.GetShippingMethodService().CalculateShippingPrice(shipment);

    This doesn't actually affect the order at all. Just gives you the result you want. From there you could either add it to the order or let the customer pick something else to add.

Please Sign in or register to post replies

Write your reply to:

Draft