0

In the simplest terms I am trying to add a 'vendor' column to the order view table in Ubercart which will display the author of each line item product.

Below is the table of interest. I have hacked the direct code contained in uc_order.order_pane.inc but will refactor with hooks the drupal way ASAP. I have added my comments in the code below.

function uc_op_products_view_table($order) {
  dpm($order);
  $table = array(
    '#type' => 'tapir_table',
    '#attributes' => array('class' => array('order-pane-table')),
  );

  $table['#columns']['qty'] = array(
    'cell' => array(
      'data' => theme('uc_qty_label'),
      'class' => array('qty'),
    ),
    'weight' => 0,
  );
  $table['#columns']['product'] = array(
    'cell' => array(
      'data' => t('Product'),
      'class' => array('product'),
    ),
    'weight' => 1,
  );

Added by me:

  $table['#columns']['Vendor'] = array(
    'cell' => array(
      'data' => t('Vendor'),
      'class' => array('vendor'),
    ),
    'weight' => 1.5,
  );

.

  $table['#columns']['model'] = array(
    'cell' => array(
      'data' => t('SKU'),
      'class' => array('sku'),
    ),
    'weight' => 2,
  );
  if (user_access('administer products')) {
    $table['#columns']['cost'] = array(
      'cell' => array(
        'data' => t('Cost'),
        'class' => array('cost'),
      ),
      'weight' => 3,
    );
  }
  $table['#columns']['price'] = array(
    'cell' => array(
      'data' => t('Price'),
      'class' => array('price'),
    ),
    'weight' => 4,
  );
  $table['#columns']['total'] = array(
    'cell' => array(
      'data' => t('Total'),
      'class' => array('total'),
    ),
    'weight' => 5,
  );

  if (!empty($order->products)) {
    $build = entity_view('uc_order_product', $order->products);

This is the entity I want to edit. uc_order_product needs to have a field for Author / Vendor to make my table look right.

    dpm($build);
    $table['#rows'] = $build['uc_order_product'];
  }
  else {
    $table['#rows'][]['product'] = array(
      '#markup' => t('This order contains no products.'),
      '#cell_attributes' => array('colspan' => 'full'),
    );
  }

  return $table;
}
0

So this is the ugly hack I used to resolve the issue:

  if (!empty($order->products)) {
    $build = entity_view('uc_order_product', $order->products);
    foreach($build['uc_order_product'] as $line_item) {
      $node = node_load($line_item['#entity']->nid);
      $vendor['#markup'] = '<a href=' . url('user/' . $node->uid) . '>' . $node->uid . '</a>';
      $vendor['#cell_attributes']['class'][] = 'vendor';
      $line_item_id = $line_item['#entity']->order_product_id;
      $build['uc_order_product'][$line_item_id]['vendor'] = $vendor;
    }
    $table['#rows'] = $build['uc_order_product'];
  }

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.