Upsell (Related Products at Checkout)

Contrib type: 
Module
Status: 
Complete and working
Moderation: 
Not ready for moderation

Downloads

Latest version: 
5.x-1.10, 6.x-1.8
Compatibility: 
Ubercart 1.x
Compatibility: 
Ubercart 2.x

This module now has a Project Page on Drupal.org. I will be adding releases asap.

Allows merchants to associate multiple products together, and offer related products before checkout. When a user checks out with a product or products that don't currently have any other products associated with it, or the number of associated products (minus the items in their cart) is too low, they will instead get a list of random products from the catalog.

To get products "related" to each other, you need to Edit the product and scroll to the bottom, where you'll find a new "Related products" select list. This is a selection of all titles in your catalog (that are published and of the node type 'product'). Choose your products and submit the changes to make them related.

A new admin area is created under /admin/store/products/upsell where you can see what products are currently associated with each other. As of 1.1, an admin area is also at /admin/store/settings/upsell where you can adjust the Customer messages as well as Node Type Associations.

This module also includes a CSS file which is added to your site whenever the block is shown.

To see it in action, go to www.rifftrax.com and add an item to your cart, or view the attached screenshots.

TODO:
- "discover" related products automatically / associate products after order submit
- show Add to Cart form buttons instead of Cart Links (make uc_cart_links not a dependency)

