Option to hide a product when placed in cart

Xangis - March 24, 2007 - 07:27
Project:e-Commerce
Version:5.x-3.0
Component:tangible
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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

#1

Christoph C. Cemper - March 25, 2007 - 11:13

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

#2

Xangis - March 25, 2007 - 22:25

Well, 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:

    case 'on payment completion':
      if ($node->manage_stock) {
        db_query('UPDATE {ec_product_tangible} SET stock = %d WHERE nid = %d', $node->stock - $node->qty, $node->nid);
      }
      break;

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.

#3

dman - March 25, 2007 - 23:02

The '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)

#4

Xangis - March 26, 2007 - 01:17

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

    case 'on payment completion':
      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 ) {
          db_query('UPDATE {node} SET status = 0 WHERE nid = %d', $node->nid);
        }
      }
      break;

Any obvious problems with the code or should that do what I want?

#5

dman - March 27, 2007 - 00:22

That'll work.
Ethically, I avoid direct SQL when there are APIs available, so I'd do the (admittedly probably much more intensive)

<?php
$node
->status = 0;
node_save($node);
?>

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.

#6

Xangis - March 28, 2007 - 18:39

Nice, thank you.

And, of course, this little solution would make a great addition to the ecommerce project as a checkbox-configurable option. :)

#7

miahawk - March 31, 2007 - 02:12
Title:Can I Hide Products When Item Is Sold Out?» Option to hide a product when placed in cart
Component:product» tangible

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

#8

Xangis - April 5, 2007 - 00:50

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

#9

brmassa - September 6, 2007 - 12:50
Status:active» fixed

Guys,

its possible using action module. This module will come on Drupal 6.

regards,

massa

#10

Anonymous - September 20, 2007 - 12:51
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.