updated to beta3 and now views_get_view_result is broken.

logging each line of the function show that the culprit seems to be view->execute that does not bring any result (simple view with 1 field, 1 argument, 1 relation and 1 filter on a related field).

dev version one week old was working.


dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Which field do you have in?

If it's a fieldapi field it's kind of special because the data isn't part of the intial query.
To find this out please provide an export.

xlyz’s picture

$view = new view;
$view->name = 'shippable_items';
$view->description = '';
$view->tag = 'commerce';
$view->base_table = 'commerce_line_item';
$view->human_name = 'Shippable items';
$view->core = 7;
$view->api_version = '3.0-alpha1';
$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['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: Fields: Referenced product */
$handler->display->display_options['relationships']['commerce_product_product_id']['id'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['commerce_product_product_id']['table'] = 'field_data_commerce_product';
$handler->display->display_options['relationships']['commerce_product_product_id']['field'] = 'commerce_product_product_id';
$handler->display->display_options['relationships']['commerce_product_product_id']['required'] = 0;
/* Field: Commerce Line Item: Line item ID */
$handler->display->display_options['fields']['line_item_id']['id'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['table'] = 'commerce_line_item';
$handler->display->display_options['fields']['line_item_id']['field'] = 'line_item_id';
$handler->display->display_options['fields']['line_item_id']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['external'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['trim'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['line_item_id']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['line_item_id']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['line_item_id']['alter']['html'] = 0;
$handler->display->display_options['fields']['line_item_id']['element_label_colon'] = 1;
$handler->display->display_options['fields']['line_item_id']['element_default_classes'] = 1;
$handler->display->display_options['fields']['line_item_id']['hide_empty'] = 0;
$handler->display->display_options['fields']['line_item_id']['empty_zero'] = 0;
/* Contextual filter: Commerce Line Item: Order ID */
$handler->display->display_options['arguments']['order_id']['id'] = 'order_id';
$handler->display->display_options['arguments']['order_id']['table'] = 'commerce_line_item';
$handler->display->display_options['arguments']['order_id']['field'] = 'order_id';
$handler->display->display_options['arguments']['order_id']['default_action'] = 'empty';
$handler->display->display_options['arguments']['order_id']['default_argument_type'] = 'fixed';
$handler->display->display_options['arguments']['order_id']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['order_id']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['order_id']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['order_id']['summary_options']['items_per_page'] = '25';
$handler->display->display_options['arguments']['order_id']['break_phrase'] = 0;
$handler->display->display_options['arguments']['order_id']['not'] = 0;
/* Filter criterion: Fields: Shippable (field_shippable) */
$handler->display->display_options['filters']['field_shippable_value']['id'] = 'field_shippable_value';
$handler->display->display_options['filters']['field_shippable_value']['table'] = 'field_data_field_shippable';
$handler->display->display_options['filters']['field_shippable_value']['field'] = 'field_shippable_value';
$handler->display->display_options['filters']['field_shippable_value']['relationship'] = 'commerce_product_product_id';
$handler->display->display_options['filters']['field_shippable_value']['value'] = array(
  1 => '1',
$translatables['shippable_items'] = array(
  t('Sort by'),
  t('Items per page'),
  t('- All -'),
  t('Line item ID'),

it's in this module: http://drupal.org/sandbox/xlyz/1099140

let me know if you need further information.

xlyz’s picture

Status: Postponed (maintainer needs more info) » Active
merlinofchaos’s picture

Can you please tell us what you are expecting versus what you are getting from this result?

merlinofchaos’s picture

Status: Active » Postponed (maintainer needs more info)
xlyz’s picture

Status: Postponed (maintainer needs more info) » Active

I use it to check if an order has order lines (line_item entity) with a boolean field (product is shippable) set to 1 in the referenced product entity.

 * Rules condition callback:
 * checks to see if the given order has shippable items
function commerce_delivery_order_has_shippable_item($order) {
  $shippables = views_get_view_result('shippable_items', 'default', $order->order_id);
  if (count($shippables) == 0) {
    return FALSE;
  return TRUE;

The preview of the view in the view edit form works as expected.

It's the views_get_view_result function that broke one week ago. I already checked that arguments are passed to the function correctly.

merlinofchaos’s picture

Ok, so far you've showed us the view and the code.

Sadly all you've communicated so far is that the result is somehow broken, when the preview works, but I still don't know what the result you *expect* is versus the result you *got*.

This is because I don't know the difference between works and broken in this context. What data do you get? What data do you expect?

merlinofchaos’s picture

Note that the code for views_get_view_result has not changed in months, so I don't really have a good idea for what might've changed in the last week.

xlyz’s picture

result expected: array of ids of line items matching filter (boolean field is 1) and argument (referenced order id matches the order id passed)

now i get allways an empty array.

dawehner’s picture

Category: bug » feature
Priority: Major » Normal

See #1063418: views_get_view_result drupal 7 returns "node" for fields:
The fieldapi fields are requested in an additional query, so they don't land in the result array at the moment.

But #1063546: Make field values accessible to themers tryed to push it, but probably rendering isn't part of views_get_view_result.

So this is a new feature, instead of a bug.

merlinofchaos’s picture

Well, I think that code is only counting result rows, not actual fields. So I'm not sure that's the problem, dereine.

1) How many result rows does the preview return?
2) Have you verified the order ID is correct and the same?

xlyz’s picture

Category: feature » bug
Priority: Normal » Major

1) depends how many shippable line items are in each order. can be 0, 1, 2 or more.
2) yes. as said i dsm(get_defined_vars()) for each line of code of my callback and of views_get_view_result function and the problem seems to be $view->execute() (row 1720 of view.module) not doing its job. I was not able to follow further, but if you can give hints i can try.

xlyz’s picture

Category: bug » feature
Priority: Major » Normal

ops. changed them unintentionally

xlyz’s picture

Status: Active » Closed (works as designed)

I investigated further and seems that the problem is somewhere else. line_items did not have order_id filled when rule condition is fired, upon a new order save. A few lines of code in commerce_order did change at the same time the problem arose, but I did not realize it, connecting the dots. Preview did not showed the problem as it has to be run on an existing order.

Views works as expected. Thanks for the prompt support you gave me.