November Happy Hour will be moved to Thursday December 5th.

Is there *any* relation between Cart and Purchase order?

Vote:
 

When a user comes back from the payment provider (external), all I have is an order ID. I can decide what this order ID is. Before the user returns, however, there's a server-to-server-call done from the payment service which runs the entire CreatePurchaseOrder-workflow (which deletes your cart and converts it into a PO).

So there I sit, with some sort of ID to an item that no longer exists. And I can't seem to find any relations between the old cart and the new PurchaseOrder. The user is anonymous, so I can't find that user's stuff either.

I tried adding a "CartReference" meta field to the PurchaseOrder, which worked fine - but the OrderContext.Current.FindPurchaseOrders(parameters, options) would not let me search in that new column ("Invalid column").

I guess I can say OrderContext.Current.FindActiveOrders() and just search from code, but that seems like a super clumsy step if there are a lot of orders.

This has to be a common problem - and if there's no easy way of finding this relation, that's a serious flaw in the API the way I see it. 

#90032
Sep 01, 2014 13:01
Vote:
 

Ok, this is in fact possible by overriding the Order number ( http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce/75/Orders/Changing-order-number-sequence/ ), and then searching like so:

public PurchaseOrder GetActivePurchaseOrderByCartId(int cartOrderGroupId)
        {
            var parameters = new OrderSearchParameters
            {
                SqlMetaWhereClause = string.Format("TrackingNumber = '{0}'", CreateOrderNumber(cartOrderGroupId))
            };
            var options = new OrderSearchOptions
            {
                Classes = new StringCollection { "PurchaseOrder" },
                RecordsToRetrieve = 1
            };

            var findPurchaseOrders = OrderContext.Current.FindPurchaseOrders(parameters, options);
            return findPurchaseOrders.FirstOrDefault();
        }

Still a horrendous API to work with, so I'm hoping this gets fixed ( http://world.episerver.com/Forum/Developer-forum/Feature-requests/Thread-Container/2014/8/Simplify-APIs-to-handle-carts-OrderGroups-OrderForms-etc/ ).

#90060
Sep 01, 2014 14:51
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.