I'm trying to get the postcode that has been entered in the Estimate Shipping block on the basket page. I am trying to grab it from local storage. I have the following code on a template file that is called on the homepage:
<script>
require(['jquery','Magento_Checkout/js/model/quote'], function($,quote){
console.log(quote.shippingAddress().postcode)
})
</script>
This one returns an error in the console: quote.shippingAddress(...) is null
I have also tried to retrieve it via the cart session:
...
use Magento\Checkout\Model\Cart;
...
public function __construct(
Cart $cart,) {
$this->cart = $cart;
}
public function getCustomerDeliveryPostcode() {
$quote = $this->cart->getQuote();
$shippingAddress = $quote->getShippingAddress();
$postcode = $shippingAddress->getPostcode();
}
This one returns nothing. Can anyone see what is wrong? Magento 2.3.0