Hello torgosPizza,
hello upsellusers,

i know, still requesting support for a 5.x module is kinda odd. I understand if you don't find time to support the 5 branch anymore. The module is awesome btw, thanks a million! There is this little thing i'd like to understand and fix if possible in our shop.

Say, i got related products A, B, C from product class1 (nodtype1)
I got related products D, E, F from products class2 (nodetype2).
I turned off to show random products. Everything else is default.

What works: i put A in cart. Upsell offers B and C. Fine.
I remove A from cart and i put D in cart instead. Again fine: Upsell offers E and F.

Now i put A back in cart, so we got A and D in cart. Upsell should now offer B, C, E and F as they are related to A nd D in cart, right? But my test-sites (one production-copy and one minimal fresh drupal5/ubercart install) keep offering me E and F only.

With many tests with more nodes, in various combinations, various settings etc. it became clear that no matter what combination, the upsell-cartpane derives its related offers solely from the _last item in the cart_.

Is there anything i can do to make it show related items from all items in cart?
I can undertand and work with code in modules a little bit, do changes here and there but can't code much myself.

Any suggestion would be appreciated. (if not to update to drupal6, ;) i know i know)

Stephan

Comments

Stephan_M’s picture

I attached a screenshot to show the problem. Related products B and C are missing in cartpane.

Stephan

Stephan_M’s picture

StatusFileSize
new32.48 KB

Doh, i stared at the code, meddled and had luck! At first glance it works (see screenshot) - unbelieveable. Here is what i changed. Can you take a look at it, please?

function uc_upsell_get_associate_nids
....
  foreach ($source as $nid) {
    if ((is_object($nid) && $nid->nid) || (is_array($nid) && $nid['nid'])) $nid = (is_object($nid)) ? $nid->nid : $nid['nid'];
    if (is_numeric($nid)) {
      $sought[] = $nid;
      $config = uc_upsell_get_config();
      $product_types = array_values($config['global']['types']);
      $products_query = "('". implode("', '", $product_types) ."')";
      $related = db_result(db_query("SELECT `related_products` FROM {uc_upsell_products} WHERE nid = %d", $nid));
      if (is_array(unserialize($related))) {
        $ary = array_merge($ary, unserialize($related));
        // ##### HERE IS WHERE THE TWO LINE WERE ######
        // #####################################
      }
    }
  }
  // #### I MOVED THOSE TWO LINES HERE, filtering needs only to be done once on final result, right? ####
  $ary = uc_upsell_get_types_array($ary);
  $ary = uc_upsell_filter_types($ary);
  // ##############################

  $ary = array_diff(array_keys($ary), $filter, $sought);
  $ary = array_unique($ary);
......

cheers,
stephan

torgospizza’s picture

Will take a look. Thanks... that chunk of code has always given me grief. Hopefully it won't break other things, though...

haysuess’s picture

Version: 5.x-2.3 » 6.x-1.20

I have the same issue in version 1.20 for Ubercart 2. Is there a known fix for it or known cause? I'd love to have upsell working properly as it should boost our sales by four figures every week or two.

EDIT: This also causes an issue where it will not display additional taxonomy items or random items to fill the rest of the available upsell spaces in.