我为该事件创建了一个观察者:sales_order_place_after
我能够从customerId
<?php
namespace MyCompany\MyModule\Observer\Sales\Order;
use Magento\Framework\Event\ObserverInterface;
class Salesrep implements ObserverInterface
{
public function __construct(
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepositoryInterface
){
$this->_customerRepositoryInterface = $customerRepositoryInterface;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
$customer = $this->_customerRepositoryInterface->getById($order->getCustomerId());
$salesrep = $customer->getCustomAttribute('salesrep')->getValue();
$order->setSalesrep($salesrep);
}
}
如果客户以客人身份订购,我如何通过电子邮件获取客户详细信息?
我也试过
$customer = $this->_customerRepositoryInterface->getByEmail($order->getCustomerEmail());
但这会返回错误。