0

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? – Abdul Mar 30 '16 at 9:17
  • @Abdul i am currently using this code: $primaryAddress = Mage::getSingleton('customer/session')->getCustomer()->getPrimaryShippingAddress();$zipcode = $primaryAddress->getPostcode(); – Alen Mar 30 '16 at 9:19
  • but are you need when customer typing in zip code field right? – Abdul Mar 30 '16 at 9:26
  • yes @Abdul I need that. – Alen Mar 30 '16 at 9:27
  • which One Page Checkout module are using right now? – Abdul Mar 30 '16 at 9:31
0

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.

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.