Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Hey,
I got the "Hide Empty Cart" option checked.
When i add a first product to the cart (with AJAX) - Cart shows up as a block on a sidebar, but it's lacking the block title.
After page refresh/change the title appears..
Any idea how to fix this? Or any workaround?
Thanks,
Simon
Proposed resolution
// Hide cart if it is empty.
if ($hide_empty_cart) {
$block['content'] = theme('html_tag', array(
'element' => array(
'#tag' => 'div',
'#value' => '',
'#attributes' => array(
'class' => 'ajax-shopping-cart-wrapper',
),
),
));
}
else {
$block['subject'] = t('Shopping cart');
$block['content'] = array(
'#theme' => 'dc_ajax_shopping_cart',
'#order' => $commerce_cart['order'],
'#line_items' => $line_items,
'#quantity' => $quantity,
'#total' => $total,
);
drupal_add_library('system', 'drupal.ajax', TRUE);
drupal_add_css(drupal_get_path('module', 'dc_ajax_add_cart') . '/css/dc_ajax_add_cart.css');
}
This is the code that generates cart block based on "hide empty cart" setting.
Possible solutions:
- Add
$block['content'] = t('Shopping cart');
in theif
-block. This makes sure that the title is always displayed even if cart is empty. This however defeats the purpose of "hide empty cart" setting, isn't it? - Remove
$block['subject'] = t('Shopping cart');
fromelse
-block. Doing this we make sure that block title is not provided by module. It will follow the block title that we give in "AJAX shopping cart" block settings. This change however will break new release of this module.
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Comments
Comment #1
subhojit777Comment #2
subhojit777Thanks for using and testing this module.
The problem is - when "hide empty cart" setting is checked and you add first product in cart, it just embeds the HTML of cart block in a certain DOM class. But when you refresh the page, the block title appears along with cart block.
In the first case, it does not respects the code written in
dc_ajax_add_cart_block_view($delta = '')
.Comment #3
subhojit777From proposed resolution, my recommendation is - we go for 2. Because, this way we are giving the control of block title display to "AJAX shopping cart" block settings. This will break the sites already using this module.. I know.. but at least this bug will be fixed and the purpose of "hide empty cart" setting will be maintained.
Comment #4
subhojit777Or we can also do this - specify the title in "AJAX shopping cart" block setting itself. And we add a setting whether to show the title or not when cart is empty. This way we maintain that a new release of this module does not breaks sites already using this module.
Comment #5
subhojit777Better don't rely on block settings. We will show block title from the template itself.
Comment #7
subhojit777