- Magento 2 Development Cookbook
- Bart Delvaux
- 878字
- 2021-07-30 09:46:22
Configuring the catalog defaults
One of the first things is to configure some default catalog settings to the preferred values. We will cover all the configuration values that are possible in a Magento 2 installation.
We will go through the available configurations and change some values to the recommended settings.
Getting ready
Open your frontend and log into the backend in a separate browser tab. We will modify some configuration values to the recommended settings. When changing a configuration value, we can check what happens in the frontend.
How to do it
In the next steps, we will take a look at the catalog settings:
- In the backend, navigate to Stores | Settings | Configuration. Open the Catalog menu, as we can see in the following screenshot:
- Open the Product Fields Auto-Generation section. In this section, we can configure the behavior of the generation of SKU and metadata. When we add the following values for the Mask for Meta Keywords, the SKU, name, and the string "Magento" will be generated when saving a product:
- {{sku}}, {{name}}, Magento
- Open the Storefront section and set the following values:
- List mode:
grid
(by default, this shows the products in a grid or list) - Products per page on Grid allowed values:
12
,24
,36
- Products per page on Grid default value:
24
Note
When changing the allowed and default value for a grid page, ensure that you can divide the numbers by the number of products that fit in a row in your theme. Otherwise, the last row of products will not be complete.
- Products per page on List allowed values:
10
,20
,30
,40
- Products per page on List default value:
10
- Allow all products per page:
No
Note
When you have a large number of products, it is not recommended to set the Allow all products per page option to
Yes
. When you have 2000 products and you want to show all the products on a single page, you will generate an enormous HTML output that can cause memory issues. - Product listing Sort by:
price
- Use Flat Catalog Category:
No
- Use Flat Catalog Product:
No
- Allow Dynamic Media URL's in Products and Categories:
Yes
- List mode:
- Enable the product reviews for guests. This allows everyone to write a review about a product. When this is enabled, a review form will appear on the product review page.
- Open the Product Alerts section to configure product alert e-mails that will be sent when the price or stock changes.
- We will configure a stock alert with the following settings:
- Allow alert when product price changes:
No
- Allow alert when product comes back in stock:
Yes
Note
The previous configurations will send stock alert e-mails (a stock alert is triggered when a product becomes available in stock) to the subscribed e-mail addresses.
- Allow alert when product price changes:
- We can set the values for Product Alerts Run settings in the next section. We will configure a daily task at 04:00 hours to send the alert e-mails:
- Frequency:
Daily
- Start time:
04:00:00
- Frequency:
- Leave the Product Image Placeholders options as they are. If we want, we can set a default image that will be shown when a product has no image or the image is not found. The best way is to set the placeholder images in the theme.
- In the Recently Viewed/Compared Products tab, set the following values:
- Show for current:
Website
Note
This will show the recent products you viewed over all stores and store views in the website.
- Default recently viewed count:
5
- Default recently compared count:
5
- Show for current:
- In the Price tab, set the Catalog Price Scope option as
Global
. For this tutorial, we don't need different prices for each store view. When Price Scope is set toGlobal
, we can only configure one global price for a product, which will be the same in all store views. - In the Layered Navigation section, we will modify some settings to customize the left navigation for the category pages:
- Display product count:
Yes
- Price navigation step calculation:
Automatic
(this will equalize price ranges)
- Display product count:
- By making these settings, the price steps will always have the same increment.
- Open the Category Top Navigation section, and set Maximal Depth to
3
. This means that the navigation will be shown with a maximum of three levels. - In the Changing the URL of a product page recipe, we will look at the Search Enginge Optimization step.
- Configure the Catalog Search section as follows:
- Minimal Query Length:
3
- Maximum Query Length:
128
- Search Engine:
MySQL
- Apply Layered Navigation if Search Results are Less Than:
0
Note
If a search result shows a lot of products, the generation of the layered navigation slows down the pageload. With this setting, you can disable the layered navigation if the results count is higher than the configured value.
- Minimal Query Length:
- Don't forget to save the configuration by clicking on the Save Config button.
How it works
All these settings are saved in the configuration table of Magento. The frontend files for the catalog pages will pick up these settings and render the output based on these settings.
When you add extra functionality to the category page, you can easily extend the configuration with extra parameters. More information about extending the configurations is given in the Extending the system configuration recipe of Chapter 6, Magento Backend.