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?
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();
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.
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.
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?
Sure.
XSLT or Razor?
Both would be useful please as I am working on on one of each at the moment :)
Thanks Søren
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:
For Razor:
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.
Actually now that I think about it there is a simpler way. In Razor at least:
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.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.