It's possible to have items in the cart that do not have a node id (fee items for example). The code in uc_upsell_get_cart_nids() does not check for valid node ids before it generates an array:
<?php
function uc_upsell_get_cart_nids() {
// Get cart nids, as a base filter
$cart_nids = array();
$user_cart = uc_cart_get_contents();
foreach ($user_cart as $cart) {
$cart_nids[$cart->nid] = $cart->nid;
}
return $cart_nids;
}
?>
This, combined with the code at line 159 of uc_upsell_core.inc (in the uc_upsell_get_associate_nids() function) can cause issues if empty node ids are returned. The code in the uc_upsell_get_associate_nids() uses a foreach loop to iterate over the $source items (which are the cart node ids), BUT it replaces the $related variable on each iteration with whatever the last one is (this seems like it's another issue in itself -- it should ADD items to $related, not replace them).
In the case where the last item in your cart is a fee item without a node id, this causes the upsell block to NOT be displayed at all.
Simple fix is to add an "if (!empty)" around the "$cart_nids[$cart->nid] = $cart->nid;" code above.
Patch coming soon...
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | uc_upsell_empty_nids-2139451-1.patch | 421 bytes | m.stenta |
Comments
Comment #1
m.stentaThis patch ensures that the uc_upsell_get_cart_nids() does not return any empty node ids.