Magento 2 Error Invalid Method Interceptor::loadByCustomer
{“0″:”Mu00e9todo invu00e1lido VendorModuleModelSubscriberInterceptor::loadByCustomer”,”1″:”#1 VendorModuleObserverLogin->execute() called at [vendor/magento/framework/Event/Invoker/InvokerDefault.php:88]n#2 MagentoFrameworkEventInvokerInvokerDefault->_callObserverMethod() called at [vendor/magento/framework/Event/Invoker/InvokerDefault.php:74]n#3 MagentoFrameworkEventInvokerInvokerDefault->dispatch()
Code:
<?php
namespace VendorModuleObserver;
use MagentoCustomerModelSession;
use MagentoFrameworkEventObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoNewsletterModelSubscriber;
use MagentoStoreModelStoreManagerInterface;
class Login implements ObserverInterface
{
/**
* @var Session
*/
private $session;
/**
* @var Subscriber
*/
private $subscriber;
/**
* @var StoreManagerInterface
*/
private $storeManager;
public function __construct(
Session $session,
Subscriber $subscriber,
StoreManagerInterface $storeManager
)
{
$this->session = $session;
$this->subscriber = $subscriber;
$this->storeManager = $storeManager;
}
public function execute(Observer $observer)
{
if($this->session->isLoggedIn()) {
$checkSubscriber = $this->subscriber->loadByCustomer($this->session->getCustomerId(), $this->storeManager->getStore()->getWebsiteId());
if($checkSubscriber->getSubscriberStatus() === 1) {
...
}
}
}
}