In order to get the category url you need to use the \Magento\Catalog\Model\Category function getUrl() like so:
Also, you can get url by CategoryRepositoryInterface
This happens because 'secret key' is missing when you just type in URL manually.
Secret key feature is enabled by default and can be disabled here: Stores => Configuration => Advanced => Admin => Security => Add Secret Key to URLs. Then you should be able to reach your action.
In router.xml file (companyName/customModule/etc/adminhtml/router.xml) For me the solution was to have the route id and frontName have the same value. In your case this would be:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/...
Typically this is caused because you have categories or products with duplicate urls. i.e a category with www.example.com/hats and a product with same url. Every time you save the product you will incrementally increase the core rewrite. The number you see at the end of your URL. The other main culprit is configurable products.
Make sure the ...
From a controller you can simply use $this->getUrl('url/path/here', $paramsHere = array()).
From anywhere else:
You need to add an instance of \Magento\Framework\UrlInterface in your class and use that:
public function __construct(
Always try to use repository. You need to inject following way:
* @var \Magento\Catalog\Helper\Category
* @var \Magento\Catalog\Model\CategoryRepository
public function __construct(
You can try below code.
$categoryId = 5;
$_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$object_manager = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId);
Before you use a category id you have confirm category id exists in admin or it will ...
Although Swagger doesn't specify "url_key", you can add this attribute value by the following method:
Note: Next time, you can use GET to know the product JSON structure first. Then any customized ...
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 deleted products previously but found out they still had entries in the url_rewrite table. So the request_path already existed.
To clear it out I had to run the ...
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 solution.
The second one: Remove the duplication data when saving category.
This data is throw in method doReplace($urls) in \vendor\magento\module-url-rewrite\...
After running the import you need to re-index the Catalog URL Rewrites index. This will generate URL's for your products.
You can do so through the admin panel:
Admin Panel -> System -> Index Management -> Next to Catalog URL Rewrites Click Reindex Data
You can also reindex through a SSH session using the indexer.php file located in /magento_root/...
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 the products UB Migration Tool created multiple url_key and url_path entries for each product instead of creating just 1 entry for url_key. So I deleted the ...
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 'url_key',
d1.value AS 'price',
t1.value AS 'short_description',
t2.value AS 'description',
v2.value AS 'image',
There is no solution. Magento doesn't support that.
I wrote a module which checks the identifier and looks the translation in the config up, then it makes a redirect.
So you have two options:
choose one language and use it for everything - don't translate the url
implement some module which does what you want.
Instead of describing how to make this ...
Please check below ways which are working solution to add a prefix before the category and products URLs
Magento 2 .2 - How to add Static Product Prefix to Product Url?
Check it out you will get the idea and let me know if you still need any help.
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 supply a FormKey (e.g: hotlinking the url) and/or supplies an Invalid FormKey - the Adminhtml AbstractAction (Magento\Backend\App\AbstractAction) will route the ...
If product URLs issue is still same after re-index the indices. Then please perform following step carefully.
If your store is live then please put site on maintenance mode using (maintenance.flag file) for some minutes while you perform following steps.
Step 1: Take a backup of table core_url_rewrite
Step 2: TRUNCATE (empty) TABLE core_url_rewrite
The product urls (yes urlS because they can me more than one) are kept in the core_url_rewrite table.
if a record in that table has the field product_id not null then it belongs to the product and the request_path is what you are looking for.
But you can have multiple cases.
There is no record in the core_url_rewrite for a specific product id: This means ...
I think the simplest solution here will be to create 301 redirects for your pages in different languages in the url rewrites management admin section.
Something like this:
For DE store view redirect from bags.html to taschen.html.
For EN store view redirect from taschen.html to bags.html.
Do the same for all the other combinations.
this way, when you ...
Since you don't have access to URLs from the URL rewrites you'll need to add a setStoreId() when loading the product. Note, it's faster to have a URL key and query it instead of loading up the entire product Model.
$productId = 1234;
$product = Mage::getModel('catalog/product')
->setStoreId(2) // set your store ID
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: String @deprecated(reason: "Use product's `canonical_url` or url rewrites instead")
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 need to inject a Magento\Catalog\Model\ProductRepository in your constructor of your Block:
public function __construct(
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 = $this->_categoryModelFactory->create();
$categoryCollection = $this->_categoryModelFactory->getCollection()->addAttributeToSelect('*');
Your front and admin <routers> (<frontName>installments</frontName>) should not be the same.
They are two ways to configure admin modules
1) Given it a different front name
The key in the url is generated based on the admin session.
And you cannot share the admin and frontend sessions, that's why when making the call from the frontend you get a different session key.
Anyway, it's not a good practice to make calls to backend actions from the frontend.
You should have 2 separate controllers, one for backend and one for ...
In general, there seem to be a few shortcomings in URL key management in EE 1.13 – read Fabrizio Branca's blog post.
Regarding your particular problem, it might help to change the url_key product attribute's scope:
Catalog → Attributes → Manage Attributes → Edit Attribute → Properties → Scope: Global
prevent having duplicate entries for the ...