Zen Cart Logo
Forums / All Other Contributions/Addons / Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Views: 658,563

Results 1,561 to 1,580 of 3,609
21 Jun 2012, 4:52 PM
#1561
simply_sterling avatar

simply_sterling

New Zenner

Join Date:
Jun 2009
Posts:
12
Plugin Contributions:
0

Stock by Attribute v4.0 addon for v1.3.5-1.3.9

DivaVocals:

what I highlighted is probably the issue since the error indicates that the products_with_attributes_stock table is missing a column called "sort".. Perhaps updating the SQl is in order..

Thanks! I inserted the file update_1_4_10.sql into my database and the problem went away. The readme file and this forum really didn't have any explanation for that file and made no mention of inserting that sql file when updating from a previous version of SBA. Others have questioned that file as well, someone should put information on it in the Readme next update. Thanks again for the help, great mod!

21 Jun 2012, 5:18 PM
#1562
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

simply_sterling:

Thanks! I inserted the file update_1_4_10.sql into my database and the problem went away. The readme file and this forum really didn't have any explanation for that file and made no mention of inserting that sql file when updating from a previous version of SBA. Others have questioned that file as well, someone should put information on it in the Readme next update. Thanks again for the help, great mod!
Rule of thumb: In GENERAL most add-ons that include a SQL file that is usually run as part of the install..

Re: "someone should put information on it in the Readme next update", no one is actively maintaining some of the SBA version available.. it's open source so ANYONE can submit an updated version with updated instructions if they would like to volunteer to do so..

27 Jun 2012, 2:51 AM
#1563
batracy avatar

batracy

New Zenner

Join Date:
Jun 2012
Posts:
57
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Not sure if this is the proper place, but I just wanted to mention that I have taken the code v4.14 and merged the changes with my test store using zen-cart 1.5. I had to fix a bug in the file /includes/modules/pages/shopping_cart/header.php to enable the shopping cart to display out of stock messages correctly, and I created a new file /admin/includes/functions/extra_functions/products_with_attributes_stock.php which will register the page in the admin->catalog menu for zen-cart 1.5. I've done a lot of testing with this and it seems to be stable, however, I don't have any dropdown product options in my store, so these are not tested. Radio and Check Boxes work just fine.

I don't have a clean 1.5 installation to create a new package from for the plugin, but I will be happy to list the changes made for anyone who would like to update the plugin.

4 Jul 2012, 2:19 AM
#1564
enochian avatar

enochian

New Zenner

Join Date:
Jan 2009
Posts:
33
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

batracy:

Not sure if this is the proper place, but I just wanted to mention that I have taken the code v4.14 and merged the changes with my test store using zen-cart 1.5. I had to fix a bug in the file /includes/modules/pages/shopping_cart/header.php to enable the shopping cart to display out of stock messages correctly, and I created a new file /admin/includes/functions/extra_functions/products_with_attributes_stock.php which will register the page in the admin->catalog menu for zen-cart 1.5. I've done a lot of testing with this and it seems to be stable, however, I don't have any dropdown product options in my store, so these are not tested. Radio and Check Boxes work just fine.

I don't have a clean 1.5 installation to create a new package from for the plugin, but I will be happy to list the changes made for anyone who would like to update the plugin.

Hi I was wondering if you could tell me how to fix the bug and make the new function file. I have tried installing this add on but it does not appear to work in Zencart version 1.5.0

Any help greatly appreciated.

7 Jul 2012, 10:34 PM
#1565
batracy avatar

batracy

New Zenner

Join Date:
Jun 2012
Posts:
57
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

The fix for the includes/modules/pages/shopping_cart/header.php is rather simple, and it may have been a problem with the merge that I did. Just make sure the stock with attributes code is after the second closing bracket "}" as shown below:

    } //end foreach [attributes]
  } //end if [attributes]

// stock by attributes
		if ( STOCK_CHECK == 'true' ) {

			// Added to allow individual stock of different attributes
			unset($attributes);
			if(is_array($products[$i]['attributes'])){
				$attributes = $products[$i]['attributes'];
			} else {
				$attributes = '';
			}

			$flagStockCheck = zen_check_stock($products[$i]['id'], $products[$i]['quantity'],$attributes);
 		        $stockAvailable = zen_get_products_stock($products[$i]['id'], $attributes);		
			if ($flagStockCheck == true) {
				$flagAnyOutOfStock = true;
			} 
		}
// end stock by attributes

Here is the code for the /admin/includes/functions/extra_functions/products_with_attributes_stock.php

<?php

if (!defined('IS_ADMIN_FLAG')) {
    die('Illegal Access');
}

if (function_exists('zen_register_admin_page')) {
    if (!zen_page_key_exists('products_with_attributes_stock')) {
        zen_register_admin_page('products_with_attributes_stock', 'BOX_CATALOG_PRODUCTS_WITH_ATTRIBUTES_STOCK','FILENAME_PRODUCTS_WITH_ATTRIBUTES_STOCK', '', 'catalog', 'Y', 6);
    }
}
?>

I also found that the ajax part of the code does not work in v1.5 and so I removed it (kept the css file but renamed it). This means that to update the stock, you will have to edit each individually. This is not really a problem for me as I don't have that many products with attributes (less than 30).

7 Jul 2012, 10:44 PM
#1566
batracy avatar

batracy

New Zenner

Join Date:
Jun 2012
Posts:
57
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Oh, I almost forgot...

After removing the ajax code, I found an error with the SQL syntax in the saveAtrrib function in the class file /admin/includes/classes/products_with_attributes_stock.php. The SQL should be corrected as follows:

$sql = "UPDATE ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK." SET quantity = '" . $value . "' WHERE stock_id = " .$id. " LIMIT 1";

correcting the SQL syntax may enable the ajax part of the code to work.

10 Jul 2012, 10:01 PM
#1567
gokeypa avatar

gokeypa

New Zenner

Join Date:
Sep 2011
Posts:
86
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Hello,

I am using zencart.1.3.9 with stock by attributes 1.4.13,

When at the shopping cart page I get the message at the top saying "Products marked with Sorry, we are currently out of stock of this item are out of stock or there are not enough in stock to fill your order.
Please change the quantity of products marked with (Sorry, we are currently out of stock of this item). Thank you"

But in the cart area below that statement that shows the items, it does NOT show which item is out of stock. It is a problem because I have multiple items selling and the customer does not know what item is out. Below are my stock
attribute settings. Any Suggestions?

Check stock level true
Subtract stock true Info
Allow Checkout false Info
Mark product out of stock Sorry, we are currently out of stock of this item Info
Stock Re-order level 5 Info
Show available stock level in cart when less than order true Info
Display Images in Admin false Info
Products status in Catalog when out of stock should be set to 0 Info
Show Sold Out Image in place of Add to Cart 1 Info
Product Quantity Decimals 0 Info
Show Shopping Cart - Delete Checkboxes or Delete Button 3 Info
Show Shopping Cart - Update Cart Button Location 3 Info
Show New Products on empty Shopping Cart Page 1 Info
Show Featured Products on empty Shopping Cart Page 2 Info
Show Special Products on empty Shopping Cart Page 3 Info
Show Upcoming Products on empty Shopping Cart Page 4 Info
Show Notice of Combining Shopping Cart on Login

my site can be found at and if you wish to test, and the item I am out of is
http://www.ruminaformoms.com/catalog/index.php

The Relaxed Soft Tank - $48.00

• Color - Black
• Size - Large

Below is how I have the attributes set up.

38 TEXT + 0.0000 + 0 0
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete
Delete Color
37 Color White + 0.0000 + 0 1
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete
36 Color Black + 0.0000 + 0 2
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete
Delete Size
32 Size Small + 0.0000 + 0.4625 1
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete
34 Size Large + 0.0000 + 0.38 3
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete
35 Size X-Large + 0.0000 + 1 4
Display Only Free Default Discounted Base Price Required
$0.00 $0.00 Update Delete

11 Jul 2012, 5:55 PM
#1568
batracy avatar

batracy

New Zenner

Join Date:
Jun 2012
Posts:
57
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Gokeypa - you need to apply the fix I outlined in an earlier post for the includes/modules/pages/shopping_cart/header.php file. You need to make sure the stock by attributes code is below the second closing bracket. See my example code in my earlier post.

