Depending on what this involves, this is either a feature request or a how-to question.
I'm building a used science fiction bookstore at www.pulpsource.com. One of the things that I would like to be able to do is automatically hide (or unpublish) a product when it is sold out. Due to the nature of used books, there's no guarantee you'll ever come across another copy of something you've sold, so showing unavailable products will only frustrate shoppers.
Is it possible to do this relatively easily? If so, how? Or, where would I look into changing the code?
If it's not possible to do this I would like to request this feature for a future version of ecommerce.
Thank you,
Jason Champion
Comments
Comment #1
Christoph C. Cemper commentedtake a look into the "tangible" product type, from readme
Creates shippable products for ecommerce.
Optional features includes inventory control and availability estimates.
Haven't used that tough so far - check it.
Comment #2
Xangis commentedWell, I've already been using the tangible product with inventory management. The way that is designed, the product shows "sold out" when a quantity is zero. That's halfway to where I want to be -- I want to remove (unupublish) the object entirely so people can no longer see it when it's sold out.
Is there a hook in the Drupal API that lets me unpublish a node? Like maybe a node->unpublish or node_published = false call that I could add to the inventory management update if the quantity hits 0?
I see where this would be done in tangible.module if it's possible:
That way shoppers won't be frustrated by seeing an item they can't buy and I can set the published flag when restocking and updating inventory if I want to make the item available again.
Comment #3
dman commentedThe 'hook' is the node status.
$node->status=0;
will unpublish it.
No automatic connection with inventory control yet, but that's a good idea. Other clients of course might not want exactly that behaviour. (reminds me to ask about that to my current job)
Comment #4
Xangis commentedThank you, that's what I was looking for.
Although I'm an expert at C++, I'm still something of a newbie with PHP. Here's what I've come up with:
Any obvious problems with the code or should that do what I want?
Comment #5
dman commentedThat'll work.
Ethically, I avoid direct SQL when there are APIs available, so I'd do the (admittedly probably much more intensive)
It sorta allows other things to happen and notice it's unpublished. I don't know what (remove from a specials promotion on the front page?), but the hooks can now catch it.
Maybe out of scope for your one job, but you see what I'm saying.
Comment #6
Xangis commentedNice, thank you.
And, of course, this little solution would make a great addition to the ecommerce project as a checkbox-configurable option. :)
Comment #7
miahawk commentedsimilar stituation here, selling one-of-a-kind art pieces as tangibles. the market has buyers who are competitive, and having one-off pieces in inventory that can be placed in the cart by multiple buyers can be problematic.
I'd love to see a way to hide a product when it goes into someone's cart, so that it's not in inventory unless they remove it from their cart or abandon their session somehow (timeout). in my market, I'd give them 24 hours to complete their transaction, and some artists would allow longer.
Comment #8
Xangis commentedTo hide a product when it goes into someone's cart, you'd do exactly what I'm doing in the ecommerce/tangible/tangible.module, but instead of under 'on payment completion' you would use 'cart add item' like this:
case 'cart add item':
if ($node->manage_stock) {
$remaining = $node->stock - $node-qty;
db_query('UPDATE {ec_product_tangible} SET stock = %d WHERE nid = %d', $remaining, $node->nid);
// Unpublish the node if the quantity is zero so customers don't see out of stock items.
if( $remaining == 0 ) {
$node->status = 0;
node_save($node);
}
}
break;
As for automatically removing it from the cart -- I have no idea. I'm sure something could be worked in to check for that on a cron job, but haven't any idea the complexity level.
Comment #9
brmassa commentedGuys,
its possible using action module. This module will come on Drupal 6.
regards,
massa
Comment #10
(not verified) commented