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,331

Results 2,441 to 2,460 of 3,609
07 Jan 2016, 01:16
#2441
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

jnabird333:

What did you mean by this statement? Did you work this fix into the last update or are you still testing it?

Yes, the files have been updated to support an admin switch (placed in the attrbute settings section of the configuration menu) to disable display of the customid in the attribute dropdowns. Installation for those that have already gotten their SBA related settings would be to upload the files and run the sql provided above, or for those with a new setup/don't mind adjusting the SBA (dynamic dropdowns as well) setting can do the install/upgrade provided in the SBA configuration menu after the files are uploaded... If the files are not uploaded but the sql is performed, then the switch does nothng. If the files are uploaded but the sql (setup) is not performed then the customid will default to being on.

07 Jan 2016, 01:26
#2442
jnabird333 avatar

jnabird333

New Zenner

Join Date:
Dec 2015
Location:
Ohio
Posts:
16
Plugin Contributions:
0

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

Besides the one question about where the quantity is checked by attributes php....where are the dynamic dropdowns controlled as I feel they are still not working as described?

alana

07 Jan 2016, 01:36
#2443
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

jnabird333:

Where does the quantity get checked for the attributes in SBA to show "out of stock"? What .php file controls this?

While I am still setting up and testing, I have not gone through a test purchase to verify the correct product quantity goes down. (I buy 1 small blue t-shirt, then the small blue t-shirt product quantity in the SBA screen goes down.)

Two maybe three areas to address that question... The "display" of out-of-stock in the dropdowns is done in the includes/classes/observers/class.products_with_attributes_stock.php (if I remember the full filename correctly, there's only one such file added by the plugin) in the sections of code that start with updateAttributes as the includes/modules/YOUR_TEMPLATE/attributes.php file is processed... Those sections go out to the includes/functions/extra_functions/products_with_attributes.php (I think it's called) file to process the data passed to it.

Now, if dynamic dropdowns is "activated" and being used, then the stock verification is done throught the combination of includes/classes/pad_base.php and pad_sbadropdown (or whatever it got called) with the functions of the second file overriding the equivalent functions of the first. (I still think the creation of that plugin was rather ingenious). The "stock" check is then performed through some javascript calculations/comparisons.

Now the issue of decrement of stock... Well, before it gets purchased there is an extra_cart actions file that inspects the contents being passed to the cart... That code is what is run regardless of DD being used or not... The DD "interface" is just a bit of a nicety showing the customer up front the current status. The real meat though is in this extra cart file. It performs a check of the provided attributes that are expected to be formatted in a typical ZC fashion to

  1. Verify that the provided attributes make a product that exists in the SBA table
  2. Verify that there is a quantity currently available as determined by the SBA table stock quantities...
  3. If the quantity in the cart is adjusted it again verifies the presence of quantity. It does not again check for the accuracy of the combinations of attributes of the product to be defined.

Failure of either of the first two prevents addition of the product to the cart/adjustment of the requested quantity to that on hand. Failure of the third adjusts quantity to the maximum available assuming that's how the store is setup... There's also caveats for those that allow selling on "backorder"..

Now the last part, that is done/addressed through the includes/classes/orders.php file and the same observers file from above... Btw, all of those files rely on the functions file above as well...

Best in all to be sure that all of the files of the plugin are up-to-date with the current distribution so that they can all interact properly together...

I do look forward to your test purchase results assuming the other issues up to that point are resolved.. Remember you don't have to use paypal or something that actually takes your money, you could use a "mail my payment" type purchase to get the same result (downloads are a little tricky for testing in that situation, but that comment is for others than your store).

07 Jan 2016, 01:41
#2444
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

jnabird333:

Besides the one question about where the quantity is checked by attributes php....where are the dynamic dropdowns controlled as I feel they are still not working as described?

alana