I was getting the same error and found that the stock by attributes code was placed in the wrong location in the code. Moving it as outlined previously will fix this error. Let me know if you need further assistance.

12 Jul 2012, 10:59 AM
#1569
godfogger avatar

godfogger

New Zenner

Join Date:
Jul 2012
Posts:
2
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Hey guys and gals, I am a noob, (As every one sighes!! Another one!!) Sorry!! I am stuck in a pickle and I'm trying to dig my way out.
After installing ZC 1.5, configured the cart to be fully operational with all my needed settings and looks, I have found that I need a module like Stock by Attribute to help me keep track of multiple attributes in my inventory. This scenario would fall in line with the whole t-shirt sizes and colors attributes analogy very similarly. My problem is that I have already started loading products, yet our catalog menu and options have just trippled over night, which is going to cause a major headache as we grow. Now that I'm to this point, going back to a fresh install to add this module would set me back weeks. Is there anyway I can get some help figuring out how to make changes to the php files without starting from scratch? I would greatly appreciate it!
P.S. I started to do a fresh install on a seperate server if it helps to cut corners, then relocate. Whichever is easier!

12 Jul 2012, 5:09 PM
#1570
jund avatar

jund

Zen Follower

Join Date:
Sep 2006
Location:
Ruckersville, VA, USA
Posts:
276
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Using ZENCART 1.5
Would like to implement "Stock by Attributes 4.7 multi add"
Unix based server (justhost.com)
Link to site: http://www.american-savage.com/index.php?main_page=product_info&cPath=122_123&products_id=254

PROBLEM:
I am selling Women's Shorts in two sizes, and the stocking level for each is unique.
The attributes are only two: (Size small and Size medium).

Is there a simple way to do this? When I say simple, I mean can I use features already built into V1.5 ?

Thank you for your time.

Regards,

jund (John Underwood)

17 Jul 2012, 6:23 PM
#1571
toneklone avatar

toneklone

New Zenner

Join Date:
Jul 2012
Posts:
1
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I did all the changes, but then I just get a white store. The admin-area works fine, the Stock by Attributes is there in my 1.5, but my store is just plain white.
Anyone knows why that is?

18 Jul 2012, 3:02 AM
#1572
batracy avatar

batracy

New Zenner

Join Date:
Jun 2012
Posts:
57
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Did you merge the code or copy it? In order for this to work, you must merge the code and merge only those sections labeled for stock by attributes. The problem here is that the code sections were not labeled in some of the files, and it gets a little tricky - but still doable.

25 Jul 2012, 7:11 AM
#1573
terra1069 avatar

terra1069

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Toneklone,

Did you resolve this issue? If so how? I am having the same problem and I did merge the files. I'm pretty sure the issue is with the file: admin/includes/functions/general.php

But you have to restore all the original ZC files that were modified or overwritten before the white screen returns to normal. I checked my site each time I uploaded a merged file and the one stated above was what sent my site to a white screen. Just restoring that file didn't fix it though.

If anyone else could help it would be much appreciated. Thank you.

1 Sep 2012, 9:41 PM
#1574
robophung avatar

robophung

New Zenner

Join Date:
Jan 2011
Posts:
66
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

ATTENTION: Restock Feature has been FIXED!!!!

Sorry for the caps, but I am just too excited :D

I really had to get the functionality of this feature to start working, well because, a typical order for my store might contain numerous products, and having to manually edit the stock for each product when I deleted a large order was not practical.

So without further Adieu! -

In \admin\includes\functions\general.php look for the following code:

