The _commerce_pdm_get_nodes_referencing function isn't specifying that the entity to pull references from is actually of the type "node". If you add a product reference field to an entity other than "node", this results in a variety of odd behaviors from the UI, none of which are pleasant. The attached git patch resolves this by adding the "node" requirement to the entity query.

An example causing the undesired behavior is if you want to have a "related products" reference field on your products entity. Add the field and add products to the reference... you'll see it start to try and show nodes that match the specified entity ID of your referenced products or if there is no matching node entity ID, it'll return a notice and error out.

CommentFileSizeAuthor
node-entity-query-fix.patch638 bytesjaymallison

Comments

joachim’s picture

Status: Needs review » Needs work

Good catch -- just spotted this myself and was looking for a bug report.

Patch looks good, just one thing:

+++ b/commerce_pdm.module
@@ -634,9 +634,10 @@ function _commerce_pdm_get_nodes_referencing($product_id) {
+        ':etype' => 'node',

There's no need to put this in with a placeholder, it can just be hardcoded into the query.

netsensei’s picture

Status: Needs work » Postponed

I don't think we should hard code the entity type here.

In theory, any entity type could be a product display. Convention dictates that product displays are node entities, but there are no arguments to referencing products to terms, profiles,... An entity can be defined as a product display once a product reference field has been assigned to it.

A use case could be the referencing of products to the file entities (http://drupal.org/project/file_entity) This could be potentially used in a structured way to sell locked down files.

Rather, I think PDM should be entity type agnostic as far as product displays goes. It's not a major blocker right now since product display nodes are by far the most common use case, but something to consider if we want to move along. So, I'm going to postpone this for now.

netsensei’s picture

Title: Commerce PDM shows references incorrectly from entities other than nodes » Commerce PDM should show all product display entities regardless of entity type
netsensei’s picture

Issue summary: View changes

added example issue case