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.

  • Neo 22 posts 42 karma points
    Feb 23, 2011 @ 12:40
    Neo
    0

    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

  • Søren Spelling Lund 1797 posts 2786 karma points
    Feb 24, 2011 @ 11:15
    Søren Spelling Lund
    0

    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.

  • Neo 22 posts 42 karma points
    Feb 24, 2011 @ 11:44
    Neo
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft