Upsell (Related Products at Checkout)

warning: parse_url(irc:///ubercart) [function.parse-url]: Unable to parse url in /var/www/vhosts/www.ubercart.org/sites/all/modules/nofollowlist/nofollowlist.module on line 121.
Contrib type: 
Module
Moderation: 
Failed code review
Status: 
Complete and working
Compatibility: 
Ubercart Beta 7
Latest version: 
1.6.1

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

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.

- An enhancement I'll be making soon to this part of the process include "walking" through the list and adding the current product you're on, and the other products, to each product's association. For instance, if you are editing Product A, and associate it in the Edit menu with Products B and C, the script should automatically add A and C to Product B's "related" list, and then do the same thing with Product C - adding A and B to its array of related products.

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/products/upsell where you can adjust the Customer messages as well as Node Type Associations.

Node Types: As of version 1.1, there is now the ability to associate node types other than the default "Product" to the Upsell system. In the admin area mentioned above, you can select (using checkboxes) which node types to include in the admin area (which lists all products and their related products), in the Product Edit form, and during Checkout. What this also means is that, when a Node Type is removed in the admin area, nodes of that particular type will no longer display in the Edit form, in the Upsell Admin area, or during Checkout. The nodes are technically still associated, but will not show up.

However, if you update a product, the array IS updated to not include products of the now-removed types. In other words, the associations are destroyed at that point. (If you are confused, please PM me. I tried to make it as hassle-free as possible, and while it may not be the most convenient system, it allows for flexibility without introducing new obstacles).

As of version 1.2, there is a CSS file included; these values can of course be overruled by your style.css. Keep in mind the only element given any attributes is the div#cart-related-item (to space out the thumbnails).

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:
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.

AttachmentSize
upsell-screen-admin.jpg68.75 KB
upsell-screen-cart.jpg158.49 KB
uc_upsell_1.6.1.tar.gz9.65 KB



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.
?>

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.

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

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'!

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!

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.

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).

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...

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.

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.

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.

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.

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)

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

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)
);

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.

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.

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 )

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.

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.

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?

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.

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.

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.

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?

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!

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
Cart page showing no products38.92 KB
Edit page showing Donation product selected25.26 KB

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>

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

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.zip4.57 KB

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 zip4.59 KB

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 - zipped4.88 KB

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!

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

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.

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.

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.

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.zip8.28 KB

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

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.

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?

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.

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.

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.

product kit support

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

Thanks!

Re: product kit support

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

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?

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.

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.jpg33.19 KB

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.

Fixed one more bug.

1.5 almost worked perfectly. I still had a problem if I added an item to the cart that didn't have any related items. It would throw a warning that the second argument in array_merge() wasn't an array.

This would then not show ANY related items from any of the products in the cart so just turning off the warning messages was not a solution.

I modified the if statement around line 826 to unserialize and check for array. It all works now.

Updated module attached. Should go into latest version I think.

----------------

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

AttachmentSize
uc_upsell.module.zip8.49 KB

Re: Upsell (Related Products at Checkout)

when using your module v1.5 i'm getting the following error:

warning: Invalid argument supplied for foreach() in /var/www/web2/html/drupal/includes/common.inc(1352) : eval()'d code on line 46.

any idea?

ps: drupal 5, php 5

edit: i found the problem, it wasn't upsell's fault.. thanks for your attention anyways Eye-wink

Re: A few things...

I am experiencing exactly the same problems as you.
In regards to the image path, I hardcoded mine as well, I also hardcoded the imagecache directory into the module for a quick fix to the images not showing up. I disabled the related products from showing in the cart due to the problem with duplicates.

edit: im using php5, drupal 5, and latest ubercart/drupal prepackaged release.

Re: Re: A few things...

Yeah this is something I've changed in the latest code revision; I'll post an update as soon as I can. The new code uses the imagecache directory from config and avoids any of these issues (both in the cart and the block).

Related products on product page

Hi,

On www.rifftrax.com is see also related products on the product page.
I find this more interesting, is this also possible with this module.

Re: Related products on product page

Yes that's just the Upsell block. When you activate the module you'll see a block in your admin/build/block screen. It doesn't take much to add the block to your site layout.

Getting images to work

How do you get images to work?

Re: Getting images to work

I got images to work but I had to change the "Preset namespace" in imagecache from uc_thumbnail to thumbnail.

Re: Re: Getting images to work

Hmm.. interesting! I had no idea that the preset name had changed for the default in Ubercart. That may be what caused some other images not appearing (for other users). Nice catch. Thanks!

(Also to reiterate, this will be a non-issue once there is a config area to choose which preset(s) to use for the Upsell blocks.)

Re: Re: Re: Getting images to work

That preset changed names between RC4 and RC5. It poses a problem, as you found out, for contributions written to the earlier spec, and for custom product pages/catalogs coded to expect the old preset name.

default value for reference value

Parse error: syntax error, unexpected '=', expecting ')' in /usr/local/psa/home/vhosts/igadgets.be/httpdocs/sites/all/modules/ubercart/uc_upsell/uc_upsell.module on line 723

Line:
function uc_upsell_resolve_associates(&$msg = '') {

Is it a problem with a default value for a reference parameter for some php version?

How can I solve this?

I think my server uses PHP 5.

Jurgen.

Re: default value for reference value

Could be. Try removing the ='' from the function so now it just looks like this:

<?php
function uc_upsell_resolve_associates(&$msg) {
?>

I'm not quite sure why the $msg var is getting referenced but then assigned an empty value in that function. It is set to that blank value before the function uc_upsell_resolve_associates gets called anyway. It seems like cruft to me so I'll take another look at it in the near future.

Let me know if that gets rid of your error.

Thanks

I ´ll allready tried that, and yes it works.

Remarks

On product page:

1)
I want to display the related items before the reactions.
But, the description of a product and the reactions aren´t blocks, they are just a part of the page.

Someone knows a way...
See http://www.igadgets.be/nl/silverlit-picooz

2)
Set product A to a related product B
Automatic B is a related product to A. This does not work! Is this mentioned.

Re: Remarks

1) can probably be adjusted by changing the weight of your upsell block.

2) is a feature that has not been developed yet, but is something I hope to accomplish in the near future.

Me again

3)
I´ve got a serious problem, the first product I add as related item isn´t displayed.
Then I can add other items, that were displayed. But the first one is never displayed.

I can bypass this to first add a non-related item.
For the products I have done this for now, I can reset in DB....

Does anybody know this problem.

Updated: If I log off, I see the first added item. Ok for me.

1)

I don´t think so.
If I give it a weight of -10, then it is also placed below on the page.
It is the only block.

Re: 1)

Can you create an Issue for these things you are seeing? Thanks.
http://www.ubercart.org/issue

Hi Torgoz... Images still

Hi Torgoz...

Images still not working for me. I think it has to do with my configuration.

The images point to:
http://www.ecopaper.com/files/imagecache/thumbnail/files/MangoWrap.jpg

but the actual image is at: http://www.ecopaper.com/files/imagecache/product/files/MangoWrap.jpg. I have no idea why that image doesnt go in thumbnails. I'm pretty sure there is something wrong with my configuration, but that being said, it would be nice if i could change where everything links to.

Re: Hi Torgoz... Images still

It looks like you don't have a preset called "thumbnail" - if you create one, the files should start showing up. Smiling Or, you could change "thumbnail" to "product" in the code - since "product" is the name of the preset that's working.

Re: Re: Hi Torgoz... Images still

hmm i do have a thumbnail category, how weird is that? Something is def messed up imn my config. I'll go in the code and change it to product Smiling

Thanks!

Re: Re: Re: Hi Torgoz... Images still

Sweet, ok its working great... except, even though on my block congiguration page i have it so it supposed to suppliment products from both the cart and random products but on Product pages it's not doing this.

ANy ideass?

Re: Upsell (Related Products at Checkout)

Hi. How do I display the upsell block items horizontally in the block rather than the default vertical view? Thanks!

Re: Re: Upsell (Related Products at Checkout)

That's what I am doing on our product pages:

http://www.rifftrax.com/rifftrax/batman-and-robin

I can't remember what the default theme function is. If it's using li and ol elements (ordered list), then you can just change the theme elements to use divs instead. I thought this was how my latest version was, however, I'll check to be sure. If that's the case you only need to edit your CSS to allow for float:left and make sure the rest of your layout doesn't break the block's layout.

Re: Re: Re: Upsell (Related Products at Checkout)

Thanks. Yeah, this css code worked for me:
.upsell-block-product { float: left; padding: 2px; text-align: center; width: 150px; }

Re: Upsell (Related Products at Checkout)

This looks like a great module! One question:
Is there a specified "field" that I can import into using node_import in order to fill the 'related products' table? I'd like to be able to set up a column in my CSV for node titles (or something else) that allows them to be imported as related to another node.

Thanks for 'filling a void' in ubercart! great contrib.

Re: Re: Upsell (Related Products at Checkout)

It's not a field, but if you look in the module there is a function that bemson created called uc_upsell_get_associate_nids($source, $max, $filter) which you should be able to hook into. I'm not sure how you're creating your CSV, but if you're doing it programmatically, you could see how the code is doing it and then add that function to your CSV generation script.

(Worst case scenario you can just duplicate the code in your own module or something). But basically the relationship nodes are stored as a serialized array in another table. And that's what the function gives you. You pass the argument $source as an array of nids you want to fetch the related nids for.

Hope that helps.

Re: Re: Re: Upsell (Related Products at Checkout)

Right now the CSV is just from an old site DB, waiting to be uploaded into Ubercart. I noticed that CCK has a "node reference" field type, is there any way (/is there any benefit) to tie this module in with that field? I would think that would enable easy import/export because its just a CCK field, but I also know very little about CCK/node reference fields.

Product kit support

Any news about the product kit support?

Re: Product kit support

