1

For our project we have customized theme in Magento2. This has billing and shipping address pages. We have to save the billing address details in quote address table. But we didn't come across any specific function to save the billing address in Magento 2.

Anybody worked on this kind of billing save in Magento2?

0

In controller:

namespace Vendor\Module\Controller\MyControler;

class MyAction extends \Magento\Framework\App\Action\Action {

    /**
     * Quote
     */
    private $quote = null;

    /**
     * Constructor
     *
     * @param \Magento\Framework\App\Action\Context $context
     * @param \Magento\Checkout\Model\Session $session
     *
     * @return void
     */
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Checkout\Model\Session $session
    ) {
        $this->quote = $session->getQuote();

        parent::__construct($context);
    }

    /**
     * Execute action
     *
     * @return void
     */
    public function execute()
    {
        $this->quote->getBillingAddress()->setRegionId('18');  // Florida
        $this->quote->getBillingAddress()->setCity('Orlando'); 

        $this->quote->getBillingAddress()->setCountryId('US');
        $this->quote->getBillingAddress()->setPostcode('32825');
        $this->quote->getBillingAddress()->setCity('Orlando');
        $this->quote->getBillingAddress()->setStreet('1234 John Young pkwy' . PHP_EOL . 'apt 123');
        $this->quote->getBillingAddress()->setTelephone('5555');
        $this->quote->getBillingAddress()->setFirstName('John');
        $this->quote->getBillingAddress()->setLastName('Young');

        $this->quote->save();

        var_dump($this->quote->getBillingAddress()->getData());
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.