So, in a "default" install the DD would be presented through includes/templates/YOUR_TEMPLATE/templates/tpl_modules_attributes.php as called through the process of generating the page from includes/templates/YOUR_TEMPLATE/templates/tpl_product_info_default.php and "gathering" the attributes... But seeing the way yours are setup in the template, it appears your template author has "bypassed" that file in place of something else... That is why I identified the variables I did because those variables are the ones generated by attributes.php to be used for display (though that too could have been bypassed by the template author).. In summary, I would say that issue is something you either need to ferret out or discuss with the template provider...

07 Jan 2016, 07:30
#2445
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

Fyi, ran through a few purchase tests... Currently, purchasng two or more "different" product (different text only) does not reduce the stock for all purchased quantity. Test was: had a total of 25 product, in cart had 10 quantity with one version of text. Added the same product but with different text in quantity of 7. Went through the purchase process and only 7 were removed from stock of that product... Not 17... So, need to look at the orders process regarding multiple copies of the same product but different associated data in regards to how SBA does that reduction...

To qualm any other concerns though, tried a purchase of a product that had 2 attributes assigned, one attribute had one and only one choice. The other had three choices. Different quantity (5, 7, and 10) were populated for each of the total three variants. Each variant was a combination of the two attributes. I then added 3 of the first from the above quantity and 7 of the last. The final result was as expected: 2, 7, and 3, respectively.

Now I did have to do something "special" on the add-to-cart in order to account for adding the appropriate quantity of such "non-stock affecting" attributes... Probably have to duplicate something about that in the orders processing part...

07 Jan 2016, 09:10
#2446
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

My guess (yet to be able to prove) is that the query of line 317 of includes/classes/observers/class.products_with_attributes_stock.php needs to be formatted like that of includes/classes/order.php line 734 (zc 1.5.3/1.5.4) such that the select query is "refreshed" for each occurrence, which isn't an issue when the attrbutes (sans text) are different...

So I would think that:

$attribute_stock_available = $db->Execute($get_quantity_query);

Should be:

$attribute_stock_available = $db->Execute($get_quantity_query, false, false, 0, true));

Inside of includes/classes/observers/class.products_with_attributes_stock.php line 317...

Reason behind this thought? Well, the sock quantity only reduced by the "last" product of the same product_id... This meant that the previous select/update combo was run a second time using the same initial data of the original available stock.... Thus, after the first product was removed from stock, when the query was asked again without clearing the cache, the result was the same on the second and final product (same products_id and sba table stock_id, but different text). Will test as soon as I get back to a computer where I can modify the code.

Sorry badarac. :)

07 Jan 2016, 10:01
#2447
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

Yup, that fixed it... Btw, the overall stock did decrement on the "problematic" listing earlier before the above fix, just not the individual stock (at the time). Applying the above "fix" allowed checkout stock tracking of product that were listed more than once in the cart, each with different text only,,,

07 Jan 2016, 21:12
#2448
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

mc12345678:

Yup, that fixed it... Btw, the overall stock did decrement on the "problematic" listing earlier before the above fix, just not the individual stock (at the time). Applying the above "fix" allowed checkout stock tracking of product that were listed more than once in the cart, each with different text only,,,

The minor fix identified above that changed the $db->Execute command has been incorporated into the download. If the software was up-to-date to yesterday or so, then should only have to apply the above posted fixes, otherwise recommend installing the current/new fileset and doing the install. BTW, also added the remove sql to the fileset to support deleting the newly added option. :)

Two files affected: the storeside observers class and the admin's install file.

08 Jan 2016, 14:34
#2449
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

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

Sorry for the delay testing things. Been busy with my day job. What should I download to pick up all the changes to test?

08 Jan 2016, 16:07
#2450
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

badarac:

Sorry for the delay testing things. Been busy with my day job. What should I download to pick up all the changes to test?

I thought your day job might be golfing. :P

