Question

I'm creating an extension which limits the Paymentmethodes in the checkout. For this I have craeted the PlugIn MethodListPlugIn with the Methode afterGetAvailableMethods.

When I try to catch the dob or email in an guest checkout, (with getQuote() (examp. getQuote()->getDob()) of \Magento\Checkout\Model\Session) I just get null.

So my question is: How can I fetch the dob and email of an guest in the checkout?

Was it helpful?

Solution

I solved it this way (I think, not sure if it was this project as I create this question).

public function __construct(
        \Magento\Customer\Model\AddressFactory $customerAddressFactory,
    ) {
        parent::__construct($context);
        $this->_customerAddressFactory = $customerAddressFactory;
}
public function prepareAddressDataById($addressId)
{
    $address = $this->_customerAddressFactory->create()->load($addressId);
    $addressData = $address->toArray();
    $addressData['dob'] = $address->getCustomer()->getDob();

    return $this->prepareAddressData($addressData);
}

( I quickly copied this out of a pretty big file and removed anything not important. So I don't know if this is plug and play ;) )

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top