Storewise product url save programatically in Magento 2
-
10-03-2021 - |
문제
I have 2 different website in my Magento. I want to store different url key
for each website. How to store it programatically ?
해결책
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');
}
제휴하지 않습니다 magento.stackexchange