0

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

0

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

  $product->setStoreId($storeId);
  $product->setUrlKey(UNIQUE_URL_KEY);
  $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.