I would like to get the zip code after the user is done inputting. I am using a One Page Checkout for this. I am currently using a code that get the zip code on the user information being saved on the system. By the way I would like to add the code on one of the custom module's model. is this possible?
-
Yes it is possible. can you share you custom module code for the retrieve zip code?– AbdulCommented Mar 30, 2016 at 9:17
-
@Abdul i am currently using this code: $primaryAddress = Mage::getSingleton('customer/session')->getCustomer()->getPrimaryShippingAddress();$zipcode = $primaryAddress->getPostcode();– AlenCommented Mar 30, 2016 at 9:19
-
but are you need when customer typing in zip code field right?– AbdulCommented Mar 30, 2016 at 9:26
-
yes @Abdul I need that.– AlenCommented Mar 30, 2016 at 9:27
-
which One Page Checkout module are using right now?– AbdulCommented Mar 30, 2016 at 9:31
|
Show 2 more comments
1 Answer
Add this code on the OnePageCheckout Controller(IndexController.php):
$billing_data = $this->getRequest()->getPost('billing', array());
and get the Zip Code:
$billing_data['postcode']
as you wish to use it on other module, just set it on the core session:
Mage::getSingleton('core/session')->unsZipCode();
Mage::getSingleton('core/session')->setZipCode($ZipCode);
and Get value from session in your module like:
$zipCode = Mage::getSingleton('core/session')->getZipCode();
this will allow you to get the Zip Code whenever the user is done inputting.