How to restrict order in website wise in magento 2.2.0
-
24-12-2020 - |
Question
I have created two websites and install track order.
- website1
- website2
but I have placed an order in website1 and track order working now properly but one issue website2 order display track order.
now how to restrict the order in website2. please advance thanks for the help.
Solution
It is module bug. I have fixed module bug
Open file Mconnectsolutions\Trackorder\Controller\Index\Info.php
and replace
code in function private function getOrder()
at line number 59
from:
private function getOrder()
{
if ($data = $this->getRequest()->getParams()) {
$orderId = $data["order"];
$email = $data["email"];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderData = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
$cEmail = $orderData->getCustomerEmail();
if ($cEmail == $email) {
$url = $this->link->getWindowUrl($orderData);
$parts = parse_url($url);
parse_str($parts['query'], $query);
$hash = $query['hash'];
if ($hash && $hash != '') {
$shippingInfoModel = $this->shippingInfoFactory->create()->loadByHash($hash);
$this->trackingData = $shippingInfoModel;
}
return $orderData;
} else {
return null;
}
}
}
To:
private function getOrder()
{
if ($data = $this->getRequest()->getParams()) {
$orderId = $data["order"];
$email = $data["email"];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderData = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
$cEmail = $orderData->getCustomerEmail();
$storeManager = $objectManager->create('Magento\Store\Model\StoreManagerInterface');
$currentStoreId = $storeManager->getStore()->getId();
if ($cEmail == $email && $orderData->getStoreId() == $currentStoreId) {
$url = $this->link->getWindowUrl($orderData);
$parts = parse_url($url);
parse_str($parts['query'], $query);
$hash = $query['hash'];
if ($hash && $hash != '') {
$shippingInfoModel = $this->shippingInfoFactory->create()->loadByHash($hash);
$this->trackingData = $shippingInfoModel;
}
return $orderData;
} else {
return null;
}
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange