Hey there,
I am looking to replace the "Remove Product" text and table row with a more simplistic X icon or link that removes the product instead. I will try to post my progress on the goal, but for now I just wanted to share some quick information on how to override the block and do a custom template without modifying the module.
The first thing you can do is copy uc_ajax_cart_block_content.tpl.php to your theme from uc_ajax_cart/templates/uc_ajax_cart_block_content.tpl.php -- this will allow you to customize the template quite a bit. However, for my goal with replacing Remove Product I need to also override some of the information provided to that block template. I did this by copying the uc_ajax_cart_preprocess_uc_ajax_cart_block_content function from uc_ajax_cart.theme.inc to my template.php while replacing uc_ajax_cart with mytheme like mytheme_preprocess_uc_ajax_cart_block_content
Note that for some reason this method requires a couple changes in order for it to work properly. One example is needing to change $item->module to $item['item']->module
function mytheme_preprocess_uc_ajax_cart_block_content(&$vars) {
$content = $vars['items'];
$items = array();
$context = array(
'revision' => 'themed',
'type' => 'price',
);
$total = 0;
$total_items = 0;
foreach ($content as $item) {
$display_item = module_invoke($item['item']->module, 'cart_display', $item['item']);
if (!empty($display_item)) {
$attributes = $item->data['attributes'];
$total += $display_item['#total'];
$total_items += $display_item['qty']['#default_value'];
$items[] = array(
'nid' => $display_item['nid']['#value'],
'qty' => t('@qty×', array('@qty' => $display_item['qty']['#default_value'])),
'title' => $display_item['title']['#value'],
'descr' => isset($display_item['description']['#value']) ? $display_item['description']['#value'] : FALSE,
'link' => url('node/' . $item['item']->nid),
'item' => $item,
'image' => uc_product_get_picture($display_item['nid']['#value'], 'cart'),
'node' => node_load($item['item']->nid),
'total' => uc_price($display_item['#total'], array(
'revision' => 'themed-original',
'type' => 'amount',
)),
'remove_link' => l(t('Remove ppproduct'),
UC_AJAX_CART_REMOVE_CALLBACK,
array(
'attributes' => array(
'onclick' => "ajaxCartBlockUIRemove(this.href); return false;",
'class' => 'remove-cart-link remove-cart-link-' . $display_item['nid']['#value'],
),
'query' => array(
'nid' => $display_item['nid']['#value'],
'destination' => $_GET['q'],
'data' => base64_encode($display_item['data']['#value']),
'action' => 'remove',
),
)
),
);
}
}
$vars['total'] = uc_price($total, $context);
$vars['items'] = $items;
$vars['item_count'] = $total_items;
$vars['cart_links'] = theme('uc_ajax_cart_cart_links');
$vars['items_text'] = format_plural( $total_items , '<span class="num-items">@count</span> Item', '<span class="num-items">@count</span> Items');
}
I will go ahead and continue working on my present goal and will share the outcome as a patch in case other people are interested in the same thing or if it is to be considered for a commit.
Comments
Comment #1
vishun commentedWoops, I forgot to remove my quick test to indicate the override was working, so if your Remove product says Remove ppproduct then you know the template override is working.
Comment #2
tunicThanks for share your work, I'll try to have a look but I don't have much time...
Comment #3
vishun commentedIt's OK tunic, this isn't much of a contribution yet. I was thinking about devising a general solution that could be contributed as a patch to maybe make an X icon option on the block configuration page. For now just some helpful templating information that may help someone in the future. Perhaps it would be some good starter information for a documentation page? I'm interested in helping out if you guys need another co-maintainer or anything.