Well, would say latest from http://www.github.com/mc12345678/Stock_By_Attributes_Combined. I hadn't done any special download this tag arrangement. It's been quiet there I think for 24 hours now. :P

08 Jan 2016, 16:28
#2451
badarac avatar

badarac

Totally Zenned

Join Date:
Aug 2009
Location:
Longs, SC
Posts:
635
Plugin Contributions:
0

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

mc12345678:

I thought your day job might be golfing. :P

Well, would say latest from http://www.github.com/mc12345678/Stock_By_Attributes_Combined. I hadn't done any special download this tag arrangement. It's been quiet there I think for 24 hours now. :P
If I hit the lottery this weekend it could be. :cool: In the absence of a small fortune I suppose I'll need to keep working to pay the bills. I'll download the most recent and test it out.

12 Jan 2016, 22:39
#2452
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

@jnabird333

At last swing by of the sample product in your store, I saw that you had overcome the issue of dynamic dropdowns. But (and it's been a few days) I noticed that it doesn't quite work right...

Once the first or greater choice has been selected, a change of any selection before the last available should reset all options "below" that one... In your case, you have a two attribute selecter, the first size, the second color. Once each of those have been selected, if the first is changed, the second is not reset... Watching the operations on the page, there was also a javascript error that occurred in that process...

Now I'm not sure which of the many javascripts on that page was causing the issue, but I'm guessing that it is the one that deals with selectors (something like that in the filename). I didn't spend much more time troubleshooting it, but thought I would let you know the expected operation and how it isn't following that "process".

12 Jan 2016, 23:05
#2453
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

@michael_rebreathe,

Your siteat last check was still presenting three attributes when it appears that only 2 are defined. Based on the source code of the displaayed page it appears as if there might have been some code merging performed with the tpl_modules_attributes.php file as there is code present only introduced in this version/ZC 1.5.5 and only to be displayed when dynamic dropdowns is disabled which makes the situation even odder as it is acting as both enabled in full and disabled in part...

13 Jan 2016, 20:55
#2454
michael_rebreathe avatar

michael_rebreathe

New Zenner

Join Date:
Jul 2015
Posts:
43
Plugin Contributions:
0

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

mc12345678:

@michael_rebreathe,

Your siteat last check was still presenting three attributes when it appears that only 2 are defined. Based on the source code of the displaayed page it appears as if there might have been some code merging performed with the tpl_modules_attributes.php file as there is code present only introduced in this version/ZC 1.5.5 and only to be displayed when dynamic dropdowns is disabled which makes the situation even odder as it is acting as both enabled in full and disabled in part...

Which is why I've been banging my head trying to figure it out. It makes no sense to me, either. Since this is only one of >400 products, we didn't let this delay release. We are now live!

I haven't touched tpl_modules_attributes.php, it doesn't appear to be a partial copy of the content, and the time stamp is synced with the other files included in the last update. I'm considering completely deleting the product and its attributes links and then recreating the product from scratch (kind of shotgun, but it's only three minutes wasted).

Something I thought I solved, but only half way...The day after we went live, a customer reiterated a concern I saw and thought I fixed. Turns out, I only fixed it on single-attribute dropdowns. We really want the quantity available to display on the product page, but "Black Qty 2" can be perceived as forcing the customer to order in pairs. I updated \includes\classes\observers\class.products_with_attributes_stock.php [161] to change it to say "Black: 2 Available" Since this is a change to the actual construction of the content of the dropdown, this isn't just a change to a language define file. Thoughts on where this is is for multi-attributes in the sea of pages?

13 Jan 2016, 22:07
#2455
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

michael_rebreathe:

Which is why I've been banging my head trying to figure it out. It makes no sense to me, either. Since this is only one of >400 products, we didn't let this delay release. We are now live!

I haven't touched tpl_modules_attributes.php, it doesn't appear to be a partial copy of the content, and the time stamp is synced with the other files included in the last update. I'm considering completely deleting the product and its attributes links and then recreating the product from scratch (kind of shotgun, but it's only three minutes wasted).

Something I thought I solved, but only half way...The day after we went live, a customer reiterated a concern I saw and thought I fixed. Turns out, I only fixed it on single-attribute dropdowns. We really want the quantity available to display on the product page, but "Black Qty 2" can be perceived as forcing the customer to order in pairs. I updated \includes\classes\observers\class.products_with_attributes_stock.php [161] to change it to say "Black: 2 Available" Since this is a change to the actual construction of the content of the dropdown, this isn't just a change to a language define file. Thoughts on where this is is for multi-attributes in the sea of pages?

Yup, and I'll look at how "best" such a statement can be easily added in the future. (Have an idea, but want to try to keep it easy for those that choose to modify it such as the above request.)

File: includes/classes/pad_sba_sequenced_dropdowns.php

Line 508:
Can change from:

            $out.=" + '" . PWA_STOCK_QTY . "' + stk2";

to:

            $out.=" + '" . PWA_STOCK_QTY . "' + stk2" . " Available";

For the fix, I'm looking at modifying PWA_STOCK_QTY and the remainder of that statement to possibly sprint the value, or more simply to have it defined as the entire text that follows the current PWA_STOCK_QTY, such that the define in: includes/languages/english/extra_definitions/products_with_attributes.php
Line 15 would be changed from:

define('PWA_STOCK_QTY', ' Qty: ');

to (untested):

define('PWA_STOCK_QTY', ' + " Qty: " + stk2 + " Available"');

Might have to reverse all the quotes on the right side of the define changing single quotes into double and double into single to support the javascript portion, and then line 508 of the previous file would be simply:

            $out.= PWA_STOCK_QTY;

Or some variation on that "thought"...

Or since I see the constant is used in the class, that it would need to be a different constant in order to work or back to the previous "thought" of using sprint to provide the data... Again, the reason behind at least offering such a "prefix"/"suffix" option is to handle multiple languages as well where the word(s) may need to follow the number instead and further why an sprint option may be better so that the code can be consistent, but the resulting text be as desired/formed.

Anyways, more than you needed, but there ya' go. :)

14 Jan 2016, 14:11
#2456
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

@michael_rebreathe

I have some other non-SBA related things to do, but took a look at tpl_modules_attributes, while I don't think there is an issue there, some of the coding pre-existed functionality that has been added. Basically there is an internal check for the product being an SBA controlled product, and then the variable is set and used for later checks. Problem might be that in the global aspect, the variable might be revised... Anyways, thinking of changing the tests in that file so that only the status as determined at that point is possible to affect operation...

I had been trying to get "creative" and rely on certain data being maintained to minimize function calls, database searches, etc... But if it the current code is potentially affecting results, first need to ensure functionality.

14 Jan 2016, 21:39
#2457
michael_rebreathe avatar

michael_rebreathe

New Zenner

Join Date:
Jul 2015
Posts:
43
Plugin Contributions:
0

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

mc12345678:

Yup, and I'll look at how "best" such a statement can be easily added in the future. (Have an idea, but want to try to keep it easy for those that choose to modify it such as the above request.)

File: includes/classes/pad_sba_sequenced_dropdowns.php

Line 508:
Can change from:

        $out.=" + '" . PWA_STOCK_QTY . "' + stk2";
> 
> to:
> ```
            $out.=" + '" . PWA_STOCK_QTY . "' + stk2" . " Available";

For the fix, I'm looking at modifying PWA_STOCK_QTY and the remainder of that statement to possibly sprint the value, or more simply to have it defined as the entire text that follows the current PWA_STOCK_QTY, such that the define in: includes/languages/english/extra_definitions/products_with_attributes.php
Line 15 would be changed from:

define('PWA_STOCK_QTY', ' Qty: ');

> 
> to (untested):
> ```
define('PWA_STOCK_QTY', ' + " Qty: " + stk2 + " Available"');

