Skip to main content
Share Your Experience: Take the 2024 Developer Survey
40 votes
Accepted

Magento2 - Get category URL by ID

In order to get the category url you need to use the \Magento\Catalog\Model\Category function getUrl() like so: $category->getUrl() Also, you can get url by CategoryRepositoryInterface ...
Amit Bera's user avatar
  • 77.5k
18 votes

Magento 2 Custom Admin Action Redirected to Dashboard

In routes.xml configuration file (companyName/customModule/etc/adminhtml/routes.xml). For me the solution was to have the route id and frontName have the same value. In your case this would be: <?...
Sankar_k's user avatar
  • 614
13 votes

Magento2 - Get category URL by ID

Always try to use repository. You need to inject following way: /** * @var \Magento\Catalog\Helper\Category */ protected $categoryHelper; /** * @var \Magento\Catalog\Model\CategoryRepository */ ...
Sohel Rana's user avatar
  • 35.9k
10 votes

Magento 2 : URL key For Specified Store Already Exists

I've fixed this issue. And I have 2 solutions for that. The first one: Clean up your database in table url_rewrite (Change the url_key of all category). You can write UpgradeData script for this ...
Toan Tam's user avatar
  • 1,328
9 votes
Accepted

Magento 2: Setting the product url key with REST API

Although Swagger doesn't specify "url_key", you can add this attribute value by the following method: { "product": { ... "customAttributes": [ { "attributeCode": "url_key", ...
PY Yick's user avatar
  • 2,705
7 votes

Magento2 - Get category URL by ID

