I have a View of type "Orders" for my Ubercart 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;



I've also experienced this issue by creating hook_views_data_alter adding the following code into it:

$data['uc_order_products']['order_product_id']['field'] = array(
    'handler' => 'views_handler_field_numeric',

I have noticed that the order_product_id had no handler so since the return of this field is the ordered product id I just went ahead and used the handler that comes with Views views_handler_field_numeric.

If you'd like, I bunched some additions related to the order product id field in my custom module in Ubercart-Add-ons.

  • You're very welcome! Glad it's working great for you! :) – Leolando Tan Jun 12 '15 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.