2

I have cloud enterprise project with multi website. We are facing issue of null object is returned from getDefaultStore method.

I have created one admin role and given full access but assigned only selected website scope which we need. enter image description here

And we using magento default login as customer functionality with that role and facing this error.and unable to login successfully. enter image description here

I checked the default code and try to debug the issue but not get any luck.When we pass here getDefaultGroupId as static for that particular website then it's working.

/**
     * @inheritdoc
     */
    public function getDefaultStoreView()
    {
        $defaultWebsite = $this->websiteRepository->getDefault();
        $defaultStore = $this->getGroup($defaultWebsite->getDefaultGroupId())->getDefaultStore();
        return $defaultStore ?: null;
    }

1 Answer 1

0

Hello Vikas kalal, for that try the below code hope it's working for you.

use Magento\Store\Model\StoreManagerInterface;
protected $storeManager;
public function __construct(StoreManagerInterface $storeManager)
{
  $this->storeManager = $storeManager;
}
        
public function getDefaultStoreView()
{
   $websiteId =1;
   // get default store id of website 1
   $storeId = $this->storeManager->getWebsite($websiteId)->getDefaultStore()->getId();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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