Would it be possible to get postcode entered before and when reloaded the page?
I would like to do the similar thing to this below on Magento 2
$cart = Mage::getSingleton('checkout/cart'); $address = $cart->getQuote()->getShippingAddress()->getPostcode();
Hello @tvgarden
magento 2 store into local storage of browser that value
require(['jquery','Magento_Checkout/js/model/quote'], function($,quote){ console.log(quote.shippingAddress().postcode) })
so you need to above way to get that value.
Hope it will help you.
Thank you.
So to use the value in PHP code I would need to make an ajax call?
Hello @tvgarden
yes right!!! In session, you will get value but sometimes not right.
Do you mean we can get postcode from Customersession?
If I can I would like to get postcode before page load.
Also I would like to know which php function is called when a postcode is entered to estimate shipping?
You can get postcode using below way,
<?php public function __construct( \Magento\Checkout\Model\Cart $_cart ) { $this->_cart = $_cart; } public function execute(Observer $observer) { $quote = $this->_cart->getQuote(); $postcode = $quote->getShippingAddress()->getPostcode(); }