That is a feature I had in there at one point, but it got removed. I'll look into adding it back in.

Drupal CVS

Any chance of getting this module into the Drupal CVS?

Chris Albrecht

Re: Drupal CVS

I'll need to apply for a CVS account, but I'd definitely like to have it in there.

Also, with regard to product kit support, the thinking I had was wrong - you can associate product kits as "Related" to a product but so far I haven't done this the other way yet. Perhaps this weekend I'll have a chance to give it a look.

EDIT: I just applied for my CVS account. Here's hoping!

Re: Re: Drupal CVS

tP, lemme know if you have any trouble getting the account.

Re: Re: Re: Drupal CVS

I received the approval email from Drupal.org CVS admins today.

I'll work over the weekend on getting my Contribs up there. It may take a bit because I want to read up on it as much as I can. If anyone has any pointers feel free to PM me either here or through my Contact form on Drupal.org.

http://drupal.org/user/151333

Adding space under upsell block in product page

I tried messing with the margin or padding using the following css:
div#block-uc_upsell-0
but it doesn't seem to do anything. Can you help? As it is the block is too close to the footer and I just wanted to add some space underneath the upsell block when it shows up on the product page. Thanks!

Re: Adding space under upsell block in product page

Can you send me a link?

EDIT: Here's a solution. You'll need to figure out the height of your Upsell block, and specify it in your CSS, along with the padding you want. For instance:

div#block-uc_upsell-0 {
  height:200px;
  padding-bottom:10px;
  width:100%;
}

That'll make the overall containing div 200px high and take up 100% of its parent element. HTH.

Upsell customizations

I've been using the upsell module for a while, and I just finished making some modifications to uc_upsell.module that add two pieces of functionality:

-Select product kit nodes in addition to product nodes
-Update the related products listings on other products

Product kit support is be pretty transparent - if you make the changes below, you will be able to select product kits to products' related products lists and vice versa. The product kits will just show up in the alphabetical listing.

When adding product B and C to product A's related products list, these modifications will also update product B and C to include product A. When editing the related product list, if product D is removed from product A's list, A will also be removed from D's list.

These modifications do not add any configuration options, they just change the functionality of the module.

I've changed two functions. First, in order to view the related products section of the edit form on product kits, add these lines to the uc_upsell_form_alter function.

1) around line 142:

<?php
$prodTypes
= array_keys(uc_product_node_info());
//add the line below
$prodTypes[] = 'product_kit';
?>

2) around line 160:

<?php
//change this
$sqlProdTypeString = "('" . implode("','",array_keys(uc_product_node_info())) . "')";

//to this
$sqlProdTypeString = "('" . implode("','",$prodTypes) . "')";
?>

To activate product kits but not add the other functionality, near line 394

<?php
$prodTypes
= array_keys(uc_product_node_info());
//add this line
$prodTypes[] = 'product_kit';
?>

To add all of the functionality, replace the uc_upsell_form_submit function with the function below.

<?php
function uc_upsell_form_submit($form_id, $form_values) {
// reduce to form's node type
$ntype = preg_replace('/_node_form$/i','',$form_id);
// get list of product types
$prodTypes = array_keys(uc_product_node_info());
//include product kits also
$prodTypes[] = 'product_kit';
   
/*  create an array of selected related products and
     add the current product to the related products lists for each of them  */
if (in_array($ntype,$prodTypes)) {
  foreach(
$form_values['relatedProducts'] as $product) {
  
$products[] = $product;
  
//drupal_set_message(t('Added '.print_r($product, true) .' to ' . $form_values['nid']));           
  
$ary = array();
  
$ary[] = $form_values['nid'];
  
$related = db_result(db_query("SELECT related_products FROM {uc_upsell_products} WHERE nid = %d", $product));
     if (!
$related) {
      
$upid = db_next_id('{uc_upsell_products}_upid');
      
db_query("INSERT INTO {uc_upsell_products} (upid, nid, related_products) VALUES (%d, %d, '%s')", $upid, $product, serialize($form_values['nid']));
      
//drupal_set_message(t('Inserted '.print_r($form_values['nid'], true) .' to ' . $product));
    
} else {
      
$ary = array_merge($ary,unserialize($related));
      
$ary = array_unique($ary);
      
db_query("UPDATE {uc_upsell_products} SET related_products = '%s' WHERE nid = %d", serialize($ary), $product);
      
//drupal_set_message(t('Added '.print_r($form_values['nid'], true) .' to ' . $product/* . ' - Array: ' . serialize($ary)*/));
    
}
}
 
//Get the list of related products for the current product
 
$currentnids = unserialize(db_result(db_query("SELECT related_products FROM {uc_upsell_products} WHERE nid = %d", $form_values['nid'])));
 
//Delete current product from the related products list for any products that are being removed
foreach ($currentnids as $currentnid) {
   if (!
in_array($currentnid,$products)) {
    
$nidarray = array();
    
$nidarray[] = $form_values['nid'];
    
$updatenids = unser