Forums / Setting Up Categories, Products, Attributes / Quantity in Stock not subtracting

Quantity in Stock not subtracting

Views: 3,418

Results 1 to 7 of 7
24 Nov 2007, 5:21 AM
#1
robbyn7 avatar

robbyn7

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
0

Quantity in Stock not subtracting

I'm using Zencart vs.1.37. I installed the Products with Attributes Stock Mod on 04/07. The issue I'm having is I have to manually reduce the quantity in stock when an order is placed. I thought this iwas done automatically by the this Mod? Am I missing something?

Here is my setup in Admin:
Check Stock Level = True
Subtract Stock = True
Allow Checkout = False

Should I update to the latest Mod Kuroi submitted?

Thanks for any help?

4 Dec 2007, 4:46 PM
#2
epsports avatar

epsports

New Zenner

Join Date:
Jul 2007
Posts:
21
Plugin Contributions:
0

Re: Quantity in Stock not subtracting

having the exact same problem, and I have also used the stock with attributes add-on. Any ideas anyone? or did you manage to sort this out Robbyn7?

5 Dec 2007, 4:22 PM
#3
robbyn7 avatar

robbyn7

Zen Follower

Join Date:
Dec 2006
Posts:
187
Plugin Contributions:
0

Re: Quantity in Stock not subtracting

Hello epsports,

I upgraded to the latest mod by Kuroi and finally got it to work. Try that if you haven't already.
Now the issue I'm having is that if you delete an order and click the checkbox to add the items back to stock, it doesn't. Here's the reply from Kuroi:

kuroi:

This is true. There is no automatic stock replenishment for deleted orders.

Robyn

28 Oct 2009, 12:58 AM
#4
starchang98 avatar

starchang98

New Zenner

Join Date:
Sep 2009
Posts:
45
Plugin Contributions:
0

Re: Quantity in Stock not subtracting

anyone have a solution to this? i installed Stock by Attributes v4.7ajax for zencart 1.3.8 and im having this problem. is there a more up to date mod? i have my admin conifiguration stock set to subtract =true but it wont subtract...

6 Apr 2011, 5:27 PM
#6
fo0bar avatar

fo0bar

New Zenner

Join Date:
Apr 2011
Location:
Australia
Posts:
16
Plugin Contributions:
0

Re: Quantity in Stock not subtracting

to anyone else who h as the same issue, i can see that it doesn't exactly get resolved here, outside of completely reinstalling, which could mess with other installed modules which modify core files (for example time zone fix).

I found the error was in the fact I'd installed another mod after stock by attributes, which overwrote SBA's files. The file(s) in particular was:
**[adminfolder]\orders.php **
as well as
[zenfolder]\classes\order.php.

I used a comparison software (winmerge), compared my server-copy of each file to the unzipped SBA copy of those files. Sure enough, there was about 4-5 lines of code in both those server-side files which didn't have the SBA code. Made the necessary mods, uploaded the modified files, tested a transaction, and all my problems were solved.

hope this helps all the other people that end up on this page like me, to find no proper resolution.

6 Apr 2011, 5:47 PM
#7
fo0bar avatar

fo0bar

New Zenner

Join Date:
Apr 2011
Location:
Australia
Posts:
16
Plugin Contributions:
0

Re: Quantity in Stock not subtracting

tried to do a step by step in an edit but i passed the 7 minutes. ugh. here we go again.

download the order.php file from your admin folder.
find the line:

$db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");

directly below that line, copy and pase the following code:

// kuroi: Begin Stock by Attributes additions
// added to update quantities of products with attributes
$attribute_search = array();
$attribute_stock_left = STOCK_REORDER_LEVEL + 1; // kuroi: prevent false low stock triggers

		if(isset($this->products[$i]['attributes']) and sizeof($this->products[$i]['attributes']) >0){
			foreach($this->products[$i]['attributes'] as $attributes){
				$attribute_search[] = $attributes['value_id'];
			}
		
			if(sizeof($attribute_search) > 1){
				$attribute_search = 'where options_values_id in ("'.implode('","', $attribute_search).'")';
			} else {
				$attribute_search = 'where options_values_id="' . $attribute_search[0].'"';
			}

			$query = 'select products_attributes_id from ' . TABLE_PRODUCTS_ATTRIBUTES . ' ' . $attribute_search .' and products_id="' . zen_get_prid($this->products[$i]['id']) . '" order by products_attributes_id';
			$attributes = $db->Execute($query);
			$stock_attributes_search = array();
			while(!$attributes->EOF){
				$stock_attributes_search[] = $attributes->fields['products_attributes_id'];	
				$attributes->MoveNext();
			}
			if(sizeof($stock_attributes_search) > 1){
				$stock_attributes_search = implode(',', $stock_attributes_search);
			} else {
				foreach($stock_attributes_search as $attribute_search){
					$stock_attributes_search1 = $attribute_search;
				}
				$stock_attributes_search = $stock_attributes_search1;
			}
			
			$get_quantity_query = 'select quantity from ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' where products_id="' . zen_get_prid($this->products[$i]['id']) . '" and stock_attributes="' . $stock_attributes_search . '"';

		$attribute_stock_available = $db->Execute($get_quantity_query);	
			$attribute_stock_left = $attribute_stock_available->fields['quantity'] - $this->products[$i]['qty'];

			$attribute_update_query = 'update ' . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . ' set quantity='.$attribute_stock_left.' where products_id="' . zen_get_prid($this->products[$i]['id']) . '" and stock_attributes="' . $stock_attributes_search . '"';
			$db->Execute($attribute_update_query);	
		}
		// kuroi: End Stock by Attribute additions

save the file, upload it to your admin folder, test a transaction and see if it's subtracting the stock. after i'd done this, it was.

zen cart 1.3.9, SBA 1.4.12. oh, and if you're wondering, i realised it was only the one file. i'd modified orders.php for a separate reason.