Here's an idea.
Three steps here:
1. /includes/classes/order.php
around line 715 or so, find this line
Code:
$this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN');
and replace it with the following:
Code:
$this->stock_query = $stock_values;
$this->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN', array('i'=>$i));
$stock_values = $this->stock_query;
2. Add a new file: /includes/auto_loaders/config.observer_bypass_stock_decrementing.php
Code:
<?php
/**
*
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*/
/**
* Designed for v1.3.9 and v1.5.0
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
}
$autoLoadConfig[190][] = array('autoType'=>'class',
'loadFile'=>'observers/class.observer_bypass_stock_decrementing.php');
$autoLoadConfig[190][] = array('autoType'=>'classInstantiate',
'className'=>'observer_bypass_stock_decrementing',
'objectName'=>'observer_bypass_stock_decrementing');
3. Add a new file: /includes/classes/observers/class.observer_bypass_stock_decrementing.php
PHP Code:
<?php
/**
* @package plugins
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
*
* Designed for v1.5.0, compatible with v1.3.9
*/
class observer_bypass_stock_decrementing extends base {
function __construct() {
$this->attach($this, array('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN'));
/**
* INSTRUCTIONS:
* The following array needs a list of product ID numbers to bypass when handling inventory reductions. Values are separated by commas:
* MAKE EDITS INSIDE THE array() below:
*/
$this->arrayOfProductsToByPass = array(3,44,18,10,1);
}
/**
* The following is fired on every product that is added to the order, just before the stock-reduction is run.
*/
function update(&$class, $eventID, $paramsArray = array())
{
global $db; // this is needed later
$i = $paramsArray['i']; // this is needed in order for the following code to know which product is being processed at the moment.
/**
* The following line checks to see if the product ID being added is in the list of products to bypass.
*/
if (in_array($class->products[$i]['id'], $this->arrayOfProductsToByPass)) {
/**
* If the above test passes, then the following line will basically tell the normal stock-reduction code that there's nothing to do.
* (technically it fudges the code so that the product ID for which it's expecting to decrease stock is not found, which therefore triggers a normal bypass)
*/
$class->stock_query = $db->Execute("SELECT * from " . TABLE_PRODUCTS . " where products_id = 0");
}
/**
* Many other things could be done here as well, including a completely different stock-handling routine.
* One could do more detailed checks for attributes present, reduce inventory on various related items, etc.
* All the data is readable from the $class->products[$i] array.
*/
// uncomment the following line to dump a list of available data to the screen for testing (not on a live site of course)
// die('<pre>Current product data: ' . print_r($class->products[$i], TRUE));
}
}
If this is helpful for you, donations welcome: www.zen-cart.com/donate
Bookmarks