Hello,

I have a View of type "Orders". I am trying to display the "Order Product ID" field value for each order product so that I can count those as distinct. I added the relationship "Order: Products", which makes the "Order Product ID" field available; however, that field is returning a value of "0" instead of the actual Order Product ID displayed in the database. How can I resolve this?

Here is an export of my view:

$view = new view();
$view->name = 'order_test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'uc_orders';
$view->human_name = 'Order Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Order: Products */
$handler->display->display_options['relationships']['products']['id'] = 'products';
$handler->display->display_options['relationships']['products']['table'] = 'uc_orders';
$handler->display->display_options['relationships']['products']['field'] = 'products';
/* Field: Order: Order ID */
$handler->display->display_options['fields']['order_id']['id'] = 'order_id';
$handler->display->display_options['fields']['order_id']['table'] = 'uc_orders';
$handler->display->display_options['fields']['order_id']['field'] = 'order_id';
/* Field: Ordered product: Order product ID */
$handler->display->display_options['fields']['order_product_id']['id'] = 'order_product_id';
$handler->display->display_options['fields']['order_product_id']['table'] = 'uc_order_products';
$handler->display->display_options['fields']['order_product_id']['field'] = 'order_product_id';
$handler->display->display_options['fields']['order_product_id']['relationship'] = 'products';
$handler->display->display_options['fields']['order_product_id']['link_to_entity'] = 0;

Comments

alokbhatt’s picture

Hello,

My assumption:
1) Created 2 products A (Product ID -1) and B (Product ID -2)
2) Order A product quantity 1 and B product quantity 2
3) Generated order ID 120

As per your requirement, the result should look like : Order ID: 120 and Order Product ID: 1, 2

Correct me if I am wrong?

hockey2112’s picture

Close, but just a bit different.

In your example, Product ID 1 and Product ID 2 appear to be their Node ID. The value I am trying to return is the Order Product ID. That is the ID assigned to the products in each order, in the uc_order_products table. So let's say you placed an order for one Product A and one Product B, and that was the first order on your site. The Order Product IDs would be "1" and "2". Then you place a second order for one of each product. The Order Product IDs would be "3" and "4". Those values are in the database, but they are not being displayed correctly in Views.

I was shown a module that adds this functionality: https://github.com/leolandotan/Ubercart-Add-ons /

http://drupal.stackexchange.com/questions/161791/order-product-id-field-...

While that is useful, it doesn't address the issue of the core Views functionality not displaying the correct values.