Page 1 of 1

Manufacturers deleteion

Posted: Sat May 17, 2025 4:48 am
by MyGamesShop
I'm dealing with an error in the server log that's just annoying. I have a Franken-Phoenix part Git Head 1.1.0.3 with a restored database from 1.0.9.?.

AH01071: Got error 'PHP message: No unique manufacturer for [203:1]; PHP message: PHP Warning: Undefined array key "manufacturers Blah Blah Blah....

There is no manufacturer with ID 203 as it was deleted ages ago.
I recreated a fake entry for it in sql and then deleted it in the Admin panel.
I notice that the SQL in the product still shows the manufacturer as 203 so the error will remain.

When deleting a manufacturer it might be a good idea to have the code NULL it in each of the products.

I know can get rid of the error by creating a fake manufacturer as 203 or NULL it in the product but that's not the best solution

Just saying. (Edit: This post contains an incorrect correction read below)

Re: Manufacturers deleteion

Posted: Sat May 17, 2025 8:24 am
by burt
Do you mean like this:

https://github.com/CE-PhoenixCart/Phoen ... rm.php#L33

which has existed for-ever?

For example in 1.0.2.2 which is a decade old more or less;
https://github.com/CE-PhoenixCart/Phoen ... s.php#L102

I'm almost certain the problem is your data, not Phoenix's code.

Re: Manufacturers deleteion

Posted: Sun May 18, 2025 12:53 am
by MyGamesShop
I'm almost certain the problem is your data, not Phoenix's code.
Yes its the old data and it should be 0 not NULL as incorrectly stated above for anyone who is manually fixing it for some reason or you will get lots of htmlspecialchars() errors......

Thanks Burt I was looking everywhere for that code to find!! I really need an IDE.

If I may ask however to complete my journey into this.
Why is it defaulted in the sql as : manufacturers_id int(11) Yes NULL
It appears that if I leave the manufacturer not input on a new product it is set to 0
Which of course is less than 1 being the first manufacturer to be setup and I guess reduces the non (int) NULL handling code.
What would be the benefit of setting it as NUL in the [install] sql setup and not 0 as default?

Maybe create some kind of 'No Manufacturer' as 0 at install just for understand-ability.

And last of all:
$db->query("UPDATE products SET manufacturers_id = '' WHERE manufacturers_id = " . (int)$manufacturers_id);
how is'' equal to 0 when its not stated as '0'?

I'm guessing you 'know' these things from experience and reading all the code.
(I know its not a coding forum but hey I'm learning)

Mark (I will another beer you for your answer and work on that image search)

Re: Manufacturers deleteion

Posted: Sun May 18, 2025 1:54 pm
by burt
Probably some throwback to osCommerce days.
Parts of Phoenix has not really been overhauled in any meaningful way.

The update should properly be setting manufacturers_id back to NULL, not ''

I'll look into it for the next version, as it might not be as simple as just changing that line of code.

Re: Manufacturers deleteion

Posted: Mon May 19, 2025 4:02 pm
by burt

Re: Manufacturers deleteion

Posted: Wed May 21, 2025 6:55 am
by MyGamesShop
In a perfect world NULL would never get read here. The issue actually came to notice from bots scripts in the advanced search error-ing onto the log missing manufacturer [0,1] and my missing manufacturer [203,1] error.
Again it would be nice to limit the characters input and type into the search fields (no I haven't looked to see if that's done) I have other issues ATM more concerning.

Your beer will come along soon in a few days on a bit more turn over. Thankyou Burt, Mark.

Re: Manufacturers deleteion

Posted: Fri May 23, 2025 11:36 am
by burt

Code: Select all

UPDATE products SET manufacturers_id = NULL where manufacturers_id = 0
No product should have a manufacturer of 0 (Zero)..
I'll make sure to note this SQL change in the upcoming 1.1.0.3

--

I have NOT TESTED the following code, so beware.
This code *should* update the products table, setting manufacturers_id to NULL if any manufacturer does not exist.

Code: Select all

UPDATE products p
LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
SET p.manufacturers_id = NULL
WHERE m.manufacturers_id IS NULL AND p.manufacturers_id IS NOT NULL;