Version history:
Now requires Imagecache2
1.7 - Wrapped "Add to cart" and "Buy now" links in a t() function. Also added a major functionality addition: When you add Products A, B, and C to product D's list of Related Products, products A, B, and C also receive Product D as a related product. This is a reciprocal relationship.
UPDATE 2/17/2009 - Discovered an issue where reciprocal products were having their relationships destroyed, and updated with only the node id of the currently-editing product. This is fixed in the most recent 1.7 release.
1.6.1 - Bug fix
1.6 - Imagecache link added to block; empty arrays given conditional to avoid Watchdog errors.
1.5 - Fixed issue where Related Products were not being found.
- - Removed hard-coded "thumbnail" link; replaced with themed imagecache thumbnail image.
1.4 - BIG UPDATE! Settings are stored in a $GLOBAL, and the module now includes a Related Products block you can place elsewhere in the site. Thanks to bemson!
1.3.2/1 - Minor bug fixes.
1.3 Thanks to user bemson, many Drupal-related fixes including proper usage of l() and theme functions. Thanks, bemson! For his changes please see this comment.
1.2 - Fixes array errors, adds more configuration options, and adds a CSS file.
- - PLEASE NOTE: This version changes variable names, so keep in mind that you will need to go to /admin/store/settings/products/upsell again and reset your configuration, including customer messages. This is to avoid namespace collisions.
- - Other changes include:
- - - Configure how many products to show at checkout (you'll need to edit the Width attribute in uc_upsell.css)
- - - Configure whether to show random products if the number of related products found is too low.
1.1.1 - Fixes a MySQL error
1.1 - Updates, tweaks, and admin additions.
- - There is now a page at /admin/store/settings/products/upsell, where you can control Customer messages and which Node Types to reference.
- - Made database queries a little more random.
1.0 - Initial upload (working, stable, not too many config options)
- - Updated to fix a variable mismatch and change the wording to "Upsell products", not "available"
- - Updated to use db_next_id as well as a missing argument for finding image cache filepaths.


PreviewAttachmentSize
upsell-screen-admin.jpgupsell-screen-admin.jpg68.75 KB
upsell-screen-cart.jpgupsell-screen-cart.jpg158.49 KB
zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Hi, After installing your

Hi,

After installing your module, I have an error on the product setting page :

<?php
warning
: Division by zero in /includes/pager.inc on line 73.
?>
torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Hi,

Zmove, That's strange. I'm not getting that error in any of my logs... but I wonder if it's because I'm not using the latest UC code? (I'm testing on Beta 3 and live on Beta 2).

My setup has a lot of products, but even when none have any products associated, I don't see that error.

Does it tell you anything in Watchdog?

EDIT: Nevermind, I think I found the issue. If you want to fix it now, just go into the function upsell_products_admin and replace:

<?php
UC_FILE_PAGER_SIZE
?>

with

<?php
UC_UPSELL_PRODUCTS
?>

... I basically copied the code from the uc_file module but forgot to change those two variables. Whoops!

Try that and see if it fixes it. I'll be updating the module in a little while.

EDIT EDIT: Updated the tarball, please re-download and let me know if there are further problems.

--
Help directly fund development: Donate via PayPal!

zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1192
Re: Re: Hi,

Strange, I'm on beta 3 too... I don't have time to check that this week, I will try to look through the problem for the next week

storbaek's picture
Offline
Joined: 01/26/2008
Juice: 36
Only work for Product content type

Great module, but is it correct that it only work for 'Product' content type? We are using other content types as products and would like to add the upsell feature to these content types. I've been looking at the admin section and content type settings, but do not find any way of adding the feature to other content type than the default 'Product'!

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Only work for Product content type

Hey, thanks for the feedback. I will look into a select list that'll allow you to include different node types. I'll post an updated version once I've done that!

--
Help directly fund development: Donate via PayPal!

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Only work for Product content type

Updated the module to version 1.1. It now includes a new table, called uc_upsell_nodetypes, which includes what Node Types to include in the Edit field, and at Checkout. Please read my notes in the main Contrib description for more info!

I would recommend uninstalling the current module, and reinstalling it, since a new Table is created, and I haven't included a function to run an update yet.

--
Help directly fund development: Donate via PayPal!

storbaek's picture
Offline
Joined: 01/26/2008
Juice: 36
Testing gives me this error

I did some testing, but going to /admin/store/settings/products/upsell gives me the following error message:

user warning: Table 'DB_primary.uc_upsell_nodetypes' doesn't exist query: SELECT * FROM uc_upsell_nodetypes ORDER BY type in C:\xampp\htdocs\Drupal\includes\database.mysql.inc on line 172.

Also, I did a you mentioned by uninstallaing (remove folder from /modules folder and reinstall the new contrib).

storbaek's picture
Offline
Joined: 01/26/2008
Juice: 36
Adding related products

Also, how are related nodes added from the node/edit screen? The reason why it struck me is that I expect to have hundreds of nodes, which can be added as related content for upsell during checkout. With that many nodes to choose from, I expect it to provide the user with a very bad user experience!

Perhaps you can elaborate a little on this side?! Also, I could imagine that a view could be limited to only showing the nodes for which the user has 'own edit permissions' or a pager functionality as views has it...

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Adding related products

It looks like the uc_upsell_nodetypes table didn't get installed for your system. Are you using MySQL or Postgre?

And right now, unfortunately the only way to add nodes is using the product edit page, and the select list. You mention you "expect" to have hundreds of nodes, but you don't right now? If that's the case, it really only takes a few seconds to add some Related products to the list, at the edit screen. Granted, it should be easier for an admin to "discover" related products if they already have hundreds or thousands of products / nodes in their system. That's one of the things on my To Do list, unfortunately it's not a top priority at the moment. If someone wants to take a crack at an efficient way to do this, I'm open to suggestions. I have some ideas myself but they don't seem very well optimized - it can be done, it'll just have to involve a Cron job, I think.

Your idea about only showing the products for which a user has 'edit' permissions is an interesting idea... I'll have to look into it. I'm not so sure it's easy to do (I could be wrong) but, it seems like it's just easier to give them permission to edit products, if you have specific roles setup to do this then it makes it that much easier.

--
Help directly fund development: Donate via PayPal!

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3425
Re: Re: Adding related products

Version 1.1 doesn't have an update() function defined to create the new table. So version 1.1 works only for a new install but not for an update from 1.0. That accounts for storbaek's problem with the table not being found, since he was updating from the old version.

storbaek, you can execute the CREATE TABLE statement manually in your DB and that should fix things. The proper SQL to execute is found in the .install file.

<tr>.
torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Adding related products

Updated the file to include the Update function (I'm lazy, what can I say? Smiling) and also, found an error in the query that builds the nodetypes table. Please update the module if you haven't already.

--
Help directly fund development: Donate via PayPal!

storbaek's picture
Offline
Joined: 01/26/2008
Juice: 36
hehe...sql error?

Now, with your new code to run update.php I see this:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')`type` VARCHAR(32) NOT NULL PRIMARY KEY (type)) /*!40100 DEFAULT CHARACTER SET ' at line 1 query: CREATE TABLE uc_upsell_nodetypes )`type` VARCHAR(32) NOT NULL PRIMARY KEY (type)) /*!40100 DEFAULT CHARACTER SET UTF8 */ ; in C:\xampp\htdocs\Drupal\includes\database.mysql.inc on line 172

Under /admin/store/settings/products/upsell, I still see this:
user warning: Table 'DB_primary.uc_upsell_nodetypes' doesn't exist query: SELECT * FROM uc_upsell_nodetypes ORDER BY type in C:\xampp\htdocs\Drupal\includes\database.mysql.inc on line 172.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: hehe...sql error?

Yeah that's the SQL that was just fixed. You need to download the module again Smiling (Update should work now too)

--
Help directly fund development: Donate via PayPal!

storbaek's picture
Offline
Joined: 01/26/2008
Juice: 36
Will create the table manually if necesary

I do not seem to be able to run update.php and get it to work. It still gives me the same error message as before. I've also tried to remove upsell from admin/build/modules and re-activate, but still no go. Can you explain me how to create the table manually? I noticed a lot of statements in the install file - would I need to add them all? I'm really in the mood of testing now Smiling

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Will create the table manually if necesary

Sorry - there was in fact another issue with the MySQL query. Changed the way the update and the initial install for uc_upsell_nodetypes works, and tested it, and it all seems to work now! Try again with version 1.1.1., or use the code to create the table manually, if you prefer:

CREATE TABLE uc_upsell_nodetypes (
`type` VARCHAR(32) NOT NULL,
PRIMARY KEY (type)
);

--
Help directly fund development: Donate via PayPal!

HalB's picture
Offline
Joined: 02/15/2008
Juice: 16
Invalid agrument php error

I don't see this mentioned, but on a fresh install of drupal + ubercart + uc_upsell, I get ...

warning: Invalid argument supplied for foreach() in /raid/clients/dbswebstore/sites/all/modules/uc_upsell/uc_upsell.module on line 119.

... on pretty much any product hit. Putting an is_array() test just prior, seems to workaround it, though I don't know nearly enough to say if that's a proper fix.

mimetic2's picture
Offline
Joined: 08/07/2007
Juice: 478
php4?

Hi HalB. I'm not a PHP programmer by any means, but i've seen teh "foreach()" error happen on PHP4. This module might have been for PHP5?

That's worked in the past. FYI.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: php4?

Yeah, I can't say I have seen that error myself (I'm running PHP5) but I will certainly put that array check in for compatibility. It won't really "fix" anything except make it not throw the error if there are no related products to show in the Edit Node form.

