Able to Purchase vs. Coming Soon

Posts: 1314
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I mentioned this in a thread about Ryan's new Add to Cart Links API code he's working on, and wanted to start a new topic to see what the demand would be.

With our current system, we are able to create a new product but prevent it from being added to someone's cart. This is especially helpful when we have a product that's Coming Soon, or a preview of a product, etc. - that way we can announce it, even if it's not necessarily available to purchase yet.

What would it take to get something like this created? Either a new module is fine but I think this type of permission would be fairly easy to implement into core. Just a checkbox or select list that would be a boolean / yes/no value. "Can this item be added to cart?"

Unless there is already a way to do this - I have checked but came up empty handed.

I understand the UberDudes are way busy, and if this is something that wouldn't be too hard, I could attempt writing a module for it. I would just need a few pointers to get started and maybe I can take a crack at it, if that's what it takes.

What do you think, sirs?

--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com

Posts: 1314
Joined: 08/14/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.

I was able to do this pretty easily using CCK and creating a new module. Unfortunately I haven't quite figured out the ".install" creation process, so for now, you just have to use CCK to create a new Text field called "Available" which is a Text Select List. The two values are:

N|Coming Soon
Y|Available

Here's the only code in the module that basically checks to see if the value is N, and if so, prevents them from adding to the cart. It's pretty basic but maybe someone else can use it (I know I can.)

I really wanted to hook into the node_info and product_form hooks from Ubercart, but really just needed something quick and dirty, and couldn't find much documentation on hooking into those functions. So this is what I came up with in a pinch.

(This is in the file uc_product_coming_soon.module:

<?php
function uc_product_coming_soon_add_to_cart($nid, $qty, $data) {
 
$available = db_result(db_query("SELECT field_available_value FROM {content_type_product} WHERE nid = %d", $nid));
 
if (
$available == 'N') {
 
   
$result[] = array(
     
'success' => FALSE,
     
'message' => t('Sorry, that product is not available to purchase yet.'),
    );
  }
  return
$result;
}
?>

AttachmentSize
uc_product_coming_soon.zip1.72 KB
--

"Pain don't hurt." - Dalton

Mike Nelson's RiffTrax! www.rifftrax.com