function zen_remove_order($order_id, $restock = false) {
    global $db, $order;
    if ($restock == 'on') {
      $order = $db->Execute("select products_id, products_quantity
                             from " . TABLE_ORDERS_PRODUCTS . "
                             where orders_id = '" . (int)$order_id . "'");

      while (!$order->EOF) {
        //restored db
        $restored_attributes = $db->Execute("select pa.products_attributes_id    
                                              from ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." opa, ".TABLE_PRODUCTS_ATTRIBUTES." pa
                                              where opa.orders_id='".(int)$order_id."'
                                              and opa.products_options_id = pa.options_id
                                              and pa.options_values_id = opa.products_options_values_id
                                              and pa.products_id='".(int)$order->fields['products_id']."'
                                              ORDER BY pa.products_attributes_id ASC
                                            ");
        while(!$restored_attributes->EOF) {
          $attr_array[] = $restored_attributes->fields['products_attributes_id'];
          $restored_attributes->MoveNext();
        }
        //echo implode(',', $attr_array);die;
        $db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK." 
                        set quantity = quantity + " . $order->fields['products_quantity'] . " 
                        where products_id = '" . (int)$order->fields['products_id'] . "'
                        and stock_attributes = '".implode(',', $attr_array)."'
                      ");
        $db->Execute("update " . TABLE_PRODUCTS . "
                      set products_quantity = products_quantity + " . $order->fields['products_quantity'] . ", products_ordered = products_ordered - " . $order->fields['products_quantity'] . " where products_id = '" . (int)$order->fields['products_id'] . "'");
        $order->MoveNext();
      }
    }

And replace with...

function zen_remove_order($order_id, $restock = false) {
    global $db, $order;
    if ($restock == 'on') {
      $order = $db->Execute("select orders_products_id, products_id, products_quantity
                             from " . TABLE_ORDERS_PRODUCTS . "
                             where orders_id = '" . (int)$order_id . "'");

      while (!$order->EOF) {
        //restored db
        $restored_attributes = $db->Execute("select pa.products_attributes_id    
                                              from ".TABLE_ORDERS_PRODUCTS_ATTRIBUTES." opa, ".TABLE_PRODUCTS_ATTRIBUTES." pa
                                              where opa.orders_id='".(int)$order_id."'
                                              and opa.products_options_id = pa.options_id
                                              and opa.products_options_values_id = pa.options_values_id
					      and opa.orders_products_id='".(int)$order->fields['orders_products_id']."'
                                              and pa.products_id='".(int)$order->fields['products_id']."'
                                              ORDER BY pa.products_attributes_id ASC
                                            ");
        while(!$restored_attributes->EOF) {
          $attr_array[] = $restored_attributes->fields['products_attributes_id'];
          $restored_attributes->MoveNext();
        }
        $db->Execute("update ".TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK." 
                        set quantity = quantity + " . $order->fields['products_quantity'] . " 
                        where products_id = '" . (int)$order->fields['products_id'] . "'
                        and stock_attributes = '".implode(',', $attr_array)."'
                      ");
        $db->Execute("update " . TABLE_PRODUCTS . "
                      set products_quantity = products_quantity + " . $order->fields['products_quantity'] . ", products_ordered = products_ordered - " . $order->fields['products_quantity'] . " where products_id = '" . (int)$order->fields['products_id'] . "'");
        unset($attr_array);
	$order->MoveNext();
      }
    }

But just a little background and forewarning, I am by no means a programmer, just a noobie, but proficient computer nerd who has had a little background in programming back in college. I sat down for the past 12 hours trying to dissect the logic of tying the line items of the ORDERS_PRODUCTS table (which records each of your unique products sold and in what quantities) to the PRODUCTS_WITH_ATTRIBUTES_STOCK table (which contains your master list of stock for each unique attribute of your product inventory) in the zen-cart database, and realized that the arguments utilized were not specific enough to appropriately identify tie the two tables together accurately.

Furthermore, $attr_array needs to be unset after each iteration, or else data just gets appended to the end of it, causing the whole function to simply not work.

PLEASE NOTE:

This needs more testing and input from the rest of you guys who use this module, because my store's attributes are set up where the only unique attribute I use is color.

So if your store's products are similar to mine, I'm sure that the fix above will work, but if you have multiple attribute combinations (such as size and color), then please test cautiously, and provide your feedback. From looking at the code, I believe it should work in all scenarios...but I can't be for certain.

Also, PLEASE test with caution!!! I would suggest creating a few dummy orders and taking note of your quantities before and after placing your dummy order then monitoring the stock levels after you delete the dummy order and choose to restock the items! It should go without saying, but...obviously don't test this on real live orders :)

Hopefully this helps out a lot of you out there, and this code (or at least the logic to make the restock feature work) make it to the 1.5 version of SBA!

1 Sep 2012, 9:52 PM
#1575
robophung avatar

robophung

New Zenner

Join Date:
Jan 2011
Posts:
66
Plugin Contributions:
0

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Sorry, also important to note for my above solution, this is for ZC 1.3.9h only! I don't have any experience with 1.5 and don't know if the code has changed much, if any, in 1.5...so I can only guarantee this to be working with the latest verion of SBA for ZC 1.3.9h.

6 Sep 2012, 9:17 PM
#1576
milobloom avatar

milobloom

Totally Zenned

Join Date:
Feb 2004
Posts:
1,267
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

My site is getting this error

1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AND pa2.products_attributes_id IN (19821) ' at line 3
in:
[SELECT count(DISTINCT pa1.options_id) AS matches FROM products_attributes pa1, products_attributes pa2 WHERE pa1.products_attributes_id IN () AND pa2.products_attributes_id IN (19821) AND pa1.options_id = pa2.options_id]

http://www.nothingbutcostumes.com/billy-the-goat-newborn-infant-costume-p-9007.html

Any suggestion on how I can fix this???

Thanks in advance

6 Sep 2012, 9:33 PM
#1577
milobloom avatar

milobloom

Totally Zenned

Join Date:
Feb 2004
Posts:
1,267
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

I searched my store for pa1 and narrowed the problem. Is there something I can comment out to remove this problem??

/home/nothingb/public_html/includes/functions/functions_lookups.php

Line #272 : SELECT pov1.products_options_id FROM (products_attributes pa1

Line #274 : ON pa1.options_values_id = pov1.products_options_values_id)

Line #278 : WHERE pa1.products_attributes_id IN ( $atr ) AND pa2.products_attributes_id IN ( $atr2 )

Line #288 : $res2 = $db->Execute("SELECT count(DISTINCT pa1.options_id) AS matches

Line #289 : FROM products_attributes pa1, products_attributes pa2

Line #290 : WHERE pa1.products_attributes_id IN ($atr)

Line #292 : AND pa1.options_id = pa2.options_id");

Line #321 : $res2 = $db->Execute("SELECT DISTINCT pa1.products_attributes_id AS needed

Line #322 : FROM products_attributes pa1, products_attributes pa2

Line #323 : WHERE pa1.products_attributes_id IN ($atr)

Line #325 : AND pa1.options_id = pa2.options_id

Line #326 : ORDER BY pa1.products_attributes_id");

/home/nothingb/public_html/snickers/includes/functions/extra_functions/functions_qty_attribute.php

Line #34 : (products_attributes pa1 INNER JOIN products_options_values_to_products_options pov1

Line #35 : ON pa1.options_values_id = pov1.products_options_values_id)

Line #42 : WHERE pa1.products_attributes_id IN ( $atr )

Line #53 : $res2 = $db->Execute("SELECT count(DISTINCT pa1.options_id) AS matches

Line #54 : FROM products_attributes pa1, products_attributes pa2

Line #55 : WHERE pa1.products_attributes_id IN ($atr)

Line #57 : AND pa1.options_id = pa2.options_id;");

6 Sep 2012, 9:53 PM
#1578
milobloom avatar

milobloom

Totally Zenned

Join Date:
Feb 2004
Posts:
1,267
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

Dr Byte once said

"WHERE pa1.products_attributes_id IN ()"
You're telling it to lookup a products_attributes_id in the list of values specified inside the parentheses, but your list is empty, thus you're creating a MySQL syntax error. Hence the error message.

So I see the 2 places... What can I do now?

WHERE pa1.products_attributes_id IN ($atr)

Is the problem..

6 Sep 2012, 10:09 PM
#1579
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
177

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

milobloom:

So I see the 2 places... What can I do now?

WHERE pa1.products_attributes_id IN ($atr)

Simple: fix the code that creates the contents of $atr
7 Sep 2012, 12:57 AM
#1580
milobloom avatar

milobloom

Totally Zenned

Join Date:
Feb 2004
Posts:
1,267
Plugin Contributions:
1

Re: Stock by Attribute v4.0 addon for v1.3.5-1.3.9

$atr = implode(',',$attributes);

in

/home/nothingb/public_html/includes/functions/functions_lookups.php

Can I change this to something?