0

How can I hide Ubercart AJAX Cart block when the user's shopping cart is empty?

I know I could hide it with some jQuery tricks (for example, looking for the "cart-empty" class under my AJAX cart block (which has the class "block-uc_ajax_cart"), and hide the whole block if I found it), but this way I also would have to solve if cart is updated... Too messy.

I haven't found any opportunities to hide the block in this case under block settings, nor under the AJAX Cart Settings (http://<mysite>/admin/store/settings/uc_ajax_cart).

Thanks for your help in advance!

1 Answer 1

0

OK, in the meantime I found the solution.

1.) Set "Block title" in the appropriate block configuration to <none>. (http://<mysite>/admin/build/block/configure/uc_ajax_cart/0) (you'll see later why)

Block title:
<none>

2.) Copy the UC AJAX Cart template files (uc_ajax_cart_block_content.tpl.php, uc_ajax_cart_block_content_empty.tpl.php) from http://<mysite>/sites/all/modules/uc_ajax_cart/templates/
to your own theme's templates directory (http://<mysite>//sites/all/themes/<mytheme>/templates/).

3.) After that, open both copied files (which are now in your template directory) in a text editor.

4.) Delete (or put in a comment) the content of uc_ajax_cart_block_content_empty.tpl.php, and upload the edited file to the server.

5.) Prepend the following to uc_ajax_cart_block_content.tpl.php to have the block title back:

<h2 class="title">
    <span class="title block-title" id="ajax-cart-headline">
        <a href="#" id="ajaxCartToggleView" class="ajax-cart-processed"><?php print t('Shopping cart')?></a>
    </span>
</h2>

(The rest should stay intact!!)

6.) Clear the theme registry cache (http://<mysite>/admin_menu/flush-cache/theme), and you're done.


UPDATE:
the method above breaks the toggling opportunity of the shopping cart content (if the following is checked in the settings: "Make the shopping cart block collapsible by clicking the name or arrow.") when clicking on the block title ("Shopping Cart"), because the title part is also updated with AJAX from the uc_ajax_cart_block_content.tpl.php file, BUT there IS a solution in jQuery, which you have to put in your own JavaScript-file (which is e.g. put in your theme's .info file), and it looks like this:

$(document).ready( function(){
    if( $('#ajaxCartToggleView').length > 0 ){
        // live: "Attach an event handler for all elements which match the current selector, now and in the future." (http://api.jquery.com/live/)
        $("#ajaxCartToggleView").live("click", function(){
            ajaxCartToggleView();
            return false;
        });
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.