0

We are using Drupal commerce and have a report in views using commerce_line_item as the base. We need to be able to split the quantities up into multiple rows. So if a line item has a qty of 5 there should be 5 rows. I am trying to implement this:

https://stackoverflow.com/questions/22291814/mysql-return-result-by-quantity-per-row

I am adding a join in hook_views_query_alter but there does not appear to be a way of changing the join condition from = to <=.

LEFT JOIN {line_items_tally} line_items_tally ON commerce_line_item.quantity = line_items_tally.n

needs to be

LEFT JOIN {line_items_tally} line_items_tally ON commerce_line_item.quantity <= line_items_tally.n

Is there any way of doing that?

0

I ended up using hook_query_alter rather than hook_views_query_alter

/**
 * Implements hook_query_alter().
 */
function custom_query_alter(QueryAlterableInterface $query) {
  if ($query->hasTag('line_itmes_qty')) {
    $query->join('line_items_tally', 't', 't.n <= commerce_line_item.quantity');
  }
}

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.