【问题标题】:What would the magento 2 equivalent of Mage::getModel('customer/customer')->loadByEmail(); be?Magento 2 相当于 Mage::getModel('customer/customer')->loadByEmail();是?
【发布时间】:2017-04-06 08:58:37
【问题描述】:

magento 2 中这段代码的等价物是什么?

Mage::getModel('customer/customer')->loadByEmail();

?

【问题讨论】:

    标签: model magento2 customer


    【解决方案1】:

    请使用此代码:

    <?php 
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customer =  $objectManager->get('Magento\Customer\Model\Customer');
    $customer->setWebsiteId('1');
    $customer->loadByEmail('test@gmail.com'); 
    ?>
    

    【讨论】:

      【解决方案2】:

      你也可以试试这个:

      protected $customerCollection;
      
      public function __construct(
          ...
          \Magento\Customer\Model\Customer $customerCollection,
          ...     
      )
      {
          ...
          $this->customerCollection = $customerCollection;
          ...
      }
      

      在您的函数中使用以下代码:-

      $customerObj = $this->customerCollection;
      $customerObj->setWebsiteId($websiteId);
      $customerObj->loadByEmail('test@gmail.com');
      

      【讨论】:

        猜你喜欢
        • 2022-01-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-04
        • 2012-11-03
        • 1970-01-01
        • 2013-09-17
        • 1970-01-01
        相关资源
        最近更新 更多