Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Keith Donnell 82 posts 187 karma points
    May 05, 2015 @ 17:26
    Keith Donnell
    0

    How to get to an IInvoice record, given an IShipment

    How do I retrieve the related invoice, given a shipment instance?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    May 05, 2015 @ 19:09
    Rusty Swayne
    1

    Hey Keith - this one is something on my to do to make easier. At the moment, the only way to do it is to walk up the graph.

    If you are running this in a controller or something that references to Merchello.Web:

    // assuming you have the IShipment
    var shipment = [from somewhere];    
    
    var merchello = new MerchelloHelper();
    
    // Every line item in the shipment will have a "ContainerKey" which, in this case is the OrderKey
    var item = shipment.Items.FirstOrDefault(x => !x.ContainerKey.Equals(Guid.Empty));
    
    var order = merchello.Query.Order.GetByKey(item.ContainerKey);
    
    var invoice = merchello.Query.Invoice.GetByKey(order.InvoiceKey);
    

    If you are doing something in a console app or test, you will need to do the same thing but with the respective services.

    var order = MerchelloContext.Current.Services.OrderService.GetByKey(item.ContainerKey);
    
    var invoice = ...
    
Please Sign in or register to post replies

Write your reply to:

Draft