Re: Re: Ryan wrote:Just a quick bit

thehandyman's picture
Offline
Joined: 11/07/2008
Juice: 16
Re: Re: Ryan wrote:Just a quick bit

UPDATE: I found the solution. This code will check the stock of each product when completing an order, then unpublish any products that have a stock or zero or negative. I left the echo's in to help debug, but as it is nothing gets sent to the screen. Any bugs please let me know!

<?php
$nids
= array();

foreach (

$order->products as $product) {
 
//echo '<br />Checking the stock level of model:' . $product->model;
  //echo '<br />The stock level is ' . uc_stock_level($product->model) . ' which we check against zero';
 
if ((uc_stock_level($product->model) - 1) <= 0) {
   
   
//echo '<br />The stock level is zero or negative, unpublish nid:' . $product->nid;
    // if the stock WILL be 0 or negative after this order, then add to the list to unpublish
   
$nids[] = $product->nid;
  }
}
/*
echo '<pre><b>The nids that will be unpublished are:</b><hr>';
print_r($nids);
echo '</pre>';
*/
node_operations_unpublish($nids);
?>
Automatically remove one-off products that have been sold? By: Magrathea (51 replies) Fri, 10/24/2008 - 15:47