How to display all products on one page in Magento 2
Hi Everybody, I am Cuong, Welcome back to my Magento 2 tutorial video series.
Today, I am going to show everybody a best practice, How to display all products on one page in Magento 2. I mean create a page show all products in Magento 2.
In this exercise, I am going to create a page called “One Page Products”, that it will display all products same as the category detail page.
To complete this best practice please follow the below steps:
Step 1: Create a new module named PHPCuong_OnePageProducts
– Create the namespace PHPCuong in the path appcode.
– Create the module named OnePageProducts in the path appcodePHPCuong.
– Create the file named registration.php in the path appcodePHPCuongOnePageProducts
– Create the file named module.xml in the path appcodePHPCuongOnePageProductsetc
End of the step #1, I have been completed the steps to declare the new module.
Step 2: Declare the route named phpcuong to accessing this page
– Create the file named routes.xml in the path appcodePHPCuongOnePageProductsetcfrontend
Step 3: Create the action named Onepage in the controller named Product
– Create the Onepage.php file in the path appcodePHPCuongOnePageProductsControllerProduct
Step 4: Create the layout named phpcuong_product_onepage.xml
– The structure of a layout will be routeName_controllerName_actionName.xml
– Create the phpcuong_product_onepage.xml layout in the path appcodePHPCuongOnePageProductsviewfrontendlayout
Step 5: Install the new module
Run the command line:
– php bin/magento setup:upgrade –keep-generated
Step 6: Test and see the results
– Go to the page with the path phpcuong/product/onepage
Thank you for your watching. If you have any questions about this best practice please feel free to leave a comment below.
Don’t forget to like, comment, share and subscribe to my channel for getting the latest videos.
Please do not hesitate to contact me if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.
Get the source codes of this tutorial at the github: