Hi, I thought I would post an issue up here, as it seems I have a problem on my server relating somehow to this module.
A similar issue is described here, though the solution is not what worked for me. - http://www.ubercart.org/forum/bug_reports/8693/anonymous_user_add_cart_d...
The problem I found was that the $_SESSION['uc_cart_id'] was changing on every page and when adding to cart, while the item did appear in the database to indicate it had been added, the session for the anonymous user changed, therefore losing its connection with the cart set up for them.

Bascially, after a lot of running around, I found that the solution to my problem was to disable the stock manager module - all other modules stayed enabled and unchanged and my problem was gone.
I have not looked into the operation of the module yet, though I might do, to see if I can figure out why. Its worth pointing out that the problem did not occur on other server setups I was running on. I am using a server through Fasthosts UK, on Linux. Other servers I have used seem to be OK.

Does anyone know why this module might alter the SESSION variable and why? Enabling this module reproduces the error, so it has to be something to do with this module!

CommentFileSizeAuthor
#9 uc_multi_stock.patch2.27 KBAlun

Comments

akolahi’s picture

Priority: Minor » Normal

I am having the exact same issue and it is easily reproducable. When Stock Manager is enabled anonymous checkout does not work. When it is disabled it works. I am using Ubercart 2.3 and the latest dev of Ubercart Marketplace.

sysrover’s picture

Assigned: Unassigned » sysrover

Hi i found problem.
This module use uc_cart_get_contents to get items from cart, but in uc_cart module this function make a little thing:

if (empty($items[$cid]) && isset($_SESSION['uc_cart_id'])) {
      // As their cart is now empty, there is no need to keep the cart ID in the session anymore
      unset($_SESSION['uc_cart_id']);
    }

Thats why ufter using this function uc_cart_id was delete, and all cart content was lost.

Solution:
I dont want change uc_cart module, thats why i make copy of uc_cart_get_contents without this no need code and put it to our uc_multi_stock module.
here is

function uc_multi_stock_gett_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];
}

And change usage of uc_cart_get_contents to uc_multi_stock_gett_contents:

// get the product quantities already in the cart
$items = uc_multi_stock_gett_contents();

Alun’s picture

Status: Active » Reviewed & tested by the community

Wonderful.
This fixed the issue for me! Thank you!
Apologies for the late feedback, I had been working without the module, but with it is better.

summit’s picture

Hi,
Is this fix committed already?
Thanks a lot in advance,
greetings,
Martijn

Alun’s picture

Hi Summit, this fix is not committed yet. I had a word with the developer, I might be able to commit the fix myself. I'll see if I can get a patch for you in the meantime.. will post here when I can.
Al

longwave’s picture

I can't reproduce this issue with Ubercart 2.4. In Ubercart 2.3 there were issues with the cart ID, but these should have been resolved in 2.4...

summit’s picture

Hi Alun, Any time may be for the patch please?
Thanks a lot in advance for your response.
greetings, Martijn

Alun’s picture

Hi summit, I'll get this patch done soon, sorry its taken so long, it slipped my mind! Can you let me know if you are having the same problem after updating to Ubercart 2.4?
Either way I'll post a patch and you can let me know if it works.
Thanks
Alun

Alun’s picture

StatusFileSize
new2.27 KB

Here is the patch, but given that this should be fixed in the latest Ubercart, I don't see a point in committing it to code, since it was only a workaround anyway!
Regards
Alun

Alun’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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