Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I want to be able to perform actions on nodes when the stock level changes for a product, for example unpublishing a node that has zero stock.
Proposed resolution
Add a rule event that fires when stock levels change, so that I can then use the rules framework to act on it.
Remaining tasks
Attached is code that performs this. It's currently designed as a separate module, but probably should be integrated into stock core.
User interface changes
None?
API changes
I have encountered two problems with building this module:
- There is no uc_product entity. This would have made most sense for what to publish when stock level changes. Using the uc_order_product entity didn't work because uc_order_product requires a uc_order entity to associate itself with (and gives a crypt "Access denied!" error when you don't have a uc_order context).
- The uc_quote module has a minor problem if there is an update to a product during the ordering process. I got the following error when the node was unpublished during the checkout process: (Issue filed separately)
Notice: Undefined property: stdClass::$street1 in uc_quote_node_update() (line 105 of /var/local/drupal7/sites/all/modules/ubercart/shipping/uc_quote/uc_quote.module).
Comment | File | Size | Author |
---|---|---|---|
uc_stock_zero.tar_.gz | 1.04 KB | djsmeg |
Comments
Comment #1
longwaveCan you provide this as a patch to uc_stock?
Also, I don't think
db_query("SELECT p.nid FROM {uc_products} p WHERE p.model = :sku", array('sku'=>$sku))->fetchField()
will work if the SKU has been adjusted by uc_attribute (this is a long standing issue with SKUs vs nodes).Comment #2
djsmeg CreditAttribution: djsmeg commentedI'll take a look at doing that. Though it kind of begs the question, should all the functionality of the stock module be reduced to this event? The message it sends is basically this event isn't it? and what about upgrades and all the other stuff you'd need to look at doing?
Or am I overthinking the problem?
Comment #3
longwaveYes, I think stock could be pretty much reduced to an entirely Rules-based solution, if someone wants to write the code to do that. Not sure what you mean about upgrades.
Comment #4
SilviuChingaru CreditAttribution: SilviuChingaru commented+1 for Rule-based solution too.
#1514756: Stock transaction should be more flexible through Rules
Comment #5
TR CreditAttribution: TR commentedComment #6
TR CreditAttribution: TR commentedAdded "Rules" component.