Which class I should inject to get the current customer? What are their differences?
\Magento\Customer\Helper\Session\CurrentCustomer\Magento\Customer\Model\Session
Which class I should inject to get the current customer? What are their differences?
\Magento\Customer\Helper\Session\CurrentCustomer\Magento\Customer\Model\SessionWell, you can use either of them.
Basically \Magento\Customer\Helper\Session\CurrentCustomer uses \Magento\Customer\Model\Session.
The benefit of using the helper class is that it provides extra helper methods to get the current customer data such as:
getCustomer : to load the current customergetCustomerId : to get the current customer idThe benefit of using the model class is that you modify the customer data with:
setCustomerDatasetCustomersetCustomerIdsetCustomerGroupIdsetCustomerAsLoggedInAlso you can do extra stuff that the helper won't let you do:
isLoggedIn()login()logout()So I guess it depends on your needs:
\Magento\Customer\Helper\Session\CurrentCustomer\Magento\Customer\Model\Session