There is a custom propery called ShippingWeight attached to every product. How can I access that value in custom Shipping Service? This is code that I am using. I getting object reference error. Can anyone please help me on this?
public Money CalculateShippingPrice(Shipment shipment)
{
decimal shippingWeight = 0;
foreach (OrderLine orderline in shipment.OrderLines)
There are two kinds of custom properties you can work with:
1) Properties added to product definitions
2) Dynamic order properties which are assigned either to the order or individual order lines
To set a dynamic order property you use CommerceLibrary:SetOrderProperty from XSLT or in .NET new up an OrderProperty object and set the relevant reference to order and order lines.
Your NullReferences exception is probably due to the order property not being set in the first place.
Alternatively you can load up the product based on SKU and lookup the shipping weight property directly on that.
get product definition from ShippingService
Hi All,
There is a custom propery called ShippingWeight attached to every product. How can I access that value in custom Shipping Service? This is code that I am using. I getting object reference error. Can anyone please help me on this?
public Money CalculateShippingPrice(Shipment shipment)
{
decimal shippingWeight = 0;
foreach (OrderLine orderline in shipment.OrderLines)
{
shippingWeight = Convert.ToDecimal(orderline.OrderProperties.SingleOrDefault(x => x.Key == "ShippingWeight").Value);
/ // Getting error in the above line
}
}
Neo
Hi Neo,
There are two kinds of custom properties you can work with:
1) Properties added to product definitions
2) Dynamic order properties which are assigned either to the order or individual order lines
To set a dynamic order property you use CommerceLibrary:SetOrderProperty from XSLT or in .NET new up an OrderProperty object and set the relevant reference to order and order lines.
Your NullReferences exception is probably due to the order property not being set in the first place.
Alternatively you can load up the product based on SKU and lookup the shipping weight property directly on that.
Thank you very much Soren for your reply.
The following code helps me to get the value and it was mentioned in one of your other post.
Product product = Product.All().Where(x => x.Sku == pSku && x.ParentProductId == null).Single();
var ShippingWeightProperty = product["ShippingWeight"];
As you said the order property is not set in the first place... :-)
Neo.
is working on a reply...