I'd like to show the "Custom Products" order pane, which you see on completed orders (user/*/orders/*) to the cart and checkout pages

I found this, which seems to be the relevant bit of code, in uc_node_checkout.module

/**
 * Handles the "Custom Products" order pane.
 */
function uc_node_checkout_order_pane_nodes($op, $arg1) {
  switch ($op) {
    case 'view':
    case 'customer':
      $order = $arg1;

      $output  = '<p>' . t('The following products in this order have customizations described below.') . '</p>';
      $output .= '<p>' . t('Please click each link to view more information.') . '</p>';
      foreach ($order->products as $product) {

        // Check for a node type association
        $has_association = isset($product->data['node_checkout_nid']);

        // If an association was not found check if there should have been
        if (!$has_association) {
          $association_node_type = uc_node_checkout_node_type_association($product->nid);
        }

        // Create a row for customised products
        if ($has_association) {
          $node_checkout_node = node_load($product->data['node_checkout_nid']);
          $items[] = l(t('@product_title (SKU @product_model) - @node_checkout_title',
                         array('@product_title' => $product->title,
                               '@product_model' => $product->model,
                               '@node_checkout_title' => $node_checkout_node->title)),
              'node/' . $node_checkout_node->nid, array('html' => TRUE));
        }

        // Create a row for should-be customised products
        if (!$has_association && $association_node_type) {
          $items[] = t('(!create_now_link) The product %product_title (SKU %product_model) is missing its node customisation.',
            array(
              '%product_title' => $product->title,
              '%product_model' => $product->model,
              '!create_now_link' => l(t('Create node association'), 'node/add/' . str_replace('_', '-', $association_node_type),
                array('query' => array('order_id' => $order->order_id, 'product_id' => $product->nid, 'order_product_id' => $product->order_product_id))),
            )
          );
        }
      }

      if (!empty($items)) {
        $output .= theme('item_list', array('items' => $items));
        return array('#markup' => $output);
      }
      else {
        return '';
      }
  }
}

How would I go about adding that (or the right code, it this will not do it!?) to a template file for both the cart and checkout?

I looked at http://www.ubercart.org/docs/user/32119/how_theme_checkout_pane_ubercart_3
and guess I should be able to add the above code to the below from uc_cart_checkout_pane.inc

/**
 * Formats the cart contents table on the checkout page.
 *
 * @param $variables
 *   An associative array containing:
 *   - show_subtotal: TRUE or FALSE indicating if you want a subtotal row
 *     displayed in the table.
 *   - items: An associative array of cart item information containing:
 *     - qty: Quantity in cart.
 *     - title: Item title.
 *     - price: Item price.
 *     - desc: Item description.
 *
 * @return
 *   The HTML output for the cart review table.
 *
 * @ingroup themeable
 */
function responsive_business_uc_cart_review_table($variables) {
  $items = $variables['items'];
  $show_subtotal = $variables['show_subtotal'];

  $subtotal = 0;

  // Set up table header.
  $header = array(
    array('data' => theme('uc_qty_label'), 'class' => array('qty')),
    array('data' => t('Products'), 'class' => array('products')),
    array('data' => t('Price'), 'class' => array('price')),
  );


  // Set up table rows.
  $display_items = uc_order_product_view_multiple($items);
  if (!empty($display_items['uc_order_product'])) {
    foreach (element_children($display_items['uc_order_product']) as $key) {
       $display_item = $display_items['uc_order_product'][$key];
      $subtotal += $display_item['total']['#price'];
      $rows[] = array(
        array('data' => $display_item['qty'], 'class' => array('qty')),
    //    array('data' => $display_item['product'], 'class' => array('products')),
        array('data' => $display_item[''], 'class' => array('osb')),
        array('data' => $display_item['total'], 'class' => array('price')),
      );
    }
  }

  // Add the subtotal as the final row.
  if ($show_subtotal) {
    $rows[] = array(
      'data' => array(
        // One cell
        array(
          'data' => array(
            '#theme' => 'uc_price',
            '#prefix' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ',
            '#price' => $subtotal,
          ),
          // Cell attributes
          'colspan' => 3,
          'class' => array('subtotal'),
        ),
      ),
      // Row attributes
      'class' => array('subtotal'),
    );
  }

  return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('cart-review'))));
}