I have some other changes to make including support for Options and Attributes, so I'll wait until those changes are in to release the next minor version (unless there are worse bugs to be found Eye-wink )

--
Help directly fund development: Donate via PayPal!

HalB's picture
Offline
Joined: 02/15/2008
Juice: 16
php4?

mimetic2, this is a php5 installation. foreach requires an array probably in every version of php. The db query just prior to this was returning NULL IIRC, which is possibly due to the clean install and no related/upsell products have been set up (yet). Thx.

HalB's picture
Offline
Joined: 02/15/2008
Juice: 16
php4?

I am hitting similar errors on the shopping cart page:

* warning: array_merge() [function.array-merge]: Argument #1 is not an array in /raid/clients/dbswebstore/sites/all/modules/uc_upsell/uc_upsell.module on line 332.

* warning: Invalid argument supplied for foreach() in /raid/clients/dbswebstore/sites/all/modules/uc_upsell/uc_upsell.module on line 343.

I know these aren't show stoppers, but thought they need some "official" resolution.

KillerJerseys's picture
Offline
Joined: 01/17/2008
Juice: 58
Re: Upsell (Related Products at Checkout)

torgos, great module -- this is exactly what was needed for UberCart!

Quick question: Is it possible to migrate this to the product page, as well?

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Upsell (Related Products at Checkout)

Yeah, it sure is. I'm not sure what the best way to do it is, though - a block perhaps? Maybe the uberdudes can suggest something, or if it'll just be a snippet of code in the template, that'll work as well.

Glad you like it! I'll add a product option to the next version. Thanks for the feedback.

--
Help directly fund development: Donate via PayPal!

jdblank's picture
Offline
Bug Finder
Joined: 12/12/2007
Juice: 127
Empty List

Hi, I just installed this module on my site (I am running ubercart beta 5) and it seemes to be installed but when i go to edit a product and choose the related products my list of products is empty.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Empty List

