Manufacturers deleteion

Open to all! Ask other shopowners for help.
Post Reply
MyGamesShop
Contributor
Posts: 131
Joined: Wed Mar 10, 2021 3:02 am
Phoenix Version: v1.1.0.6
Has thanked: 8 times
Been thanked: 5 times

Manufacturers deleteion

Post 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)
Last edited by MyGamesShop on Sun May 18, 2025 1:07 am, edited 1 time in total.


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Manufacturers deleteion

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
MyGamesShop
Contributor
Posts: 131
Joined: Wed Mar 10, 2021 3:02 am
Phoenix Version: v1.1.0.6
Has thanked: 8 times
Been thanked: 5 times

Re: Manufacturers deleteion

Post 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)
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Manufacturers deleteion

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Manufacturers deleteion

Post by burt »

I am not here to build for you.
I am here to build with you. Let's help each other.
MyGamesShop
Contributor
Posts: 131
Joined: Wed Mar 10, 2021 3:02 am
Phoenix Version: v1.1.0.6
Has thanked: 8 times
Been thanked: 5 times

Re: Manufacturers deleteion

Post 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.
User avatar
burt
Core Team
Posts: 4551
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Manufacturers deleteion

Post 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;
I am not here to build for you.
I am here to build with you. Let's help each other.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply