Hot answers tagged

32

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 nameSpace ['Your_nameSpace'] use Magento\Catalog\Api\CategoryRepositoryInterface; class ['Your_Class_name'] protected $_storeManager; protected $...


24

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.


17

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: <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/...


15

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. Step 1 Make sure the ...


14

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: protected $urlBuider; public function __construct( .... \Magento\Framework\UrlInterface $urlBuilder, .... ) { .... $this->...


12

Always try to use repository. You need to inject following way: /** * @var \Magento\Catalog\Helper\Category */ protected $categoryHelper; /** * @var \Magento\Catalog\Model\CategoryRepository */ protected $categoryRepository; public function __construct( \Magento\Catalog\Helper\Category $categoryHelper, \Magento\Catalog\Model\CategoryRepository ...


8

You can try below code. $categoryId = 5; $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $object_manager = $_objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); echo "<pre>"; print_r($object_manager->getData()); Before you use a category id you have confirm category id exists in admin or it will ...


8

Although Swagger doesn't specify "url_key", you can add this attribute value by the following method: { "product": { ... "customAttributes": [ { "attributeCode": "url_key", "value": "<your_value>" } ] } } Note: Next time, you can use GET to know the product JSON structure first. Then any customized ...


7

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 ...


7

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\...


6

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/...


6

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 ...


5

To get the url key you need to call UrlKey method as beleow $_product->getUrlKey(); Hope this will help..


5

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', e.sku, d1.value AS 'price', t1.value AS 'short_description', t2.value AS 'description', v2.value AS 'image', ...


4

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 ...


4

Maybe it's better to use that property: /** * Array of actions which can be processed without secret key validation * * @var array */ protected $_publicActions = ['action_name'];


4

Following class is responsible for generating url key: vendor/magento/module-catalog-url-rewrite/Observer/ProductUrlKeyAutogeneratorObserver.php /** * @param \Magento\Framework\Event\Observer $observer * @return void */ public function execute(\Magento\Framework\Event\Observer $observer) { /** @var Product $product */ $product = $observer->...


4

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 - 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. Thank You


3

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 ...


3

I think you should add to your header url_key and url_path and set them for each product. For example, in url_key you have "awesome-product" and in url_path "awesome-product.html".


3

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 Step ...


3

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 ...


3

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 ...


3

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 ->load($...


3

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")


3

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( \Magento\Catalog\Model\...


3

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('*'); $...


2

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 <admin> <routers> <installments> <use>admin</use> <args> <module>...


2

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 ...


2

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 This should prevent having duplicate entries for the ...


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