I should probably make this more clear. I think you need to go to /admin/store/settings/products/upsell and select which node types to associate in the list.

I am thinking now about making "product" already selected by default. Thanks for bringing it to my attention... will post a fix for this soon.

--
Help directly fund development: Donate via PayPal!

jdblank's picture
Offline
Bug Finder
Joined: 12/12/2007
Juice: 127
Re: Re: Empty List

OK, i was able to select the associated product but it does not seem to show up on the cart page. The customizeable message does show up.

Any ideas?

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Empty List

Not sure what you mean. Do any products show up at all? Can you attach a screenshot?

How many products does your store have and how many did you associate? Even if you don't associate any it should show 5 (or however many) random products from your site.

Send me a link or image so I can investigate Smiling Thanks!

--
Help directly fund development: Donate via PayPal!

jdblank's picture
Offline
Bug Finder
Joined: 12/12/2007
Juice: 127
Re: Re: Re: Re: Empty List

Here are two images. One is the edit page of the Product called "Payment" with the Product called "Donation" selected for upsell.

The 2nd is the shopping cart page. You can see no products are showing up.

Thanks for helping to troubleshoot.

Josh

AttachmentSize
Edit page showing Donation product selected 25.26 KB
Cart page showing no products 38.92 KB
jdblank's picture
Offline
Bug Finder
Joined: 12/12/2007
Juice: 127
Re: Re: Re: Re: Re: Empty List

Here is the code in the view source for the cart page. It still won't display associated product:

</div><div id="cart-related-products"><p>Please consider making</p><table id="related" width="100%"><tr><td><div id="cart-related-item" style="padding:5px; width:18%; float:left; text-align:center;">
<a class="buy-related-item" href="/node/"><img class="buy-related-item" src="/files/imagecache/thumbnail/"></a><br/><a class="buy-related-item" href="/node/"></a></div></td></tr></table></div>
torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Re: Re: Re: Empty List

Can you give me either temporary Admin access, or at least give me some more detail about how your products are setup?

Also do you see that the row is being created in uc_upsell_product, with an array associating the related products? I can't really narrow down what's happening here if I have more info. If you do give me Admin access, just so I can check out your setup, I promise not to break anything Smiling

--
Help directly fund development: Donate via PayPal!

bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
Wish I followed development earlier

I didn't read up on developments for this contrib, and after experiencing most of these same problems, fixed what was important to my project.

I've attached my patch, but I'm too lazy to figure out how to do this formally - ie, via UC's development channels.

This file fixes the following issues I experienced:

  1. Empty product list: Now shows list of products.
  2. Only works with 'product' node type: Lists all UC product types/classes.
  3. Incorrect image paths: Image path now considers your site config ($base_path and files directory).

I've added the following features to the module:

  1. Can now set threshold of related products, via settings page.
  2. Theme function for pane display. The default theme's html output matches the existing module - in case anyone's site depends on it. The theme function skeleton is:
    function theme_uc_upsell_related_items_pane($nodes,$custMessage) {
    // include $custMessage
    // process $nodes
    // return some html
    }

    The theme is called whether related nodes exist or not. Again, the default theme preserves the previous behavior of showing nothing if no related nodes exist.

  3. Provides new get_cart_related() function that now returns an array of (loaded) nodes. The nodes are related to the given nodes up to the threshold - otherwise, the returned list is randomly supplemented.

    Of course, I did this to separate form and functionality. Also, I'd like to use such results in a block but I didn't need it for my current project... I'll let someone else add uc_upsell_block(), or do that myself later.

    If no args are provided, the function does use the current user's cart items. If no argument is given and no cart items exist, this function will return an empty array and NOT a random set of product nodes.

    Additionally, the function sets the reference variable $custMessage , which is set to the proper message (configured by the user).

Here's what I did NOT fix, because I didn't need it right now:

  • Form select list, for associating nodes, on a product-edit page is still missing.
    Ok, I can't explain it, but something happened during my install... However, because I only needed to show *something* on my cart page, making specific associations was something I could do without. I'll look into it later.

Hope this UNTESTED patch works for you and your installation. To the UC and torgosPizza, do include what you find valuable in this file. Mind you, I did reduce the lines for filtering the final node-set.