/**
 * Themes cart items on the checkout review order page.
 *
 * @param $variables
 *   An associative array containing:
 *   - items: An associative array of cart item information containing:
 *     - qty: Quantity in cart.
 *     - title: Item title.
 *     - price: Item price.
 *     - desc: Item description.
 *
 * @return
 *   A string of HTML for the page contents.
 *
 * @ingroup themeable
 */
function responsive_business_uc_checkout_pane_cart_review($variables) {
  $rows = array();
  $items = uc_order_product_view_multiple($variables['items']);

  foreach (element_children($items['uc_order_product']) as $key) {
    $item = $items['uc_order_product'][$key];
    $rows[] = array(
      array('data' => $item['qty'], 'class' => array('qty')),
      array('data' => $item['product'], 'class' => array('products')),
      array('data' => $item['total'], 'class' => array('price')),
    );
  }

  return theme('table', array('rows' => $rows, 'attributes' => array('class' => array('cart-review'))));;
}



but I can barely read php let alone write it!

Am I on the right track?

Comments

olisb’s picture

To clarify: ideally, I would like to replace the link to the 'product type', which currently shows up in the ubercart cart and the checkout pages (from uc_cart_review_table and uc_checkout_pane_cart_review in the code above) with a link to the node which the customer is buying.

I looked at
https://drupal.org/node/1300908
http://www.ubercart.org/forum/support/2298/remove_product_links_shopping...
http://www.ubercart.org/project/uc_rm_productlinks
and managed to use the code here http://www.zyxware.com/articles/3697/drupal-7-ubercart-how-to-remove-the... to disable the product links on the cart page (but not checkout) although that's not really what I want to do...

Can anyone help me create the right php to replace the link to the 'product type' in the uc_cart_review_table and uc_checkout_pane_cart_review form tables with a link to the node which the customer is buying?

I don't think this should be too tricky for someone who knows php since the required code is already in use in the 'view order' pages, courtesy of the first block of code in the post above.

olisb’s picture

more info from people wanting the same here:
https://drupal.org/node/1846268
which pointed me here https://drupal.org/node/1696914 which features a patch to make uc_checkout do exactly what I want (which it looks like it should do straight out of the box anyway...) but the patch only half works. I now have the 'Product' title on /cart linking to the edit view of the right node, but not on the all important /cart/checkout

anyone got their version to work!?

olisb’s picture

Bingo! For anyone else trying to make the links work on the cart/checkout page too add this to your template.php file

function YOUR_THEME_NAME_uc_cart_review_table($variables) {
  $items = $variables['items'];
  $show_subtotal = $variables['show_subtotal'];

  $subtotal = 0;

  // Set up table header.
  $header = array(
    array('data' => theme('uc_qty_label'), 'class' => array('qty')),
    array('data' => t('Products'), 'class' => array('products')),
    array('data' => t('Price'), 'class' => array('price')),
  );

  // Set up table rows.
  $display_items = uc_order_product_view_multiple($items);
  if (!empty($display_items['uc_order_product'])) {
    foreach (element_children($display_items['uc_order_product']) as $key) {
      $display_item = $display_items['uc_order_product'][$key];
	  //dsm($display_item);
	  // Change the display markup to show the checked-out node
	  $nc = $display_item['#entity']->data['checkout_node']->title;
	  if(isset($display_item['#entity']->data['node_checkout_nid'])) {
		$title = '<a href="/node/'.$display_item['#entity']->data['node_checkout_nid'].'/edit?destination=cart/checkout">'.$display_item['#entity']->title.': '.$nc.'</a> <span class="node-checkout-edit">(click to edit)</span>';
		$display_item['product']['#markup'] = $title;
	  }
      $subtotal += $display_item['total']['#price'];
      $rows[] = array(
        array('data' => $display_item['qty'], 'class' => array('qty')),
        array('data' => $display_item['product'], 'class' => array('products')),
        array('data' => $display_item['total'], 'class' => array('price')),
      );
    }
  }

  // Add the subtotal as the final row.
  if ($show_subtotal) {
    $rows[] = array(
      'data' => array(
        // One cell
        array(
          'data' => array(
            '#theme' => 'uc_price',
            '#prefix' => '<span id="subtotal-title">' . t('Subtotal:') . '</span> ',
            '#price' => $subtotal,
          ),
          // Cell attributes
          'colspan' => 3,
          'class' => array('subtotal'),
        ),
      ),
      // Row attributes
      'class' => array('subtotal'),
    );
  }

  return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('class' => array('cart-review'))));
}