0

I grab the customer through their email in a backend controller:

$baseCustomer = $customerModel->loadByEmail($creationEmail);

Then I grab $customer['default_billing'] to get the ID of the billing address information.

    $cloneBilling = $baseCustomer['default_billing'];
    $baseAddress = Mage::getModel('customer/address')->load($cloneBilling);

From there I'm able to grab the customers firstname, lastname, street, city, postcode, country_id, and telephone.

$cloneCountryId = $baseAddress['country_id'];
        $clonePostcode = $baseAddress['postcode'];
        $cloneCity = $baseAddress['city'];
        $cloneTelephone = $baseAddress['telephone'];
        $cloneStreet = $baseAddress['street'];

TLDR Question: I have the customer and they have an address how do I grab the region and region_id also known as the state?

  • have you tried $baseAddress['region']? – subroutines Apr 27 '17 at 1:45
1

Take a look at Mage_Customer_Model_Address_Abstract::getRegion(), you'll notice that underlying it is actually a model. In your case, try

$baseAddress->getRegion(); // returns string, eg. Texas
$baseAddress->getRegionId(); // returns numeric, eg. 57
$baseAddress->getRegionModel(); // returns Mage_Directory_Model_Country 
$baseAddress->getRegionCode(); // returns string, eg. TX

[edit] My test code:

$m = Mage::getModel('customer/address')->load(14);
$result[] = $m->getData();
$result[] = $m->getRegionId();
$result[] = $m->getRegion();
$result[] = $m['region'];

Here's the $result:

array(4) { [0] => array(23) { ["entity_id"] => string(2) "14" ["entity_type_id"] => string(1) "2" ["attribute_set_id"] => string(1) "0" ["increment_id"] => NULL ["parent_id"] => string(2) "23" ["created_at"] => string(25) "2013-01-25T11:35:28+08:00" ["updated_at"] => string(19) "2013-02-18 03:11:19" ["is_active"] => string(1) "1" ["prefix"] => NULL ["firstname"] => string(9) "Collage02" ["middlename"] => NULL ["lastname"] => string(4) "test" ["suffix"] => NULL ["company"] => NULL ["city"] => string(9) "Putrajaya" ["country_id"] => string(2) "MY" ["region"] => string(9) "WP Labuan" ["postcode"] => string(5) "72510" ["telephone"] => string(10) "0375216584" ["fax"] => NULL ["vat_id"] => NULL ["region_id"] => string(3) "500" ["street"] => string(9) "Presint 6" } [1] => int(500) [2] => string(12) "WP Putrajaya" [3] => string(12) "WP Putrajaya" }

One reason the region info is empty could be that it is empty. You can check it by looking at the result of print_r($baseAddress->getData());

  • getRegion() returns nothing. getRegionId() returns 0? – CodingMageSheen Apr 27 '17 at 22:54

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.