Might have to reverse all the quotes on the right side of the define changing single quotes into double and double into single to support the javascript portion, and then line 508 of the previous file would be simply:

        $out.= PWA_STOCK_QTY;
> 
> Or some variation on that "thought"... 
> 
> Or since I see the constant is used in the class, that it would need to be a different constant in order to work or back to the previous "thought" of using sprint to provide the data... Again, the reason behind at least offering such a "prefix"/"suffix" option is to handle multiple languages as well where the word(s) may need to follow the number instead and further why an sprint option may be better so that the code can be consistent, but the resulting text be as desired/formed. 
> 
> Anyways, more than you needed, but there ya' go. :)

Not quite so simple as just changing line 508, but I got it.
To allow any combination of prefixes and suffixes, I added

define('PWA_STOCK_QTY_PFX', ' :');
define('PWA_STOCK_QTY_SFX', ' Available');


Changed /includes/classes/pad_sba_sequenced_dropdowns.php (lines 506 +)
    if ($curattr == sizeof($attributes) - 2) {
      if (STOCK_SHOW_ATTRIB_LEVEL_STOCK == 'true') {

//$out.=" + '" . PWA_STOCK_QTY . "' + stk2";
$out.=" + '" . PWA_STOCK_QTY_PFX . "' + stk2";//Put prefix here
$out.=$outArray;
$out.="[opt]";
}
}
//$out.=",opt.substring(1));\n";
$out.="+ '" . PWA_STOCK_QTY_SFX . "',opt.substring(1));\n";//Added the suffix here
$out.=" } else {\n";

Now for the second dropdown it shows
Black :2 Available
Blue :4 Available
Green :2 Available
Red :3 Available

...which works for us and is flexible should our passions change.

> **mc12345678:**
>
> ```
define('PWA_STOCK_QTY', ' + " Qty: " + stk2 + " Available"');

This will totally puke, since "stk2" is the name of the array holding the second-tier attributes stock quantities, which has to be accessed to determine the quantity. Once I got it to work with Prefix and Suffix, this is how the relevant line of Java is put together:

frm['id[6]'].options[frm['id[6]'].length]=new Option(htmlEnDeCode.htmlDecode(txt6[opt]) + ' :' + stk2['_'+frm['id[1]'].value][opt]+ ' Available',opt.substring(1));

It worked fine with just a prefix, but the suffix gets in the way of accessing the array.

14 Jan 2016, 22:26
#2458
michael_rebreathe avatar

michael_rebreathe

New Zenner

Join Date:
Jul 2015
Posts:
43
Plugin Contributions:
0

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

michael_rebreathe:

Not quite so simple as just changing line 508, but I got it.
To allow any combination of prefixes and suffixes, I added

define('PWA_STOCK_QTY_PFX', ' :');
define('PWA_STOCK_QTY_SFX', ' Available');

> 
> Changed /includes/classes/pad_sba_sequenced_dropdowns.php (lines 506 +)
> ```
        if ($curattr == sizeof($attributes) - 2) {
          if (STOCK_SHOW_ATTRIB_LEVEL_STOCK == 'true') {
          //$out.=" + '" . PWA_STOCK_QTY . "' + stk2";
            $out.=" + '" . PWA_STOCK_QTY_PFX . "' + stk2";//Put prefix here
            $out.=$outArray;
            $out.="[opt]";
          }
        }
      //$out.=",opt.substring(1));\n";
        $out.="+ '" . PWA_STOCK_QTY_SFX . "',opt.substring(1));\n";//Added the suffix here
        $out.="        } else {\n";

Now for the second dropdown it shows
Black :2 Available
Blue :4 Available
Green :2 Available
Red :3 Available

...which works for us and is flexible should our passions change.

This will totally puke, since "stk2" is the name of the array holding the second-tier attributes stock quantities, which has to be accessed to determine the quantity. Once I got it to work with Prefix and Suffix, this is how the relevant line of Java is put together:

