Joe Wasson [MSFT]
Guest
|
Posted:
Fri Sep 16, 2005 12:51 am Post subject:
RE: Cannot get ShippingMethod name, ID only. |
|
|
I think you've ended up dancing around the right answer. If you're trying
to have only one shipping method then you only need "cart.ShippingMethodID
= optShip.Value;", setting each line item shouldn't be necessary (I'm not
entirely certain, but I've been told by another developer this is the case).
The first code you display has a bug where you are trying to get the
ShippingMethodName by using the ShippingMethod Name. Also, the Shipments
array is not built until you run the pipeline, so that explains why the
first and second code blocks don't really work.
One would think that the third code block would work, but due to the way
ShippingMethodName is implemented you could be running into two problems:
1) if there is more than one shipping method or shipping address assigned
to the basket and/or lineitems then this property will return null, as
there is no single shipping method. 2) There appears to be a bug in the
implementation where the Shipping Method ID is used for the
ShippingMethodName.
My recommendation is to use "cart.ShippingMethodID = optShip.Value;" to set
the shipping method and use
"TransactionContext.Current.GetShippingMethodName(CommerceContext.OrderSyste
m.GetBasket(currUserGuid)["shipping_method_id"])" to get the shipping
method name.
I hope this helps. Let me know if you have any questions or my answer
didn't help.
-joe
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Tue, 13 Sep 2005 17:24:49 +0400
Subject: Cannot get ShippingMethod name, ID only.
From: Ripos <ripos@ripsoft.net>
We use CS2002+SP3+FP1.
We build out site on top of the Starter Site.
This is a method of saving a Shippment:
Cart cart = TransactionContext.Current.Cart;
foreach(LineItem item in cart.LineItems) {
cart.SetShippingMethod(item.Index, optShip.Value);
}
cart.ShippingMethodID = optShip.Value;
cart.Save();
This is a method of getting a current Shippment:
Cart cart = TransactionContext.Current.Cart;
lblShipping.Text = TransactionContext.Current.GetShippingMethodName (
((Shipment) Cart.Shipments[0]). ShippingMethodName);
Also I've tried:
Cart cart = TransactionContext.Current.Cart;
lblShipping.Text = ((Shipment)cart.Shipments[0]).ShippingMethodName;
and Cart cart = TransactionContext.Current.Cart;
lblShipping.Text = Cart.ShippingMethodName;
All of them say that MethodName is null, and for some of them even
MethodID is null too.
May be I do smthing wrong? |
|