Ubercart: modificare Carrello finale
Avrei necessità di usare ubercart facendogli però eliminare dallo shopping cart (la pagina di riepilogo degli ordini nel carrello) tutti i riferimenti ai costi, e se possibile alle quantità.
Per ora sono riuscito ad eliminare il Subtotale e i riferimenti del totale dal blocco del carrello, ma non riesco a togliere la colonna del "Totale" (evidenziata nell'immagine allegata). Come posso toglierla?
Per la quantità invece la cosa migliore sarebbe sostituire il form con la scelta e mettere un "1" fisso, in modo che l'utente non possa chiederne quantità maggiori.
Grazie!
| Allegato | Dimensione |
|---|---|
| ishot-2.jpg | 39.5 KB |

Risposte
Per il theming del carrello
Per il theming del carrello puoi fare un override della funzione theme_uc_cart_view_form definita in uc_cart.module.
Per controllare la quantità c'è un modulo apposito http://drupal.org/project/uc_restrict_qty.
Grazie! ho provato a
Grazie! ho provato a smanettare un pò ma finora il risultato è stato nulla o un errore interno :)
Puoi dirmi a spanne cosa dovrei toccare per togliere del tutto la colonna del prezzo?
function uc_cart_view_form($form_state, $items = NULL) {
$form['items'] = array(
'#type' => 'tapir_table',
'#tree' => TRUE,
);
$context = array(
'revision' => 'themed-original',
'type' => 'amount',
);
$i = 0;
foreach ($items as $item) {
$display_item = module_invoke($item->module, 'cart_display', $item);
if (!empty($display_item)) {
$form['items'][$i] = $display_item;
$form['items'][$i]['image']['#value'] = uc_product_get_picture($display_item['nid']['#value'], 'cart');
$description = $display_item['title']['#value'] . $display_item['description']['#value'];
$form['items'][$i]['desc']['#value'] = $description;
$form['items'][$i]['title']['#type'] = 'value';
$form['items'][$i]['description']['#type'] = 'value';
if (empty($display_item['qty'])) {
$form['items'][$i]['qty'] = array(
'#value' => '',
);
}
$form['items'][$i]['total'] = array(
'#value' => uc_price($display_item['#total'], $context),
'#theme' => 'uc_cart_view_price',
);
$i++;
}
}
$form['items'] = tapir_get_table('uc_cart_view_table', $form['items']);
// If the continue shopping element is enabled...
if (($cs_type = variable_get('uc_continue_shopping_type', 'link')) !== 'none') {
// Setup the text used for the element.
$cs_text = variable_get('uc_continue_shopping_text', '') ? variable_get('uc_continue_shopping_text', '') : t('Continue shopping');
// Add the element to the form based on the element type.
if (variable_get('uc_continue_shopping_type', 'link') == 'link') {
$form['continue_shopping'] = array(
'#value' => l($cs_text, uc_cart_continue_shopping_url()),
);
}
elseif (variable_get('uc_continue_shopping_type', 'link') == 'button') {
$form['continue_shopping'] = array(
'#type' => 'submit',
'#value' => $cs_text,
'#submit' => array('uc_cart_view_form_submit'),
);
$form['continue_shopping_text'] = array(
'#type' => 'hidden',
'#value' => $cs_text,
);
}
}
Hmm.. mi riferivo
Hmm.. mi riferivo all'override della funzione theme_uc_cart_view_form, così non devi modificare il modulo originale di ubercart. Metti nel tuo template.php (es. poniamo che il tuo tema sia garland) la funzione garland_uc_cart_view_form e ci copi la funzione originale theme_uc_cart_view_form in pratica:
function garland_uc_cart_view_form($form) {
drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
/* INIZIO AGGIUNTA */
unset($form['items']['#columns']['total']);
foreach (element_children($form['items']) as $i) {
unset($form['items'][$i]['total']);
}
/* FINE AGGIUNTA */
$output = '<div id="cart-form-products">'
. drupal_render($form['items']) .'</div>';
foreach (element_children($form['items']) as $i) {
foreach (array('title', 'options', 'remove', 'image', 'qty') as $column) {
$form['items'][$i][$column]['#printed'] = TRUE;
}
$form['items'][$i]['#printed'] = TRUE;
}
// Add the continue shopping element and cart submit buttons.
if (($type = variable_get('uc_continue_shopping_type', 'link')) != 'none') {
// Render the continue shopping element into a variable.
$cs_element = drupal_render($form['continue_shopping']);
// Add the element with the appropriate markup based on the display type.
if ($type == 'link') {
$output .= '<div id="cart-form-buttons"><div id="continue-shopping-link">'
. $cs_element .'</div>'. drupal_render($form) .'</div>';
}
elseif ($type == 'button') {
$output .= '<div id="cart-form-buttons"><div id="update-checkout-buttons">'
. drupal_render($form) .'</div><div id="continue-shopping-button">'
. $cs_element .'</div></div>';
}
}
else {
$output .= '<div id="cart-form-buttons">'. drupal_render($form) .'</div>';
}
return $output;
}
le righe tra inizio|fine aggiunta servono a eliminare la colonna totale.
Non l'ho testato, e forse non è elegantissimo, ma a occhio e croce dovrebbe andare.
Fammi sapere!!
Aiuto... ci provo! ;)
Aiuto... ci provo! ;)
Allora, qualcosa dovrei aver
Allora, qualcosa dovrei aver fatto ma non è cambiato nulla... che sbaglio?
Il tema è Sky, ho aperto themes/sky/template.php e cambiato aggiungendo il pezzo che mi hai passato, alla fine il template.php è diventato così:
<?php
// $Id$
/**
* @file
* The guts of the theme :)
*/
require_once('theme-settings.php');
/**
* Add Custom Generated CSS File
* This file is generated each time the theme settings page is loaded.
*/
$custom_css = file_directory_path() .'/sky/custom.css';
if (file_exists($custom_css)) {
drupal_add_css($custom_css, 'theme', 'all', TRUE);
}
function sky_uc_cart_view_form($form) {
drupal_add_css(drupal_get_path('module', 'uc_cart') .'/uc_cart.css');
/* INIZIO AGGIUNTA */
unset($form['items']['#columns']['total']);
foreach (element_children($form['items']) as $i) {
unset($form['items'][$i]['total']);
}
/* FINE AGGIUNTA */
$output = '<div id="cart-form-products">'
. drupal_render($form['items']) .'</div>';
foreach (element_children($form['items']) as $i) {
foreach (array('title', 'options', 'remove', 'image', 'qty') as $column) {
$form['items'][$i][$column]['#printed'] = TRUE;
}
$form['items'][$i]['#printed'] = TRUE;
}
// Add the continue shopping element and cart submit buttons.
if (($type = variable_get('uc_continue_shopping_type', 'link')) != 'none') {
// Render the continue shopping element into a variable.
$cs_element = drupal_render($form['continue_shopping']);
// Add the element with the appropriate markup based on the display type.
if ($type == 'link') {
$output .= '<div id="cart-form-buttons"><div id="continue-shopping-link">'
. $cs_element .'</div>'. drupal_render($form) .'</div>';
}
elseif ($type == 'button') {
$output .= '<div id="cart-form-buttons"><div id="update-checkout-buttons">'
. drupal_render($form) .'</div><div id="continue-shopping-button">'
. $cs_element .'</div></div>';
}
}
else {
$output .= '<div id="cart-form-buttons">'. drupal_render($form) .'</div>';
}
return $output;
}
/**
* Implementation of hook_theme().
* This function provides a one-stop reference for all
*/
function sky_theme(&$existing, $type, $theme, $path) {
return array(
'breadcrumb' => array(
'arguments' => array('breadcrumb' => array()),
'file' => 'functions/theme-overrides.inc',
),
'conditional_stylesheets' => array(
'file' => 'functions/theme-custom.inc',
),
'feed_icon' => array(
'arguments' => array('url' => NULL, 'title' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'form_element' => array(
'arguments' => array('element' => NULL, 'value' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'fieldset' => array(
'arguments' => array('element' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'menu_local_tasks' => array(
'arguments' => NULL,
'file' => 'functions/theme-overrides.inc',
),
'more_link' => array(
'arguments' => array('url' => array(), 'title' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'pager' => array(
'arguments' => array('tags' => array(), 'limit' => NULL, 'element' => NULL, 'parameters' => array(), 'quantity' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'status_messages' => array(
'arguments' => array('display' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'status_report' => array(
'arguments' => array('requirements' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'table' => array(
'arguments' => array('header' => NULL, 'rows' => NULL, 'attributes' => array(), 'caption' => NULL),
'file' => 'functions/theme-overrides.inc',
),
'render_attributes' => array(
'arguments' => array('attributes'),
'file' => 'functions/theme-custom.inc',
),
);
}
/**
* Implementation of hook_preprocess().
*
* @param $vars
* @param $hook
* @return Array
*/
function sky_preprocess(&$vars, $hook) {
// Only add the admin.css file to administrative pages
if (arg(0) == 'admin') {
drupal_add_css(path_to_theme() .'/css/admin.css', 'theme', 'all', TRUE);
}
/**
* This function checks to see if a hook has a preprocess file associated with
* it, and if so, loads it.
*/
if (is_file(drupal_get_path('theme', 'sky') .'/preprocess/preprocess-'. str_replace('_', '-', $hook) .'.inc')) {
include('preprocess/preprocess-'. str_replace('_', '-', $hook) .'.inc');
}
}
Adesso immagino di aver fatto qualche errore imbarazzante... :D
Sembra tutto ok. Hai pulito
Sembra tutto ok. Hai pulito la cache per forzare la rilettura dei file del tema?
Ecco appunto... l'avevo detto
Ecco appunto... l'avevo detto che sarebbe stato imbarazzante! :D
In realtà avevo fatto flush all cache e non era cambiato nulla, adesso l'ho cancellata del theme registry e funziona perfettamente.
Grazie di tutto!
Ottimo!
Ottimo!
salve, ho un problema per
salve, ho un problema per certi versianalogo a quello di cerion86.
mi servirebbe inserire un nuovo campo, preso dal prodotto, nella form del carrello di Ubercart...
ho cercato in letteratura e nei vari blocchi ma sono ancora confuso e le modifiche che ho apportato sembrano non dare i risultati sperati...
sono riuscito a far visualizzare le nuova riga, ma, nonostante tutti i miei sforzi, non riesco a metterci alcun valore dentro.
potete aiutarmi??
Ciao, purtroppo questo è un
Ciao, purtroppo questo è un post un vecchio di anni, aprine uno nuovo con i tag più appropriati.
Se sei ancora in fase di valutazione della suite ecommerce da utilizzare ti segnalo il progetto commerce (https://drupal.org/project/commerce) alternativo ad Ubercart (solo Drupal 7). Il carrello è implementato con Views e aggiungere un campo del prodotto alla relativa pagina di visualizzazione è piuttosto immediato.
"purtroppo" ho già fatto
"purtroppo" ho già fatto buona parte del portale e cambiare adesso impensabile per i tempi di go-live che abbiamo.
seguirò il tuo consiglio, aprirò una nuova segnalazione, sperando di trovare una soluzione.
grazie