Magento 2.4.6-p4

I am chaning the url key by using


Now, when I view this product in admin, it still shows the old url key. Loading the product and printing the url key shows the new key:


So, how can I also make it change in admin?



3 Answers 3


You can defne the storeID as well. Please do as given below :

namespace vendor\module\Block\Quote;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ProductFactory;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Element\Template;
class Items extends Template {

public function __construct(
    Context $context,
    ProductRepositoryInterface $productrepo,
    ProductFactory $product,
    array $data = []
) {
    parent::__construct($context, $data);
    $this->productrepo = $productrepo;
    $this->product = $product;

public function ProductUrl($sku)
    $product = $this->productrepo->get($sku);
    $product->setStoreId(0);//setting the value on all store view
    $product->setUrlKey('add your url key'); // Replace with your desired URL key

Just a wild guess, but maybe you're missing setUrlPath()?


First please run bin/magento s:up;bin/magento index:reindex and then check

if doesn't work still run this command and let me know the result, might be attribute scope issue.

select a.*
from `catalog_product_entity_varchar` a
join `eav_attribute` b
    on b.attribute_id = a.attribute_id
where b.attribute_code = 'url_key'
and a.entity_id = 12673;

change entity_id with your product id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.