frm['id[6]'].options[frm['id[6]'].length]=new Option(htmlEnDeCode.htmlDecode(txt6[opt]) + ' :' + stk2['_'+frm['id[1]'].value][opt]+ ' Available',opt.substring(1));

> It worked fine with just a prefix, but the suffix gets in the way of accessing the array.

Pushed this solution to single attribute dropdowns as well...Once implemented, any changes to prefix or suffix will hit single and multi-attribute dropdowns simultaneously

/includes/classes/observers/class.products_with_attributes_stock.php (line ~158 +)
          if (STOCK_SHOW_ATTRIB_LEVEL_STOCK == 'true' && $products_options->fields['pasqty'] > 0) {

//test, only applicable to products with-out the read-only attribute set
if ($products_options_DISPLAYONLY->fields['attributes_display_only'] < 1) {
//$PWA_STOCK_QTY = PWA_STOCK_QTY . $products_options->fields['pasqty'] . ' ';
$PWA_STOCK_QTY = PWA_STOCK_QTY_PFX . $products_options->fields['pasqty'] . PWA_STOCK_QTY_SFX .' ';//Changed to Prefix, added Suffix
//show custom ID if flag set to true
if (STOCK_SBA_DISPLAY_CUSTOMID == 'true' AND ! empty($products_options->fields['customid'])) {
$PWA_STOCK_QTY .= ' (' . $products_options->fields['customid'] . ') ';//We have this commented out to prevent customids in the dropdowns, but allow them on shopping cart and pick lists
}
}

14 Jan 2016, 23:53
#2459
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

Thanks for doing all the leg work, I did kind of think it wouldn't quite be as easy as I described, but I still think it can be... More to follow on that. :) glad that the issue was resolved and shared with others...

As to the customid on the multiple attributes, I actually thought I hadn't included it yet, but am wrong based on the commenting out of the code above... Need an if statement surrounding that line to evaulate against the same constant that was added in the other file where it was presented in three rows of the file... Also need to incorporate a prefix/suffix to the model# as well to expand on user modification options...

Thanks again!!!

17 Jan 2016, 16:07
#2460
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

Discovered while viewing a customer's order in admin:
criteria to reproduce:
product has attributes, but product is not tracked by SBA and STOCK_SBA_DISPLAY_CUSTOMID == 'true' (ie. expecting to have the custom_id displayed).

SQL error thrown at line 794 of admin/includes/classes/products_with_attributes_stock.php

Error is equivalent to below:

PHP Fatal 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 ')' at line 4 :: select customid as products_model
                                      from products_with_attributes_stock 
                                      where products_id = 5 
                                      and stock_attributes in () ==> (as called by) path_to_admin/includes/classes/products_with_attributes_stock.php on line 794 <== in path_to_store_includes/classes/db/mysql/query_factory.php on line 155

Error may be slightly different on various ZC versions (ie. the line number associated to query_factory.php); however, the above was from running on ZC 1.5.3. The same issue would occur on any version of ZC that this code is run.

How to fix:
replace line 787 with:

        if ([B]$attribute_stock->RecordCount() > 0 && [/B]!$customid->RecordCount()){ // if a customid does not exist for the combination of attributes then perhaps the attributes are individually listed.

Original code in this "area":

if(is_array($attributes) and sizeof($attributes) > 0){
              // check if attribute stock values have been set for the product
              // if there are will we continue, otherwise we'll use product level data
            $attribute_stock = $db->Execute("select stock_id 
                                                  from " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " 
                                                  where products_id = " . (int)$products_id . ";");
      
              if ($attribute_stock->RecordCount() > 0) {
                  // search for details for the particular attributes combination
                      $first_search = 'where options_values_id in ("'.implode('","',$attributes).'")';
                  
                  // obtain the attribute ids
                  $query = 'select products_attributes_id 
                          from '.TABLE_PRODUCTS_ATTRIBUTES.' 
                                  '.$first_search.' 
                                  and products_id='.$products_id.' 
                                  order by products_attributes_id;';
                  $attributes_new = $db->Execute($query);
                  
                  while(!$attributes_new->EOF){
                      $stock_attributes[] = $attributes_new->fields['products_attributes_id'];
                      $attributes_new->MoveNext();
                  }

                $stock_attributes_comb = implode(',',$stock_attributes);
              }
              
              //Get product model
              $customid_model_query = 'select products_model 
                                              from '.TABLE_PRODUCTS.' 
                                              where products_id = '. (int)$products_id . ';';

              //Get custom id as products_model
              $customid_query = 'select customid as products_model
                                      from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' 
                                      where products_id = :products_id: 
                                      and stock_attributes in (:stock_attributes:);'; 
        $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer');
        $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'string');
          $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made
        if (!$customid->RecordCount()){ // if a customid does not exist for the combination of attributes then perhaps the attributes are individually listed.
                $customid_query = 'select customid as products_model
                                      from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' 
                                      where products_id = :products_id: 
                                      and stock_attributes in (:stock_attributes:)'; 
          $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer');
          $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'passthru');
              $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made
        }
          }

Revised Code:

if(is_array($attributes) and sizeof($attributes) > 0){
              // check if attribute stock values have been set for the product
              // if there are will we continue, otherwise we'll use product level data
            $attribute_stock = $db->Execute("select stock_id 
                                                  from " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " 
                                                  where products_id = " . (int)$products_id . ";");
      
              if ($attribute_stock->RecordCount() > 0) {
                  // search for details for the particular attributes combination
                      $first_search = 'where options_values_id in ("'.implode('","',$attributes).'")';
                  
                  // obtain the attribute ids
                  $query = 'select products_attributes_id 
                          from '.TABLE_PRODUCTS_ATTRIBUTES.' 
                                  '.$first_search.' 
                                  and products_id='.$products_id.' 
                                  order by products_attributes_id;';
                  $attributes_new = $db->Execute($query);
                  
                  while(!$attributes_new->EOF){
                      $stock_attributes[] = $attributes_new->fields['products_attributes_id'];
                      $attributes_new->MoveNext();
                  }

                $stock_attributes_comb = implode(',',$stock_attributes);
              }
              
              //Get product model
              $customid_model_query = 'select products_model 
                                              from '.TABLE_PRODUCTS.' 
                                              where products_id = '. (int)$products_id . ';';

              //Get custom id as products_model
              $customid_query = 'select customid as products_model
                                      from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' 
                                      where products_id = :products_id: 
                                      and stock_attributes in (:stock_attributes:);'; 
        $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer');
        $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'string');
          $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made
        if ([B]$attribute_stock->RecordCount() > 0 && [/B]!$customid->RecordCount()){ // if a customid does not exist for the combination of attributes then perhaps the attributes are individually listed.
                $customid_query = 'select customid as products_model
                                      from '.TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK.' 
                                      where products_id = :products_id: 
                                      and stock_attributes in (:stock_attributes:)'; 
          $customid_query = $db->bindVars($customid_query, ':products_id:', $products_id, 'integer');
          $customid_query = $db->bindVars($customid_query, ':stock_attributes:', $stock_attributes_comb, 'passthru');
              $customid = $db->Execute($customid_query); //moved to inside this loop as for some reason it has made
        }
          }

FWIW, the above is expected to be revised again, there are some additional logic functions that can be applied to provide a smoother operation and would have prevented finding that error. Ie., the error was present because any check performed regarding if the products_id in question was tracked by SBA did not properly/promptly address that condition... Now there is actually a function that returns a true/false condition if a product is tracked by SBA and therefore, that can be incorporated up front and any "special" custom_id handling after that. To be addressed in a later change.