Hey I hope this question isn't to broad but how is the order attached to a customer that is created after guest checkout?
Background to my question:
I want to attach a custom field to my customer. This custom field is acquired in checkout and stored in the order. I tried to receive the order in a observer watching the customer_register_success
event:
namespace Vendor\CheckoutCustomerInfo\Observer;
use Magento\Customer\Model\Customer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
class AddInfoFromOrderToCustomerObserver implements ObserverInterface
{
private $collectionFactoryInterface;
public function __construct(CollectionFactoryInterface $collectionFactoryInterface)
{
$this->collectionFactoryInterface = $collectionFactoryInterface;
}
/**
* @param Observer $observer
*
* @return void
*/
public function execute(Observer $observer)
{
/**
* @var Customer $customer
*/
$customer = $observer->getCustomer();
$orders = $this->collectionFactoryInterface->create($customer->getId())->addFieldToSelect(
'*'
)->setOrder(
'created_at',
'desc'
);
}
}
But in $orders
I do not have the order.
Am I doing something wrong with querying the orders of the customer or is it attached somehow different? Is this event to early to get the order?
Thanks in advance!