Magento 2 Certified Associate Developer — Question 3
A client has asked you to include category url keys in product URLs.
How is this done?
Answer options
- A. Create an observer for controller_action_postdispatch_catalog_product_view
- B. This is not possible because products can belong to multiple categories
- C. Set the configuration value of catalog/seo/product_use_categories to Yes
- D. Create an after plugin on \Magento\UrlRewrite\Controller\Router::generateRewrite
Correct answer: D
Explanation
The correct approach is to create an after plugin on \Magento\UrlRewrite\Controller\Router::generateRewrite, as this allows for the modification of URL generation to include category keys. Option A is incorrect because observers do not directly influence URL generation in this context. Option B is not valid as it is indeed possible to include category URL keys. Option C does not provide the necessary method to implement this requirement.