I didn't review my comments nor removed yours, so take them all with a grain of salt.

- bemson

AttachmentSize
New uc_upsell.module file - uc_upsell.module.zip 4.57 KB
bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
Migrated changes to updated uc_upsell.module

After a quick check-in with torgoPizza, it seems I've updated an older version of this file.
I've migrated the following to the module and torgoPizza will integrate what's useful to the next version (something beyond v1.2).

  • Theme-able pane function. Same as before, so see above comment for details.
  • Revised get_cart_related_items() Same as before, see above comment for details.
  • Removed use of uc_upsell_nodetypes table The module now automatically enables associating all UC product classes to each other.

    If you're upgrading, after succesfull installation, you should remove the uc_upsell_nodetypes table from your database. (If this change gets integrated, torgoPizza will remove the relevant lines from the module's de/install routine.)

  • Updated constant names This one's minor, but I've listed the changes below, in case your scripts look for the old constants.
    UC_UPSELL_PRODUCTS   -> UC_UPSELL_MAX
    UC_UPSELL_NOPRODUCTS -> UC_UPSELL_SUPPLEMENT
    
  • Minor tweaks Mostly ui tweaks to the settings page.

Ok, again, I hope this works for you all.

I still have to handle my original installation, because I don't get the select-field for making associations on my product-edit form.

AttachmentSize
uc_upsell.module for v1.2 as zip 4.59 KB
bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
K, it works for me now...

Ok folks. I've updated my uc_upsell.module file so it works for my site. I've fixed the following problems.

  1. Associations not available to all product classes. The module now alters node-edit forms for all UC product types.
  2. Pane links don't work for non-root installations. The default theme of the module now renders links with l() - which considers clean-url status and the root directory path.

I've added the following:

  • Added perms for administrating module settings. Don't know why I did this one. Just figured access control was wise for administration pages.
  • Added links between associations and settings page. Just taking a cue from other modules I've seen.
  • Moved associations select-field in edit-node form. There is probably better placement for this form item, but it felt better inside the "Product" fieldgroup.

It works for my site now. The biggest issue was compatibility with non-standard drupal installations; mine was in a non-root directory and clean-url's was off (I've since turned them on).

As always, do test and don't just replace! Comment here and let everyone know what's wrong/missing with this patch. Also remember that this is not an official update from torgoPizza.

Look for v1.3 to contain some functionality from this file.

AttachmentSize
uc_upsell.module - "works-for-me!" version - zipped 4.88 KB
torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: K, it works for me now...

Bemson, the new code works perfectly. I've rolled it into the new version.

The only thing I added was the drupal_add_css() function to the themed cart output - that way people can still style the tags as they wish. I also added an update to the .install file that deleted the uc_upsell_nodetypes table.

Feel free to suggest more changes. I still have a few items on my TODO list, but I don't think they are of major importance. Thanks again for your hard work!

ALL USERS Please update to Version 1.3 of this module and continue testing. Let me know if you discover any bugs. Thanks!

--
Help directly fund development: Donate via PayPal!

mimetic2's picture
Offline
Joined: 08/07/2007
Juice: 478
Install fresh 1.3

So I used to have the upsell module installed, but it gave me an array error (i think i had v1.1). Anyway so I uninstalled the module and then re-installed Upsell v1.3.

I got this error:

Fatal error: Cannot redeclare uc_upsell_update_1() (previously declared in /home/ecopaper/public_html/modules/ubercart/contrib/uc_upsell/uc_upsell.install:33) in /home/ecopaper/public_html/modules/ubercart/contrib/uc_upsell/uc_upsell.install on line 58

Also the install file says v1.2

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Install fresh 1.3

I had caught that and then reuploaded the file last night as the last thing I did. Looks like the file didn't actually update. I'll post it again, please download 1.3.1.

--
Help directly fund development: Donate via PayPal!

mimetic2's picture
Offline
Joined: 08/07/2007
Juice: 478
Re: Re: Install fresh 1.3

Soo for some reason no products are showing up on the cart page. I went to cart and the "upsell" pane is in checked.

Is there something else i have to do?

EDIT: I didnt make product associations yet. I did it for an item in my cart and it started working. I thought that if you didnt have an association it would show up randomly (i had it checked) but this isnt the case.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Install fresh 1.3

How many did you select? Is it more than the threshold configured in Admin? If it's less than that, try changing that number or Check the option to "Show random products if needed"..

EDIT: Looking at it again on my test box, I do notice some inconsistencies. It does work but not quite how I expected. Try checking the box, or changing the value of products to show and see if that helps. Meanwhile I'll make some changes to the code to try and improve it.

--
Help directly fund development: Donate via PayPal!

bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
Suggestion Upsell block and configuration features

Ok, I had some extra time and decided to implement the Upsell module to suit my needs (again). I've listed my additions and changes below, in varying degrees of detail.

  • Upsell Items block A single block is now available for use on pages other than the cart; it disables itself when in a cart path. There are many simple options to determine how related items are found. The "Upsell Items" block's features are detailed later.
  • Consolidated variables I've removed the constants and defined a single array to contain the Upsell configuration. This stemmed from an interest to reduce hits to the server and structure Upsell's features
  • Pane theme function is now "theme_pane_upsell" Do rename your theme function accordingly. My concern was ridiculously long function names and protecting the "_pane" hook from collision/confusion. (The previous theme function was "theme_uc_upsell_related_items_pane"...)

Internally, overall, I've isolated the functionality of the module in to a separate function, called uc_upsell_get_associate_nids(). Like the original get_cart_related_items() routine, this function is recommended for developer use but is not a direct replacement.

The uc_upsell_get_associate_nids() function returns an array of nids (not nodes that have been linked/related/associated to the given nodes. This function takes the following arguments.

source (array)
The required set of nids (or nodes), from which the related products are sought.
max (integer)
An optional integer that limits the number of returned nids. When 0 or NULL, all associate nids are returned.
filter (array)
An optional array of nodes that filter the returned array. Note: Nodes from the source array are automatically filtered

The other function of note could be considered a replacement to get_cart_related_items(), as it also returns associate nids and sets a referenced string variable. uc_upsell_resolve_associates() returns the nids displayed by the Upsell pane and block. The function considers the current Drupal path along with the module's settings, to determine how to find associate nodes.

"Upsell Items" block
The upsell block provides three modes.

  1. Product page Renders the block on product pages only. You can also specify whether and how to supplement the target number of related products. On product pages, Upsell will use the product node as a source for related nodes.
  2. Non-Product page Renders the block on non-product pages only. Unlike a product or cart page, you must specify the sources for finding related nodes (cart or random). You can also require that the cart is not empty, in order to render the block.
  3. Both Upsell will use each mode's options and render block on all pages. Of course, this does not common general block visibility settings, and page by page control is still preserved.

The main reason I provide these modes is that I need to show different messages/titles based on the type of page. It seemed easier to provide a switch here, rather than insert such logic manually via the standard visibility settings.

Theming the "Upsell Items" block
I did provide a default upsell items block listing, but it's a rudimentary list. I couldn't figure out how to declare a themeable function for the Upsell block (e.g., "theme_block_upsell"), so I decided to send an extra "related" property to your theme_block function. Thus, the associate nodes are accessible to your block function or template file as $block->related. Use this array of loaded nodes to render thumbnails and cart links as desired.

NOTE: This file will likely ignore any existing settings you've made, since it's using different variable names. Be sure to migrate your original settings after installing this contrib file.

AttachmentSize
v1.4 alpha - uc_upsell.module.zip 8.28 KB
deegree's picture
Offline
Joined: 11/07/2007
Juice: 111
the hero is back

thanks for this great module which saved my head because my boss was wondering that ubercart doesn't have the upsell feature...

Great Job, great Man Laughing out loud

-Dee

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
You mean great "men" I

You mean great "men" Smiling I merely started it, bemson took it to the next level!

In any event, you're welcome.

--
Help directly fund development: Donate via PayPal!

bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
Quick fix for error that occurs when you remove associations

I ran into an error when viewing a product after removing all of it's associations.

In uc_upsell.module, replace these lines:

$related = db_result(db_query("SELECT related_products FROM {uc_upsell_products} WHERE nid = %d", $nid));
if ($related) $ary = array_merge($ary,unserialize($related)); // Don't destroy the array!

...with these lines:

$related = unserialize(db_result(db_query("SELECT related_products FROM {uc_upsell_products} WHERE nid = %d", $nid)));
if (is_array($related)) $ary = array_merge($ary,$related);

This bit of type checking allows the contrib to continue saving null values when you remove all associations from a product. This way, we can avoid giving array_merge a bad argument.

Hope this helps anyone who ran into this issue!

...Perhaps the contrib should remove the row entirely, instead of setting it to an serialized representation of null/empty-array?

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Quick fix for error that occurs when you remove associations

Agreed, I can look into this or you can if you get to it first. (You seem to be doing a lot with this module lately anyway Smiling)

One other thing I need to tackle that's of importance is the ability to distinguish Attributes and Options. At least with the latest versions of UC you can set an attribute to be required before an item is added to cart; but not everyone chooses this option. I'm thinking the "Add to cart" links could, when Attribute/Option combos are found, cycle through the first 3 (limit it to 3 or so) and if there are more then say "More options..." which will link to the main product node.

--
Help directly fund development: Donate via PayPal!

bemson's picture
Offline
Joined: 02/11/2008
Juice: 25
Error fixed and cart-links in pane/block

Regarding the error... The line changes I suggested handled it for me.

Regarding add-to-cart links in a pane/block...
Is requiring attributes before adding-to-cart a preference? If so, then go ahead and include that logic when building the default theme. However, I'd leave the rendering and logic up to the developer.

I think your enhancements only apply to your current site. My Upsell pane and block, for example, use a different imagecache preset I and don't include a cart link.

I'm in #ubercart, and welcome discussing this further.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Error fixed and cart-links in pane/block

Updated the module to 1.4. It's modified slightly since the one you posted as Alpha. Please test and let me know if it works for you all.

--
Help directly fund development: Donate via PayPal!

zcferres's picture
Offline
Joined: 04/06/2008
Juice: 55
product kit support

How about adding functionality for product kit support? This would allow us to show related packages that include the product.

Thanks!

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: product kit support

Good idea.. I'll look into how exactly to accomplish that, and if it's easy enough, post another update.

--
Help directly fund development: Donate via PayPal!

72dpi's picture
Offline
Joined: 10/07/2007
Juice: 134
Re: Re: product kit support

I love this plugin. I have an issue tho, not on my localhost, but my live site. Whenever I go to enable it, I get the whitescreen of death.

it's so bad that I have to disable it via phpmyadmin.

Anyone else had this?

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: product kit support

Hmm, that's odd. I don't get that (but my server is pretty robust). Can you add the Error Reporting code to your index.php file, and let me know what the error is that you are getting? Sounds like it's going to be a Fatal error, possibly a memory issue.

--
Help directly fund development: Donate via PayPal!

sleepingmonk@drupal.org's picture
Offline
Joined: 01/20/2008
Juice: 81
A few things...

I'll try to be concise.

1) Tried using 1.4 but it wouldn't display related items in the cart pane. So I tried 1.3 instead.

2) The file attachment on this page says uc_upsell-1.3.2.tar.gz but on install says 1.3.1

3) I got this to work but images weren't showing up. The image url was wrong. I used a print_r on $conf and found there is no $conf['file_directory_path'] which the theme function uses to build the path. Should this exist in the $conf array? Any ideas why mine doesn't? Manually editing the file path in the module gives me images now.

4) In both versions I get a lot of duplicates on the list at admin/store/products/upsell I've attached a screen cap. However, the node edit page shows the proper items in the "Related Products for Upsell:" select box. Again, this happens in both versions for me.

This site is in development and I'm still using Ubercart Beta 7. I've dug around but haven't found anyone with the same problems. Maybe someone could shed some light on whether these are Upsell bugs or maybe caused by something else.

As it stands right now it seems "usable" but quirky. A very needed module, thanks for the hard work!

AttachmentSize
Screenshot.jpg 33.19 KB

"I've had this birthmark since I was born." --JB

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
sleepingmonk, Please update

sleepingmonk,

Please update to version 1.5. I did some digging, and it turns out that in bemson's latest revision, the code was looking for a variable called $product_nid which only existed if you were on a product node. I fixed this, so that if $product_nid isn't set, to use the $cartNids array. Related products are now showing up.

I also changed the thumbnail display to use the imagecache configuration, which I assumed it was doing, but didn't take into consideration filepath differences. Now it's using a themed imagecache function to determine the location of the product's image and use the thumbnail preset's config. It works for us, so please do try it on your site and let me know if you still have issues.

--
Help directly fund development: Donate via PayPal!