-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Adds configurable columns to product grid #3451
base: main
Are you sure you want to change the base?
Conversation
Imho this should be made optional. Our instance doesnt have images, instead they are coming from CDN anyways and we've overwritten the parts, but it would make it (I think) like we have "none" images for any product - and simply add a column for no reason. Also I think some vendors doesnt want that even if they have their product images attached to magento. |
We should have the implementation of Magento 2 grids in OpenMage, but more extensive changes are needed. There are a lot of implementations all over the Internet and for a while I considered displaying an image in the grid as useful for quick visual identification of the product, but the feedback I received was negative. First of all, the grid was getting bigger, especially when 200 products were viewed on the page. The page loading time increases, there are requests for each individual image. I could agree with this PR only if there is also the option to disable the display of the column in product grid, which should be implicitly set in Backend to No. |
... there must be the option of control in the Backend for each individual grid where images are displayed: Product Grid, Category Grid, Related/Up-sells/Cross-sells Grids. |
I agree, I will convert this PR into a draft because I want to immediately configure the choice of columns to display, which by default does nothing in order to avoid any compatibility and performance issues. I will complete the PR in the next few days while waiting for further feedback. |
In addition, we must set up in the Backend, in the same section that controls each individual grid, the size of the image. Displaying an image of 64 px height compared to 200 displayed products on the page or maybe even more if someone uses other custom values, will increase the use of the scroll, will at least triple the display. |
What do you think about last commit be9d683? I've used traits to add columns to the grid and i've added configuration to enable product image column and setting the width. If this path can be ok, I can proceed with additional features and reorganize the configuration more effectively, for which I would dedicate a separate tab. Same questions about:
PS: phpstan report that traits cannot have constant, but using self it's ok then
waiting for feedback |
I would like to be able to control the display of the column in each of the 5 grids where it appears: Product, Category, Up-Sells, Cross-Sells, Related. From the attached image it appears that it is a unitary control and not an individual one. The idea of using multiselect is not a bad one
Product - Image Thumbnail But if he has other custom grids then he will no longer have control. I think it would have been better to have a discussion in the dedicated section about this idea and then you could proceed to its implementation. |
Yes, through the trait and the way I have organized the code, I would be able to implement dedicated configurations for each type of grid (catalog_product, catalog_category/product, upsell, related, crossell, and other grids like sales), where you can set additional columns besides the product image a its order. |
you can revert the changes if you feel so, I did only we we agreed on. I asked about the doublescroll because it didn't feel related to this PR (the name) and I didn't read the content of the file. Now I think I get why is that. it does the horizontal scrolling of the grid. |
Sure, should I manually revert your single commits eventually then force a push, or is there a simpler method (maybe from github ui)? |
if you git revert a commit you don't have to force push |
Is it possible to limit specific section / field config by ACL? I haven't done it before... i tried
|
AFAIK ACLs can't be applied to system/configurations |
createDoubleScroll() { | ||
let scrollbarTop = document.createElement('div'); | ||
scrollbarTop.classList.add('hor-scroll-top'); | ||
scrollbarTop.appendChild(document.createElement('div')); | ||
scrollbarTop.style.overflow = 'auto'; | ||
scrollbarTop.style.overflowY = 'hidden'; | ||
scrollbarTop.firstChild.style.height = '0'; | ||
scrollbarTop.firstChild.style.paddingTop = '1px'; | ||
scrollbarTop.firstChild.appendChild(document.createTextNode('\xA0')); | ||
this.wrapperScrollBar.parentNode.insertBefore(scrollbarTop, this.wrapperScrollBar); | ||
|
||
this.scrollbarTop = scrollbarTop; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've read this file in more detail, the only thing that I'd try to do, in order to avoid as much javascript as possible, is to have this div directly into the widget/grid.phtml
it should work ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's so better only for save a few lines because if someone overwrites grid.phtml we lost it.
If you care about its size we can minify it as mage/adminhtml/grid-double-scroll.min.js and distribute also the original source mage/adminhtml/grid-double-scroll.js and can be done to others files like grid.js.
More javascript is not necessary bad if it's usefull, IMHO this is a usefull feature because if the columns don't fit in the window and I want to view the last column in a particular row, I have to scroll down to the end and then up to that row.
If we compare to other modern backends like Magento 2, our JS/Memory footprint is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really woulnd't compare anything to M2 and I still believe, also from a performance standpoint, there's no need for element injection in js
and it shouldn't be minified either in the source code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's leave this decision pending for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, grid.phtml is already modified by this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you tested if it works correctly when there are more grids like in product view (related, upsell etc..) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script, as it is, is independent from the template. The only requirement is that the table is wrapped inside a div.hor-scroll, so it would also work on third-party implementations with a custom template that not include div.hor-scroll-top
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the moment the script is called by a modified version of the template so it wouldn't work. I understand that it is callable by any situation but I'll never agree that many lines of javascript are better than 1 line of html + 1 line of css, both for readability and performance.
people may have a customized grid.html (doubt it but possible) but they could also have customized layout xml so the script won't be loaded, both approaches have pros and cons but the script is not 100% better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the moment the script is called by a modified version of the template so it wouldn't work
Then the script should be modified to work with this external div, with all handling of the events relative to the current grid
people may have a customized grid.html (doubt it but possible) but they could also have customized layout xml so the script won't be loaded, both approaches have pros and cons but the script is not 100% better.
This is not necessarily true, the script should always be injected as grid.js unless explicitly removed in a layout update.
IMHO I prefer to keep grid.phtml clean without a div that is not clear what it does, in terms of performance it doesn't change anything.
But these are just details, the priority for me is that PR should be tested and reviewed on its implementation solution with interface contract, naming convention, etc.
For system config ACL read https://alanastorm.com/custom_magento_system_configuration/ Maybe it helps. Does it still work to add grid columns via observer? |
Suggestions:
|
yes |
can't add an acl for system config |
If it does not work to set ACL "one level deeper" to config section i think its worth to raise an issue. |
no it's a different type of ACL |
I am not sure about it, but EnhancedGrid extension has a user based grid config. (or it was a modified version of it) |
yes it has it, but it works differently it doesn't save in system config but it has two tables |
This add new configuration to choose columns for catalog product list, i think this is an important feature to add to OpenMage.
IMPORTANT:
Original solution with trait has been replaced with a new flexible architecture that follow magento way, inspiration from massaction grid component.
Also create an interface to implement custom columns in other grids easily keeping the code well organized.
All the relevant classes that extend
Mage_Adminhtml_Block_Widget_Grid
have been restored to their original state.Technical details
To modify the grid columns, two things need to be done:
For this reason, the class
Mage_Adminhtml_Block_Widget_Grid
initialize an helper that must implements two methods for this purpose.The helper is bound by a contract with the interface
Mage_Adminhtml_Helper_Widget_Grid_Config_Interface
, which requires the implementation of the two methods:public function applyAdvancedGridCollection($collection);
This method is called by 'Mage_Adminhtml_Block_Widget_Grid' after
_prepareCollection()
and allows to modify the collection by accessing the$collection->addAttributeToSelect
and other methods.public function applyAdvancedGridColumn($gridBlock);
This method is called after
_prepareColumns
and allows adding new columns to the grid by accessing the$gridBlock->addColumnAfter()
and all the public methods ofMage_Adminhtml_Block_Widget_Grid
.Here, for example, I quickly implemented a new field in the orders grid:
empiricompany@b40ae34
(without system configuration)
The helper for advanced grid is initialized like this.
Here, I have made a note that a factory class would be needed.
The identification of the correct helper by checking block id avoids setting the helper manually in each relevant class.
I'm thinking about a new configuration file called grid.xml that maps grid IDs to helpers and a factory class.
Otherwise, and it remains an option, we should specify an helper for advanced grid like this:
Column sorting
To manage column sorting the class
Mage_Adminhtml_Block_Widget_Grid
adds the blockadminhtml/widget_grid_advanced
(as massaction) to the 'grid.phtml' template.The block is then called in grid.phtml, after massactionblock:
This block inserts the JavaScript that will handle the sorting by initializing 'varienGridAdvanced' (included in grid.js)
PS: This block can also be used to insert a reset button for column order.
For this feature a new controller Mage_Adminhtml_GridController has been created.
The columns can be sorted using drag & drop. Upon the drop event, an AJAX call to
adminhtml/grid/saveColumnOrder
is made, and the sequence of columns is saved in system_configadvanced_grid/_id_of_grid_/order
.Then the grid reloads as usual through AJAX, similar to a search.
Features:
I have added a new column renderer for product images. The images are resized to 64px by default to reduce file size, and they are generated in media/catalog/product/cache/0/64x64/ directory.
Image previews are linked to the original url.
This is a proof of concept - Not ready for production
I have not tested yet with php 7.4, only php 8.2
It should be perfectly compatible with any existing columns added by overwriting the classes that extend Mage_Adminhtml_Block_Widget_Grid, like Mage_Adminhtml_Block_Catalog_Product_Grid.
Knowed Bugs / Issues:
Phpstan doesn't like constants in traits, even though in theory they seem to not cause any problems when called with self like: self::CONFIG_PATH_GRID_ENABLEDref: https://wiki.php.net/rfc/constants_in_traits
Costants moved to a dedicated helper Mage_Adminhtml_Helper_Widget_Grid_Config
Improvements:
Code Refactoring