I have to save the account edit
with customer default shipping address
details. After the successful order placement.
I have created the observer but not sure how to call editPost
of the customer from that execute method.
<?php
namespace YX\Customer\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class OrderSuccess implements ObserverInterface
{
protected $customerSession;
public function __construct(
\Magento\Customer\Model\Session $customerSession
)
{
$this->customerSession = $customerSession;
}
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
// TODO: Implement execute() method.
$customer = $this->customerSession->getCustomer();
$shippingAddress = $customer->getDefaultShippingAddress();
if ($shippingAddress) {
$firstname = $shippingAddress->getFirstname();
$secondname = $shippingAddress->getLastname();
$telephone = $shippingAddress->getTelephone();
}
}
}
Now I need to send these 3 parameter $firstname
, $secondname
, $telephone
to editPost
controller.
How can to achieve it.
My code looks something like that
public function execute(Observer $observer)
{
// TODO: Implement execute() method.
$customer = $this->customerSession->getCustomer();
$shippingAddress = $customer->getDefaultShippingAddress();
if ($shippingAddress) {
$firstname = $shippingAddress->getFirstname();
$secondname = $shippingAddress->getLastname();
$telephone = $shippingAddress->getTelephone();
$customer->setData('firstname', $firstname);
$customer->setData('lastname', $secondname);
$customer->setData('mobile', $telephone);
$customer->save();
}
account edit
action is not a good idea. Why you need this editpost – Amit Bera♦ Aug 7 '19 at 13:24I want to take the default shipping address first last name and save it to customer edit form which is formEdit , default shipping address will remain as it is
.Clarify it – Amit Bera♦ Aug 7 '19 at 14:01