zamzom:
Trying to run SBA 1.5.4 for [ZC 1.5.8][PHP 8.0]
Few remarks for some errors in admin/products_with_attributes_stock page.
First it gives the following error
--> PHP Fatal error: 1064:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 0, 1' at line 1
In admin/includes/classes/products_with_attributes_stock.php
on around line 376:
$query_products = "SELECT DISTINCT " . $retFieldsTxt . ((empty($search_order_by_fields) || empty($retFieldsTxt)) ? '' : ', ') . $search_order_by_fields . "
FROM " . TABLE_PRODUCTS_ATTRIBUTES . " pa
INNER JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON (pa.products_id = pd.products_id)
INNER JOIN " . TABLE_PRODUCTS . " p ON (pa.products_id = p.products_id)
WHERE
pd.language_id=" . (int)$language_id . "
" . $w . "
ORDER BY " . $search_order_by;
// . $SearchRange; // zamzom: Took it out, because splitPageResults adds another LIMIT which triggers MySql error
if (!isset($_GET['seachPID']) && !isset($_GET['pwas-search-button']) && !isset($_GET['updateReturnedPID'])) {
$products_split = new splitPageResults($_GET['page'], STOCK_SET_SBA_NUMRECORDS, $query_products, $products_query_numrows);
}
> $SearchRange already carries a MySql LIMIT statement, however a consequtively coming call to splitPageResults adds another LIMIT statement so this triggers an error. I think the first $SearchRange can be ommited?
>
> Secondly, search does not function. It seems earlier search parameter was input through a Get statement (in admin/products_with_attributes_stock.php) however in the latest it was converted to a Post method. Nevertheless again in admin/includes/classes/products_with_attributes_stock.php around line 277
> ```php
if (isset($_GET['search']) && $_GET['search']) { // mc12345678 Why was $_GET['search'] omitted?
$s = zen_db_input($_GET['search']);
//$w = "(p.products_id = '$s' OR d.products_name LIKE '%$s%' OR p.products_model LIKE '%$s%') AND " ;//original version of search
//$w = "( p.products_id = '$s' OR d.products_name LIKE '%$s%' OR p.products_model LIKE '$s%' ) AND " ;//changed search to products_model 'startes with'.
//$w = "( p.products_id = '$s' OR d.products_name LIKE '%$s%' ) AND " ;//removed products_model from search
$w = " AND ( p.products_id = '$s'
OR d.products_name LIKE '%$s%'
OR p.products_model LIKE '%$s%'
OR p.products_id
IN (SELECT products_id
FROM " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
WHERE pwas.customid
LIKE '%$s%')
) "; //changed search to products_model 'starts with'.
}
//Show last edited record or Limit number of records displayed on page
$SearchRange = null;
if (isset($ReturnedProductID) && !isset($_GET['search'])) {
$ReturnedProductID = zen_db_input($ReturnedProductID);
//$w = "( p.products_id = '$ReturnedProductID' ) AND " ;//sets returned record to display
$w = " AND ( p.products_id = '$ReturnedProductID' ) " ;//sets returned record to display
if (empty($_GET['products_filter']) || $_GET['products_filter'] < 0) {
$SearchRange = "LIMIT 1";//show only selected record
}
Get statements are used and these don't get anything :no: I think all of the $_GET['search'] should be replaced by $_POST['search']
also there is an error with the $w assignment, the tag for product description table should be pd instead of d, again around line 282:
$w = " AND ( p.products_id = '$s'
OR pd.products_name LIKE '%$s%'
OR p.products_model LIKE '%$s%'
OR p.products_id
IN (SELECT products_id
FROM " . TABLE_PRODUCTS_WITH_ATTRIBUTES_STOCK . " pwas
WHERE pwas.customid
LIKE '%$s%')
) "; //changed search to products_model 'starts with'.
Please note, I am not necessarily responding to the "latest" or one that has the "most detail". Please forgive me as it looks like 6 posts were made to say the same thing, with this first one effectively addressing all of the issues at once. I'm ok with responding to the entirety.
Fatal error because of the changes made to the splitPageResults class, I'm addressing that by evaluating the constructor for the class to determine how to respond. In Zen Cart 1.5.7 and below, any such "LIMIT" statement was basically removed/ignored. I haven't gone back through all of the code to see if the use of LIMIT is at all necessary, but at one time it was and so I'm keeping its potential for existence in "older" versions, but removing it from queries that are directly fed into the splitPageResults query basically of Zen Cart 1.5.8.
Then, the search feature. Kind of funny, I think that I vaguely recall noticing that "recently" the search really only worked by selection of product from the various dropdowns. No one has said anything in the last 3 years since that change was made. Too bad really. Lack of statement of that issue has a lot of meanings. I thank you for pointing it out and therefore driving for solution. So, what I did instead of modifying the $_GET to $_POST was to instead assign the $_GET to the $_POST. In all cases when both are available, POST should override GET for security purposes. That is now done here as well with the search.
The table prefix of 'd' for product description? Unfortunately that was how we had been referencing the products_description table. At one point or another, effort was made to align the table references with those "standard" in Zen Cart, even if that itself is not consistent. I've updated references.
Then, because of discrepancies in how Zen Cart has handled strings containing NULL, code that has been incorporated uses a method of the query_factory that in Zen Cart 1.5.8 has become protected. Yes, the same result could have been obtained using what is now a public method; however, at the time of incorporation I specifically chose to use the unique method (getBindVarValue) instead of the method that was perceived as malleable and basically required a dummy value to perform the test directly accomplished by getBindVarValue.
BTW, thank you for the explanation of why the previous posts were made first as a single and applicable post and then split up. Although you've requested the other posts to be deleted, I wouldn't be surprised if they remain. There's no telling if or how many of them already have been referenced elsewhere on the internet. No harm though in them remaining either. :)
As to solution, I didn't yet pretty up the commits, but if you grab the code from this branch/commit, it addresses the items you've identified and others that were identified while addressing them: <https://github.com/mc12345678/Stock_By_Attributes_Combined/commit/19ea27f4ac8334a4b4c61569d77461d52e940d29>
I'm still working through what was recently otherwise posted and doing a comparison against the Zen Cart 1.5.8 version of the shopping cart class to address improvements to the extra_cart_actions file.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...