You can try below code. $categoryId = 5; $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $object_manager = $_objectManager->create('Magento\Catalog\Model\Category')->load(...
Suresh Chikani's user avatar
7 votes

Error, "URL key for specified store already exists" When I'm Adding Products or Moving a Category

We had a similar issue where we couldn't save categories and after much database searching and debugging I found the issue was when it updated the product url's for the category. We'd imported and ...
Jason Watt's user avatar
6 votes

URL Key not changing in Magento 2

The issue resolved with below solution. As I said url_key was not regenerating only with Migrated Products from Magento 1 to Magento 2 with UB Migration Tool Lite Extension. At the time of Migrating ...
zubair's user avatar
  • 115
6 votes
Accepted

Export Product Sku and Product_Url in magento2

I got reference for the answer from this answer and I add addition part to show url_key column, please try this sql query : SELECT e.entity_id AS 'id', v1.value AS 'name', v0.value AS '...
mrfizh's user avatar
  • 1,363
5 votes

Magento2: How do I get product url key?

To get the url key you need to call UrlKey method as beleow $_product->getUrlKey(); Hope this will help..
Mohammad Mujassam's user avatar
4 votes

Magento2 - Get category URL by ID

If you care about performance, this is a light Model that you can inject and use. <?php declare(strict_types=1); namespace ModuleNamespace\ModuleName\Model; use Magento\CatalogUrlRewrite\Model\...
Danilo Argentiero's user avatar
4 votes

URL was already generated for an item with SKU. ERROR

This is strange bug in Magento. This will happened - if URL-key exist in Magento, and if Product name exist in Magento. If each Products will with Unique Name - will be all OK. Becouse URL-key based ...
Alex's user avatar
  • 486
4 votes
Accepted

Where can I find the product url key builder for Magento 2?

Following class is responsible for generating url key: vendor/magento/module-catalog-url-rewrite/Observer/ProductUrlKeyAutogeneratorObserver.php /** * @param \Magento\Framework\Event\Observer $...
Sohel Rana's user avatar
  • 35.9k
3 votes
Accepted

Magento 2 - change url-key for a category for all store views programatically

You can use below code to change url_key for category for all store. we do not have direct function to change for all store so looping is added according to stores. $this->_categoryModelFactory = $...
arushi's user avatar
  • 790
3 votes

Magento 2 : URL key For Specified Store Already Exists

The following approach works fine for me to resolve below issue. "URL key for specified store already exists." Step : 1 First, I have find out the above message by using grep command. ...
Jitendra Patel's user avatar
3 votes

Magento2: How do I get product url key?

Here is the method I used to get the product url. It is definitely not optimal as I have to load the entire product to get it so very bad in terms of performance. Create a block after that First you ...
Manish's user avatar
  • 3,116
3 votes

M2: Is `url_path` used for anything?

url_path is deprecated, and could safely delete its data. I tested it in my Magento 2.3.2. You could see the deprecated statement in the offical github comment and the graphql-ce codes. url_path: ...
Key Shang's user avatar
  • 3,425
3 votes

Magento 2 Custom Admin Action Redirected to Dashboard

The problem of the routing redirection with the security key enabled is the action url set in the menu.xml under /etc/adminhtml/ <?xml version="1.0" ?> <config xmlns:xsi="http:/...
Michelangelo's user avatar
3 votes

Magento 2 Custom Admin Action Redirected to Dashboard

When attempting to access modules/functionality in the backend (Adminhtml), Magento checks for the presence of the secret Form Keys, and if/when someone does attempt to access an action and doesn't ...
Sharath Kumar's user avatar
3 votes

Magento 2 - add prefix before category and products urls

Please check below ways which are working solution to add a prefix before the category and products URLs https://magecomp.com/blog/how-to-add-prefix-to-store-products-urls-in-magento-2/ Magento 2 .2 - ...
CoderKube Technologies's user avatar
2 votes

Show product URL Key with product ID

To get this: in Collection: $collection = Mage::getModel('catalog/product')->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('entity_id', array('in'=&...
PЯINCƎ's user avatar
  • 11.7k
2 votes

Magento2: How to generate admin url with secure key from a controller

You can generate secure admin url key by protected $urlBuider; public function __construct( .... \Magento\Backend\Model\UrlInterface $urlBuilder, .... ) { .... $this->...
HaFiz Umer's user avatar
  • 1,661
2 votes

M2: Is `url_path` used for anything?

"url_path" is used for url rewrites generation. Even in Magento 2.4.
Sergey Uskov's user avatar
2 votes
Accepted

Non-default store view URL 404

“Add Store Code to Urls” in Stores > Configuration > General > Web > URL options to see if it solves the problem.
Mehdi's user avatar
  • 878
2 votes

How to generate url-key for product programmatically

For Update Url Key : $product=Mage::getModel(‘catalog/product’)->load(34441); $old_url_key = $product->getUrlKey(); $product->setUrlKey($manufacturer . ’-’ . $old_url_key); $product->save(...
Harshil Parekh's user avatar
2 votes

Magento 1.9- Pass a Parameter to cms page url

You can't use following type of url for cms page example.com/custom-products/1 OR example.com/custom-products/param/1 Because CMS Router class take whole things as an identifier. In example it's ...
Sohel Rana's user avatar
  • 35.9k
2 votes
Accepted

Add a static URL prefix for product and category Magento 2

I found a good solution for this situation! We need to make our custom module for extending Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator class with plugin methods and Magento\...
Mehran Zarei's user avatar
2 votes

Some products have catalog/product/view/id/2221/name-of-the-product from product URL magento 2?

Note: Please take a backup of the database To resolve this issue first delete the rows from the "url_rewrite" table which has 'product' as 'entity_type'. You can use below query DELETE FROM `...
Kishor Thummar's user avatar
2 votes
Accepted

How to get product by url_key and store id magento 2

Use below code to load any product by filter url key and store id. $storeid = 1; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $collection = $...
Hitesh's user avatar
  • 1,569
2 votes
Accepted

What does this pattern match when filtering strings for URLs

This pattern #[^0-9a-z]+#i matches all NOT numeric and NOT alphabetical symbols, in other words it will replace any symbol which is NOT in range 0-9 or a-z with the - symbol. The ^ symbol inside ...
Siarhey Uchukhlebau's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible