I need to make a list of popular (most buy) products. I create a view which displays Ordered Products and use aggregation to sort the products based on number that the products has been sell in past. I have there available all node basic infomations, product options but I miss any custom fields (like image field).

I try to use any possible relations that is available but without success. I think there should be one relation that make relation between product and node fields.

Thanks for any advice or solution.

Files: 
CommentFileSizeAuthor
#23 1565484-views-product-custom-fields-23.patch1.86 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,459 pass(es).
[ View ]
#20 1565484-views-product-custom-fields.patch2.23 KBlongwave
PASSED: [[SimpleTest]]: [MySQL] 2,455 pass(es).
[ View ]
#15 custom_fields_not_available-1565484-15.patch2.24 KBg089h515r806
PASSED: [[SimpleTest]]: [MySQL] 2,105 pass(es).
[ View ]
#5 custom_fields_not_available-1565484-5.patch1.86 KBg089h515r806
PASSED: [[SimpleTest]]: [MySQL] 2,103 pass(es).
[ View ]

Comments

Title:Access product content fields in Ordered Products viewProduct custom fields not available under Orders type views
Category:feature» bug

Updated the title to better reflect the issue, and marking as bug.

Custom content type fields defined under Product content type or other product classes are not available within the Orders type views. This should be available as part of "Order: Products" relationship.

Title:Product custom fields not available under Orders type viewsProduct custom fields not available under Orders/Ordered Products type views

Should be Orders/Ordered Products type views.

This is SQL from an Order type views with Order: Products relationship defined. Fields in volunteer_ticket content type are not available for views field/filter. What could be the problem?

SELECT uc_orders.order_id AS order_id, uc_order_products_uc_orders__uc_products.model AS uc_order_products_uc_orders__uc_products_model, uc_orders.order_id AS uc_orders_order_id
FROM
{uc_orders} uc_orders
LEFT JOIN {uc_order_products} uc_order_products_uc_orders ON uc_orders.order_id = uc_order_products_uc_orders.order_id
LEFT JOIN {node} uc_order_products_uc_orders__node ON uc_order_products_uc_orders.nid = uc_order_products_uc_orders__node.nid
LEFT JOIN {uc_products} uc_order_products_uc_orders__uc_products ON uc_order_products_uc_orders.nid = uc_order_products_uc_orders__uc_products.nid
WHERE (( (uc_order_products_uc_orders__node.type IN  ('volunteer_ticket')) ))
ORDER BY uc_orders_order_id ASC
LIMIT 10 OFFSET 0

Is there any solutions?? anyone?? i want my imagefields/filefields to ordered products - page.

Status:Active» Needs review
StatusFileSize
new1.86 KB
PASSED: [[SimpleTest]]: [MySQL] 2,103 pass(es).
[ View ]

Here is a patch which solve this issue on our project.

Status:Needs review» Reviewed & tested by the community

This patch definitely shoul be commited. I made a litle module that is using hook_views_data_alter to implement this relationship. I think there is a problem with this patch also:
For anonymous users I get:

Notice: Undefined index: table in _node_query_node_access_alter() (line 3229 of /data/drupal/beta/distr/7/modules/node/node.module).
Notice: Undefined index: table in _node_query_node_access_alter() (line 3229 of /data/drupal/beta/distr/7/modules/node/node.module).
Notice: Undefined index: table in _node_query_node_access_alter() (line 3229 of /data/drupal/beta/distr/7/modules/node/node.module).
Notice: Undefined index: table in _node_query_node_access_alter() (line 3229 of /data/drupal/beta/distr/7/modules/node/node.module).

I'll dig in a little and see what causing the problem.

Status:Reviewed & tested by the community» Needs review

Status:Needs review» Reviewed & tested by the community

The patch is great, the problem was: #1785434: Ubercart is not implementing the foreign keys setting correctly in schema

The implementation of 'nid' field, according to node.views.inc from views module should be like this:

<?php
$data
['uc_order_products']['nid'] = array(
       
'title' => t('Nid'),
       
'help' => t('The nid of the ordered product. If you need more fields than the nid: Node relationship'),
       
'relationship' => array(
           
'title' => t('Node'),
           
'help' => t('Relate product to node.'),
           
'handler' => 'views_handler_relationship',
           
'base' => 'node',
           
'field' => 'nid',
           
'label' => t('node'),
        ),
       
// Information for displaying the nid
       
'field' => array(
         
'handler' => 'views_handler_field_node',
         
'click sortable' => TRUE,
        ),
       
// Information for accepting a nid as an argument
       
'argument' => array(
         
'handler' => 'views_handler_argument_node_nid',
         
'name field' => 'title', // the field to display in the summary.
         
'numeric' => TRUE,
         
'validate type' => 'nid',
        ),
       
// Information for accepting a nid as a filter
       
'filter' => array(
         
'handler' => 'views_handler_filter_numeric',
        ),
       
// Information for sorting on a nid.
       
'sort' => array(
         
'handler' => 'views_handler_sort',
        ),
    );
?>

Also, I think that the product node should be implemented only as a relationship and $data['node']['table']['join']['uc_order_products'] should not be defined in uc_order.views.inc.

Status:Reviewed & tested by the community» Needs work

I agree that "$data['node']['table']['join']['uc_order_products']" should be removed. It is useless.
But it is added by module mainterner.

The code was copied from Views Core(views\modules\comment.views.inc) :

  $data['comment']['nid'] = array(
    'title' => t('Nid'),
    'help' => t('The node ID to which the comment is a reply to.'),
    'relationship' => array(
      'title' => t('Content'),
      'help' => t('The content to which the comment is a reply to.'),
      'base' => 'node',
      'base field' => 'nid',
      'handler' => 'views_handler_relationship',
      'label' => t('Content'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'field' => array(
      'handler' => 'views_handler_field_numeric',
    ),
  );
  $data['comment']['uid'] = array(
    'title' => t('Author uid'),
    'help' => t('If you need more fields than the uid add the comment: author relationship'),
    'relationship' => array(
      'title' => t('Author'),
      'help' => t("The User ID of the comment's author."),
      'base' => 'users',
      'base field' => 'uid',
      'handler' => 'views_handler_relationship',
      'label' => t('author'),
    ),
    'filter' => array(
      'handler' => 'views_handler_filter_numeric',
    ),
    'argument' => array(
      'handler' => 'views_handler_argument_numeric',
    ),
    'field' => array(
      'handler' => 'views_handler_field_user',
    ),
  );

I only made a little change to fit ubercart's requirement.

I do not think that it is nessesary to add such code:

'click sortable' => TRUE,
and
'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
'validate type' => 'nid',

Maybe 'views_handler_filter_numeric' already include "'click sortable' => TRUE,".
I mean that if the handler is 'views_handler_filter_numeric' , the the default value of 'click sortable' is TRUE.

If you still think that it is nessesary to add more info to it, you could submit a patch to Views Core, if the patch accepted by views core.
I could copy it again ^_^

My suggestion was copied from Node fields definition in Views Core so is no need to patch views only to modify this patch. Take a look in views/modules/node.views.inc for nid field:

<?php
...
 
// nid
 
$data['node']['nid'] = array(
   
'title' => t('Nid'),
   
'help' => t('The node ID.'), // The help that appears on the UI,
    // Information for displaying the nid
   
'field' => array(
     
'handler' => 'views_handler_field_node',
     
'click sortable' => TRUE,
    ),
   
// Information for accepting a nid as an argument
   
'argument' => array(
     
'handler' => 'views_handler_argument_node_nid',
     
'name field' => 'title', // the field to display in the summary.
     
'numeric' => TRUE,
     
'validate type' => 'nid',
    ),
   
// Information for accepting a nid as a filter
   
'filter' => array(
     
'handler' => 'views_handler_filter_numeric',
    ),
   
// Information for sorting on a nid.
   
'sort' => array(
     
'handler' => 'views_handler_sort',
    ),
  );
...
?>

If you think $data['node']['table']['join']['uc_order_products'] should be removed, please post a patch. Quoting code is fine for discussion, but it is much easier to review and be sure of your full set of changes if you post patch files.

$data['node']['nid'] is diferent with $data['comment']['nid'] .
$data['node']['nid'] does not have 'relationship', nid is a normal property field of node.

$data['uc_order_products']['nid'] is more similar with $data['comment']['nid'].
At here $data['comment']['nid'] is a good example to follow.

We do not need to duplaicate the defination of $data['node']['nid'] at ['uc_order_products']['nid'] , it already defined in $data['node']['nid']. At ['uc_order_products']['nid'] and $data['comment']['nid'], we reference the defination of $data['node']['nid'] by using 'relationship'.

StatusFileSize
new2.24 KB
PASSED: [[SimpleTest]]: [MySQL] 2,105 pass(es).
[ View ]

Latest patch. works very well.

I have removed

$data['node']['table']['join']['uc_order_products']
$data['uc_products']['table']['join']['uc_order_products']
$data['uc_orders']['table']['join']['uc_order_products']

['table']['join'] could only pull a few fields, not all fields of node. Maybe only the fields from {node} table.
By using 'relationship', we could pull all node fields after we add a "Ordered product: Node" relationship.

If user already using fields provided by " $data['node']['table']['join']['uc_order_products'] " and "$data['uc_orders']['table']['join']['uc_order_products']". They will get a PDO error after apply "custom_fields_not_available-1565484-15.patch".
The correction is very simple:
add the relationship, and edit the fields again, the error will disappear.

Status:Needs work» Needs review

change status to needs review.

Status:Needs review» Needs work

The last submitted patch, custom_fields_not_available-1565484-15.patch, failed testing.

Status:Needs work» Needs review

Version:7.x-3.1» 7.x-3.x-dev
StatusFileSize
new2.23 KB
PASSED: [[SimpleTest]]: [MySQL] 2,455 pass(es).
[ View ]

This is the same as #15 except with some minor changes to the text.

This works well for me, but I also do not want to break existing Views if possible. Can we include both the automatic joins and the manual relationships?

Yes, we do not need to remove the code of "['table']['join']" in Drupal 7. Include both of them still works very well.
It will be very unfriendly if user get a PDO error after they update to latest code.

Just add a comment to remind that the code of "['table']['join']" will be removed in Drupal 8. I think this will be a little better.

Status:Needs review» Needs work

Patch needs work based on #21

Status:Needs work» Needs review
StatusFileSize
new1.86 KB
PASSED: [[SimpleTest]]: [MySQL] 2,459 pass(es).
[ View ]

@g089h515r806: If you can confirm this works for you with no issues, I think this is ready to be committed.

Status:Needs review» Needs work

The last submitted patch, 1565484-views-product-custom-fields-23.patch, failed testing.

The last submitted patch, 1565484-views-product-custom-fields-23.patch, failed testing.

Status:Needs work» Needs review

It works very well.

Status:Needs review» Fixed

Committed #23, thank you for working on this.

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.