Hi,
I love this module, thanks for building!
It is working great on node pages. But somehow on views pages it is showing NULL items in cart..?
So when I select an item, and go to another nodepage, fine, It shows 1 item in cart,
When I go back to a views page, the block is empty again! again node page 1 item in cart.
I can show you my site if you want it?
Thanks for going into this! greetings, Martijn

Comments

summit’s picture

Also on custom panels/ctools pages, empty shopping cart block is shown!
greetings, Martijn

summit’s picture

Hi,
Using the code from here: http://drupal.org/node/876620#comment-3306396 I got the microcart working for views and panels pages, only on the homepage it is not working.
Is something different from the homepage?

My added code is:

function uc_microcart_metadata() {
  $meta = array(
    'count' => 0,
    'total' => 0.00,
  );
  $cid = uc_cart_get_id();
  $contents = uc_microcart_get_contents($cid);

  foreach ($contents as $item) {
    $meta['count'] += $item->qty;
    $meta['total'] += $item->qty * $item->price;
  }
  return $meta;
}

//http://drupal.org/node/876620
function uc_microcart_get_contents($cid = NULL, $action = NULL) {
  static $items = array();

  $cid = $cid ? $cid : uc_cart_get_id(FALSE);

  // If we didn't get a cid, return empty.
  if (!$cid) {
    return array();
  }

  if ($action == 'rebuild') {
    unset($items[$cid]);
  }

  if (!isset($items[$cid])) {
 
    $items[$cid] = array();
    $result = db_query("SELECT c.*, n.title, n.vid FROM {node} n INNER JOIN {uc_cart_products} c ON n.nid = c.nid WHERE c.cart_id = '%s'", $cid);

    while ($item = db_fetch_object($result)) {
      for ($i = 0; $i < count($items[$cid]); $i++) {
        if ($items[$cid][$i]->nid == $item->nid && $items[$cid][$i]->data == $item->data) {
          $items[$cid][$i]->qty += $item->qty;
          continue 2;
        }
      }
  
      $product = node_load($item->nid);
      $item->cost = $product->cost;
      $item->price = $product->sell_price;
      $item->weight = $product->weight;
      $item->data = unserialize($item->data);
      $item->module = $item->data['module'];
      $item->model = $product->model;

      // Invoke hook_cart_item() with $op = 'load' in enabled modules.
      foreach (module_list() as $module) {
        $func = $module .'_cart_item';
        if (function_exists($func)) {
          // $item must be passed by reference.
          $func('load', $item);
        }
      }
      $items[$cid][] = $item;
    }

    // Allow other modules a chance to alter the fully loaded cart object.
    drupal_alter('uc_cart', $items[$cid]);
   
  }

  return $items[$cid];
}

Thanks for looking in homepage issue still, and may be this code, or similar for the case, can be added?
greetings, Martijn

summit’s picture

Hi,
I got it working with above code..but...it is not working correctly with caching.
My homepage then shows not the right amount of items in the cart.
It shows 1 if there are 2 in, it shows 0 if there is 1 in....

Without caching with above code it is working!

greetings,
Martijn

summit’s picture

Title: Module not working on views pages, working on node pages! » Module not working correct on homepage when pages are cached

Changing title. Greetings, Martijn

summit’s picture

Hi looking further, may be a same sort as http://drupal.org/node/463602#comment-1970992 can help?

<?php
      jQuery.getJSON( Drupal.settings.basePath + 'cart/ajax/update',d,updateAjaxCart);
    return false;
  });
  // Added this line as per patch #6
  jQuery.getJSON( Drupal.settings.basePath + 'cart/ajax/update',{},updateAjaxCart);
})

function showAjaxCartMessage(content)
?>

and in themes template.php something like:

<?php
function mytheme_uc_cart_block_summary($item_count, $item_text, $total, $summary_links) {
  // We have to do this to make sure that jquery.ajax.cart.js is loaded each time the cart is.
  if(module_exists("uc_ajax_cart")) {
    _uc_ajax_cart_load_res();
  }
}
?>

How do I alter this code to work with uc_microcart?
greetings, Martijn

dicreat’s picture

subscribe

rich.yumul’s picture

to get around the caching issue, yes, I believe an AJAX based solution would probably be best.

We'll have to include it in the next revision, unless somebody submits a patch... :)

summit’s picture

Hi, A AJAX based solution is welcomed very much!
Thanks in advance for building it in the next revision if no patch pops up..
( I am not a AJAX programmer, sorry).
greetings, Martijn

rich.yumul’s picture

You might try the patch here, http://drupal.org/node/1228580#comment-4916974

Would that possibly help?

summit’s picture

Hi, I abondened project, so am not able to test anymore. May be other can test for you.
Thanks for your assistance and reply.
greetings, Martijn