Hi, how to add column item price in cart page?
Thanks
Using TAPIr through hook_form_alter(): http://www.ubercart.org/docs/developer/7512/tapir_tables_api
Thanks, i will check it.
Ryan, thanks for your help.
But, i am very confuse about that 
Can you tell me how the way step by step ?
Thanks
I recently needed the same thing and finally came up with this. I'm not sure if this is the correct way of doing it but it seems to work for me.
I placed this in a custom module called "uc_custom" located under the modules/ubercart directory.
function uc_custom_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
$form['items']['#columns']['unit_price'] = array(
'cell' => t('Price'),
'weight' => 4,
'enabled' => true,
);
$form['items']['#columns']['qty']['weight'] = 5;
$form['items']['#columns']['total']['weight'] = 6;
$i = 0;
foreach ($form['#parameters'][2] as $item) {
$form['items'][$i]['unit_price']['#value'] = uc_currency_format($item->price);
$i = $i + 1;
}
}
}
@mlle.yotnottin
Thank you so much for your help.
I have do that, and print the unit price in table... but it was located not in the right place.. i think i must alter the table... how to alter the table...
Are that is using hook_table_alter or how ?
I want to display the table like :
Remove Products Price Qty Total
(checkbox) product_name 12,000 2 24,0000
or you can check for the capture image on http://img410.imageshack.us/img410/8617/cartpageilustrationzw9.jpg
Thanks
Use the weight fields for each column to establish your column order.
I wanted the unit_price column to come before the qty and total columns so I set it's weight to 4. I then set the qty weight to be 5 and the weight for the total column to be 6 to make sure they displayed in the table where I wanted them to be.
Quick warning: this line: foreach ($form['#parameters'][2] as $item) { accesses the $form['#parameters'] array with an absolute index of 2. This array contains the data for each line item in the order but it may (or may not) actually show up at some index number other than 2. This part of the code needs some error checking to make sure you actually have the line item array and not something else.
Good luck!
Mlle.Yotnottin
Ehm.. i try to modify the uc_cart_view_table for the correct input in table...
But i getting false... I don't know what the wrong...
Sorry for my acknowledgement , thanks
function custom_ubercart_form_alter(&$form, &$form_state, $form_id){
if ($form_id == 'uc_cart_view_form'){
$forms['items']['#column']['desc']['weight'] = 0;
$forms['items']['#column']['price'] = array(
'title' => t('Price(Rp)'),
'weight' => 1,
'enabled' => true,
);
$forms['items']['#column']['qty']['weight'] = 2;
$forms['items']['#column']['total']['weight'] = 3;
$i = 0;
foreach ($form['#parameters'][2] as $item) {
$form['items'][$i]['unit_price']['#value'] = uc_currency_format($item->price);
$i = $i + 1;
}
}
}
function custom_ubercart_table_alter(&$table, $table_id) {
if ($table_id == 'uc_cart_view_table'){
$table['#columns'] = array(
'desc' => array(
'cell' => '',
'weight' => 0,
),
'price' => array(
'cell' => t('Price(Rp.)'),
'weight' => 1,
),
'qty' => array(
'cell' => t('Qty.'),
'weight' => 2,
),
'total' => array(
'cell' => t('Total'),
'weight' => 3,
),
);
foreach (element_children($table) as $i) {
$subtotal += $table[$i]['#total'];
$table[$i]['desc']['#cell_attributes'] = array('width' => '100%', 'class' => 'desc');
$table[$i]['price']['#cell_attributes'] = array('class' => 'price');
$table[$i]['qty']['#cell_attributes'] = array('class' => 'qty');
$table[$i]['total']['#cell_attributes'] = array('nowrap' => 'nowrap', 'class' => 'price');
$table[$i]['#attributes'] = array('valign' => 'top');
}
$table[] = array(
'total' => array(
'#value' => '<strong>'. t('Subtotal:') .'</strong> '. uc_currency_format($subtotal),
'#cell_attributes' => array(
'colspan' => 'full',
'align' => 'right',
'nowrap' => 'nowrap',
'class' => 'subtotal',
),
),
);
return $table;
}
}
They ask some change, this is the capture that they are want to get.
http://img144.imageshack.us/img144/7781/carthbid8.jpg
Thanks
| Attachment | Size |
|---|---|
| cart-hb.jpg | 17.65 KB |
Ok, i get it 
Thanks for your help... but the question.. how to disabled the column that not used ?? i have add 'disabled' => true but it's still displayed 
ehm...
IC, i get it.. it was solved. 
The las problem.. ehmm how to change qty column from text field to regular text ??
Thanks
IC, i get it.. it was solved. 
The las problem.. ehmm how to change qty column from text field to regular text ??
Thanks
Based on uc_restrict code (and not tested)
/**
* Implementation of hook_form_alter().
*/
function uc_restrict_qty_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
for ($i = 0, $j = count(uc_cart_get_contents()); $i < $j; $i++) {
$form['items'][$i]['qty']['#type'] = 'value';
$form['items'][$i]['qty']['#theme'] = 'restrict_qty_field';
}
}
}...how to disabled the column that not used ?? i have add 'disabled' => true but it's still displayed
You might try replacing
<?php
$table[$i]['qty']['#cell_atributes'] = array ('class' => 'qty');
?>with
<?php
$table[$i]['qty']['#type'] = 'hidden';
?>in your override of uc_cart_view_table.
OR
in your hook_form_alter(&$form, $form_state, $form_id), add
<?php
//Replace column header w/ nothing:
$form['items']['#columns']['qty']['cell'] = '';
foreach (
$form['#parameters'][2] as $item) {
//...other stuff here
//Hide the 'qty' field in each row:
$form['items'][$i]['qty']['#type'] = 'hidden';
//...more stuff here
}
?>I needed the unit price as well, but I'm using product kits, so I changed it a bit. Depending on the type of product kit we have to adapt the code.
function attiks_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
$form['items']['#columns']['unit_price'] = array(
'cell' => t('Price'),
'weight' => 4,
'enabled' => true,
);
$form['items']['#columns']['qty']['weight'] = 5;
$form['items']['#columns']['total']['weight'] = 6;
// For product kits we can only set the unit price on the first item
$product_kit_price = array();
foreach ($form['#parameters'][2] as $i => $item) {
if ($item->data['module'] == 'uc_product_kit') {
if (!isset($product_kit_price[$item->data['unique_id']])) {
// Load product kit to get the sell price
$vid->vid = $item->data['kit_id'];
$p = uc_product_kit_load($vid);
switch ($p->mutable) {
case -1: // As unit, no details
$product_kit_price[$item->data['unique_id']]['id'] = $i;
$product_kit_price[$item->data['unique_id']]['unit_price'] = $p->sell_price;
break;
case 0: // As unit, with list
$product_kit_price[$item->data['unique_id']]['id'] = $i;
$product_kit_price[$item->data['unique_id']]['unit_price'] = $p->sell_price;
break;
case 1: // As separate products
$form['items'][$i]['unit_price']['#value'] = uc_currency_format($item->price);
break;
}
}
}
else {
$form['items'][$i]['unit_price']['#value'] = uc_currency_format($item->price);
}
}
foreach ($product_kit_price as $item) {
$form['items'][$item['id']]['unit_price']['#value'] = uc_currency_format($item['unit_price']);
}
}
}
When I followed instructions here, the item price showed up, but the labels didn't line up with data. I have no idea why fiddling with the labels worked, but it did. (I also removed the remove column)
<?php
function capcart_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
$form['items']['#columns']['price'] = array(
'cell' => t('Price'),
'weight' => 3,
'enabled' => TRUE,
);
$form['items']['#columns']['desc']['cell'] = t('Price');
$form['items']['#columns']['qty']['cell'] = t('Total');
$form['items']['#columns']['total']['cell'] = '';
$form['items']['#columns']['price']['cell'] = t('Qty.');
$form['items']['#columns']['remove']['access'] = FALSE;
$form['items']['#columns']['products']['weight'] = 1;
$form['items']['#columns']['desc']['weight'] = 2;
$form['items']['#columns']['qty']['weight'] = 4;
$form['items']['#columns']['total']['weight'] = 5;
$i = 0;
foreach ($form['#parameters'][2] as $item) {
$form['items'][$i]['price']['#value'] = uc_currency_format($item->price);
$i = $i + 1;
}
}
}
?>Hi Cakka,
I try custom_cart its not work for me . please help
The snippets people have been posting on this thread, and elsewhere, work great for the regular cart page.
But what about cart review table on the Checkout page? I'm still trying to get that going.
In exploration of this issue I'm simply trying to just affect that cart review table in SOME way but after going through 5 functions I still can't seem to be able to touch it. Like changing the title from "Cart Contents" to anything else. Am I missing something? I'm clear cache on the Performance page, and refreshing admin and/or module pages for the hell of it.
