1

I loaded following class into my controller:

use Magento\Store\Model\StoreManagerInterf‌​ace;

And injected it in my constructor:

StoreManagerInterf‌​ace $storeManagerInterface,

However it returns following error:

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Qxs\Verkoopje\Controller\Index\Index\Interceptor

How to load the storeManager in my controller?

  • Remove generated folder please. – Rohan Hapani Aug 6 '19 at 9:13
  • Thanks, I thought i never have to do that in developer mode... Now it returns : Exception #0 (RuntimeException): Class Magento\Store\Model\StoreManagerInterf‌​ace does not exist Class Qxs\Verkoopje\Controller\Index\Index\Interceptor generation error: The requested class did not generate properly, because the 'generated' directory permission is read-only. If --- after running the 'bin/magento setup:di:compile' CLI command when the 'generated' directory permission is set to write --- the requested class did not generate properly, then you – Coen Ponsen Aug 6 '19 at 9:21
  • Try to run php bin/magento setup:upgrade and php bin/magento setup:di:compile – Moin Malek Aug 6 '19 at 9:34
  • It keeps returning:Class Magento\Store\Model\StoreManagerInterf‌​ace does not exist Class Qxs\Verkoopje\Controller\Index\Index\Interceptor generation error: Th e requested class did not generate properly, because the 'generated' direct ory permission is read-only. If --- after running the 'bin/magento setup:di :compile' CLI command when the 'generated' directory permission is set to w rite --- the requested class did not generate properly, then you must add t he generated class object to the signature of the related construct method, only. – Coen Ponsen Aug 6 '19 at 10:11
  • Go to this path vendor/magento/module-store/Model/StoreManagerInterface.php and check please file available or not. – Rohan Hapani Aug 6 '19 at 10:18
1

Try to use this below way :

protected $_storeManager;    

public function __construct(
    .....
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    .....
)
{
    .....
    $this->_storeManager = $storeManager;
    .....
}

/**
 * Get store identifier
 *
 * @return  int
 */
public function getStoreId()
{
    return $this->_storeManager->getStore()->getId();
}

After inject class in construct remove generated folder and clean cache.

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.