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:

  1. Add $block['content'] = t('Shopping cart'); in the if-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?
  2. Remove $block['subject'] = t('Shopping cart'); from else-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

subhojit777’s picture

Issue summary: View changes
subhojit777’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Component: Code » User interface
Status: Active » Needs work

Thanks 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 = '').

subhojit777’s picture

From 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.

subhojit777’s picture

Or 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.

subhojit777’s picture

Better don't rely on block settings. We will show block title from the template itself.

  • subhojit777 committed 651aa8c on 7.x-1.x
    Issue #2424311 by szymonjankowski: Block title is not appearing after...
subhojit777’s picture

Status: Needs work » Fixed

  • subhojit777 committed 651aa8c on 7.x-2.x
    Issue #2424311 by szymonjankowski: Block title is not appearing after...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.