I’m trying to access logged in customer data in an “after” plugin.
The plugin is working, but I need some logic based on a custom customer attribute.
I try to do this but I get an error
Fatal error: Uncaught Error: Call to a member function get() on null in /Users/name/file/project/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 170
I’ve tried using create instead of get for the object manager, but I get the same result.
I have a helper function that I use to get this data in some phtml files, but it doesn’t seem to work in this class.
Do I have to get this data from somewhere else?
Thanks
namespace <company>EmailCopyPlugin;
use MagentoFrameworkAppObjectManager;
use MagentoSalesModelOrderEmailContainerOrderIdentity;
use PsrLogLoggerInterface;
class SendOrderCopy
{
private $logger;
private $objectManager;
public function __construct(
LoggerInterface $logger,
ObjectManager $objectManager
)
{
$this->logger = $logger;
$this->objectManager = $objectManager;
}
public function afterGetEmailCopyTo(OrderIdentity $identity, $emailList)
{
$customer = $this->objectManager::getInstance()->get('MagentoCustomerModelSession')->getCustomer();
$customer = $customer->getData();
var_dump($customer);
$emailList[] = "<email>";
$emailList[] = "<email";
return $emailList;
}
}