I would like to add store code to a custom URL in Magento 2.3.0
Actually, I want to pass store code to a custom URL in my custom module based on relevant store order.
Let's take an example:
public function getCustomUrl($orderData) {
if($this->emailHelper->dynamicUrl()){
return $this->urlInterface->getUrl($this->emailHelper->dynamicUrl()).'oId/'.$orderData->getIncrementId().'/fId/'.$this->getFollowUpId();
}else {
return $this->urlInterface->getUrl('route/controller/index/'.'oId/'.$orderData->getIncrementId().'/fId/'.$this->getFollowUpId());
}
}
In the above code
- $orderData = order object i can get storeId in this object
- $this->emailHelper->dynamicUrl() = get custom string from system config
- $orderData->getIncrementId() = pass orderId to url params
- $this->getFollowUpId() = module custom table ID pass to url params.
Above code, the result is http://example.com/default/seo/oId/000000112/fId/179
where /default/
is store code. I would like to pass /store2Code/ instead of
/default/where
/store2Code/` is order placed on store 2.
So in short pass store code based on the placed order store.
Note : I have enabled pass store code to URL from system config. so the reason for this store code is showing in URL.
Any help would be appreciated! Thanks.
$this->storeManager->getStore()->getStoreUrl().'/'.$this->storeManager->getStore()->getCode().'oId/'.$orderData->getIncrementId().'/fId/'.$this->getFollowUpId();
setCurrentStore($storeId);
will make it work?