For my site, I wanted to be able to add products to the store, then have a copywriter add the product display nodes. Unfortunately there is no built in way to provide a list of commerce products ready to be referenced. This represents a hole in the workflow for adding products which can be addressed by a simple view.

Goals:

  • Provide a list of products that were not yet referenced by any product display node.
  • Provide a link to quickly add a product display referencing the product.

To accomplish this you will need:

  • Views 3.x
  • prepopulate module (7.x in dev) - enabled

Steps:

  1. Start by creating a new view. For "show" select "Commerce Product" and "type" your product type. Provide a page with the URL of your choice and display format set to "table" and leave everything else as default.
  2. Add the fields you would like to show. At the very least you should have "Commerce Product: Rendered ..." to show the title with a link to the product and the Product ID field (which will be used later - you can hide it from display if you want, but it will need to be in your view).
  3. Add a relationship for "Commerce Product: Node referencing products from [your_prudct_ref_field]."
  4. Add another field to your view "Content: Title" and set it to use the reference you just created.
  5. In the settings for this field, under "no results behavior" use the following code:<em>None.</em> <a href="/node/add/product?edit[your_reference_field][und]=[product_id]">Add Product</a>.
  6. Check to make sure you now see a listing of all your products in the preview. Products that are currently referenced will have a link to the product display, and products that are not referenced will have a link to add a display product that will use that product ID as a reference.
  7. Add a filter for Content:Product (your_reference_field). Set the operator to "is empty" and if you like, you can expose the filter and operator so your copywriter can switch between looking at products that are and are not referenced.

That's it! Save your view and visit the URL for the page view. You should see something similar to this (if you have orphaned products):

Only local images are allowed.http://img.skitch.com/20120316-8ac855kiqkhfdsujuuj26h344d.jpg

Clicking on "add product" in the right column should open up a new "add node" page for your display product type with the referenced product already filled in. If it didn't, check to make sure you entered all the field names correctly (yours will vary from what is in the example code) and followed all the instructions.