lat9 / usu

Ultimate SEO URLs for Zen Cart
GNU General Public License v3.0
1 stars 5 forks source link

MySQL Fatal Error when a product has a `products_description` entry, but none in `products` #46

Closed proseLA closed 2 years ago

proseLA commented 2 years ago

https://github.com/lat9/usu/blob/457f840a3592aeb9fb7179d0ae2e409cb6e625d7/includes/classes/usu.php#L899-L904

this thread has exposed a bug: https://tinyurl.com/y2aty628

here is some sample code to illustrate:

$cID = '_';

    if (strpos($cID, '_') !== false) {
        $temp = explode('_', $cID);
        $original = array_pop($temp);
        echo "-------->" . $original . "<---------<br>";
        print_r($temp);
        die(__FILE__ . ':' . __LINE__);
    }

results of said test are:

--------><---------
Array ( [0] => )

because the original is being passed back by reference, it needs to be cast back to an integer. or i'm sure there are other solutions as well...

lat9 commented 2 years ago

The underlying issue, I think, is/was that the product for which a URL is to be built is not present, resulting in a NULL return from zen_get_products_category_id. I've tried to reproduce the issue, but have been unable to. It looks like all other cases within /includes/classes/usu.php that use that function cast its return to an int, other than the call in the class' get_product_canonical method.

Noting that, while the code fragment provided can induce the issue, I'd be more comfortable that a solution really works if I could find a way to force the error via a misconfigured Zen Cart product. I've tried simply referencing an invalid product (as indicated in the debug-log supplied in the Zen Cart posting that you identified), but with no luck.

Either way, I believe the source of the issue is that missing cast in get_product_canonical, so that's the way I'm tending. Thanks for the investigation, it helped a lot!

lat9 commented 2 years ago

OK, issue reproduced. Turns out the issue is caused by a product that has an entry in the products_description table, but not in the products (what a mess!).

Adding that additional cast identified above results in the product being "not found" (as expected).