Change Ubercart cart form view with corresponding template

In order to change custom view of ubercart cart form we need to use themplate uc_cart_view_form.tpl.php. If you want to add a price column for each product you just need to paste the code given below into file with uc_cart_view_form.tpl.php name, then you should clear drupal caches using path: /admin/config/development/performance.

{syntaxhighlighter brush: css;fontsize: 100; first-line: 1; }<?php $variables['form']['items']['#tree'] = 1; ?>{/syntaxhighlighter} {syntaxhighlighter brush: css;fontsize: 100; first-line: 1; }<?php $variables['form']['items']['#columns']['remove']['weight'] = 6; ?> <?php $form = &$variables['form']; ?> <div class="uc-default-submit custom"> <?php hide($form['actions']['continue_shopping']); ?> <?php hide($form['actions']['update']); ?> </div> <?php{/syntaxhighlighter} {syntaxhighlighter brush: css;fontsize: 100; first-line: 1; }// here we add price column $form['items']['#columns'] += array( 'price' => array( 'cell' => t('Price'), 'weight' => 2.5, ), ); global $language; //here we make loop and process all form items{/syntaxhighlighter} {syntaxhighlighter brush: css;fontsize: 100; first-line: 1; } for($i=0; $i < count($form['items']); $i++) { if(isset($form['items'][$i]['nid'])) { // Loading the node so we can retrieve the information we need. $product = node_load($form['items'][$i]['nid']['#value']); // Adding the 'Units' to the product that is in the user's cart. $form['items']['#rows'][$i]['units'] = field_view_field('node', $product, 'field_units', array('label' => 'hidden') ); $form['items']['#rows'][$i]['units'] += array( '#cell_attributes' => array( 'class' => array('units'), ), '#tree' => 1, '#id' => 'edit-items-0-units', '#sorted' => 1, ); $node = node_load($form['items'][$i]['nid']['#value']); $image = field_view_field('node', $node, 'uc_product_image', array('label' => 'hidden','type' =>'image', 'settings' => array('image_style' => 'uc_product', 'image_link' => 'content')) ); $form['items']['#rows'][$i]['picture'] = $image; // Adding the 'Price per item' to the product that is in the user's cart. $form['items']['#rows'][$i]['price'] = array( '#markup' => uc_currency_format($product->price), '#cell_attributes' => array( 'class' => array('price'), ), '#tree' => 1, '#id' => 'edit-items-0-price', '#sorted' => 1, ); $nid = $form['items'][$i]['nid']['#value']; $node = node_load($nid); //Get texonomy term $form['items']['#rows'][$i]['taxonomy'] = field_view_field('node', $node, 'taxonomy_catalog', array('label' => 'hidden') ); $form['items']['#rows'][$i]['taxonomy'] += array( '#cell_attributes' => array( 'class' => array(''), ), '#tree' => 1, '#id' => 'edit-items-0-units', '#sorted' => 1, ); if (variable_get('uc_checkout_enabled', TRUE)) { $form['actions']['checkout'] = array( '#type' => 'submit', '#value' => t('Checkout'), '#submit' => array('uc_cart_view_form_submit', 'uc_cart_view_form_checkout'), '#field_prefix' => '<div class="button_checkout">', '#field_suffix' => '</div>', ); } } } ?> <?php print drupal_render_children($form); ?>{/syntaxhighlighter}
Rating: 
0 out of 10 based on 0 ratings.