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:

  1. 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).
  2. 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).
    
CommentFileSizeAuthor
uc_stock_zero.tar_.gz1.04 KBdjsmeg
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave’s picture

Status: Active » Needs work

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

djsmeg’s picture

I'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?

longwave’s picture

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

SilviuChingaru’s picture

TR’s picture

Version: 7.x-3.x-dev » 8.x-4.x-dev
Issue summary: View changes
TR’s picture

Component: Stock » Rules

Added "Rules" component.