I have 2 different website in my Magento. I want to store different url key for each website. How to store it programatically ?

1 Answer 1


I able to achieve this solution by this :

public function __construct (
\Magento\Catalog\Model\ResourceModel\Product $productResourceModel
) {
  $this->productResourceModel = $productResourceModel;

public function changeUrlByStore($sku, $storeId = 1){
  $product = $this->productFactory->create();
  $productId = $this->productResourceModel->getIdBySku($sku);
  $this->productResourceModel->load($product, $productId);

  $this->productResourceModel->saveAttribute($product, 'url_key');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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