Hello, I have the following use case:
On certain Events, certain Products are sold. Each Event has 1+ references to a Product.
A logged in user can place an Order for an Event (Event ID passed through via Node Reference URL widget module.
An Order also has 1+ references to a Product - quantity combination (configured as a Field Collection, in order to be able to associate the relationship with a quantity value).
I need to limit the Product options in the Order create / edit screen so that only the Products available at the particular Event (that the Order refers or will refer to) are select-able, not all products in general.
I suppose I need a view to limit the nodes that can be referenced, with the Event ID as contextual filter. Ideally I would need to get all Products referenced (I assume this is the reverse reference relationship?) by the Event reference contained in the Order (which will be set when editing an order) otherwise from the Event ID in the URL (I assume when first creating an Order the Event reference is not yet stored, thus I must fall back to the Event ID that the Node Ref URL widget provides). Up until now I have been unable to make the view preview output anything for a known Event ID passed as a contextual filter...
Can someone indicate how I should go about doing this?
Thank you
Comments
Comment #1
marktheshark commentedTo clarify, essentially I need a view with the following logic (excuse the pseudo-code):
Note also that this References view will go into the Product ref field of the Product-Quantity Field Collection which is embedded in the Order node, so I'm not sure how to access the containing order from the contained collection.
Any help would be appreciated.
Comment #2
marktheshark commentedSolved it myself. Did away with the Field Collection by the way. In case anyone needs to implement something similar, here goes:
The contextual filter uses a default value which is PHP Code (in order to get the Event Nid from the currently processed Order node).
The code basically means: load the Order node being displayed, if it's an existing node, use the Event ID (field_order_event) that this Order references, otherwise if it's a new Order, use the same Event ID that the URL widget also provides in the GET request to prepopulate this field within the order.
As a result, only the Products sold at the particular Event are available as options for referencing within an Order.