Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8: Fix cannot remove category on admin product edit categories tab #2205

Conversation

iamniels
Copy link
Contributor

@iamniels iamniels commented Jun 8, 2022

Description (*)

On PHP 8.0, ids in the category tree JSON are rendered as integers instead of as strings on previous PHP versions. Whether this has something to do with Mage_Adminhtml_Block_Catalog_Category_Tree::_getNodeJson, with Zend_Json::encode or with json_encode is unknown to me and not relevant for this PR and worth another discussion.

The issue fixed in this PR is that with PHP 8.0+ a product cannot be removed from categories in the categories tab of the product edit view. This is because the ids in the JSON provided by Magento to populate the categories tree (with bildCategoryTree) are integers instead of strings previously. The JS function categoryRemove() in categories.phtml can only handle ids as strings.

The best solution imho is to make categoryRemove() a bit more robust and support both integers and strings.

Manual testing scenario of solved issue

  1. Go to categories tree in product edit view and deselect a checkbox.
  2. Save product
  3. Category checkbox is selected again.

@github-actions github-actions bot added Component: Adminhtml Relates to Mage_Adminhtml Component: Catalog Relates to Mage_Catalog Template : admin Relates to admin template labels Jun 8, 2022
@elidrissidev
Copy link
Member

This seems to be related to the database adapter. If you try getting the Id field of any model it will return a string pre-PHP 8 and an integer starting from PHP 8.

@fballiano
Copy link
Contributor

This seems to be related to the database adapter. If you try getting the Id field of any model it will return a string pre-PHP 8 and an integer starting from PHP 8.

yes but ''+id doesn't seem very easy to understand, i'd use id.toString() if possible

@elidrissidev
Copy link
Member

Agreed

@fballiano
Copy link
Contributor

@iamniels can you give a test to the version I pushed? hope it's fine :-)

@Sdfendor
Copy link
Contributor

Sdfendor commented Jun 9, 2022

@elidrissidev

string pre-PHP 8 and an integer starting from PHP 8.

I made the same observation but the change e.g. with ID (integer) data from the database adapter, happened with PHP 8.1, in PHP 8.0 the DB delivers still string. We have code in our shops in place to take that into account since we frist tried out OM with PHP 8.1.

@elidrissidev
Copy link
Member

@Sdfendor You must be right then as I only tested this with 7.4 and 8.1

Copy link
Member

@elidrissidev elidrissidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well

@fballiano fballiano merged commit 3005c60 into OpenMage:1.9.4.x Jun 9, 2022
@iamniels iamniels deleted the Fix_cannot_remove_category_in_admin_product_edit_categories_tab branch June 10, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Adminhtml Relates to Mage_Adminhtml Component: Catalog Relates to Mage_Catalog Template : admin Relates to admin template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants