How to get Region text from address id (Magento 2)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I am not able to get region text from address id,



 <?php $_pAddsses = $block->getDefaultBilling() ?>
<?php echo $block->getAddressById($_pAddsses)->getRegionId() ?>
// output 5



<?php echo $block->getAddressById($_pAddsses)->getRegion() ?>
//output ""(empty)


And for my question, I don't have any region code, as many countries don't have region dropdown, like - India country dropdown doesn't have region dropdown, so in the database, the region id is 0 and region is whatever we filled in the text box for the region.



enter image description here



I checked the database it does contain region text.



I need region text to populate the region text box for which region dropdown is not available for countries.



I am not able to figure out what am I doing wrong.










share|improve this question































    2















    I am not able to get region text from address id,



     <?php $_pAddsses = $block->getDefaultBilling() ?>
    <?php echo $block->getAddressById($_pAddsses)->getRegionId() ?>
    // output 5



    <?php echo $block->getAddressById($_pAddsses)->getRegion() ?>
    //output ""(empty)


    And for my question, I don't have any region code, as many countries don't have region dropdown, like - India country dropdown doesn't have region dropdown, so in the database, the region id is 0 and region is whatever we filled in the text box for the region.



    enter image description here



    I checked the database it does contain region text.



    I need region text to populate the region text box for which region dropdown is not available for countries.



    I am not able to figure out what am I doing wrong.










    share|improve this question



























      2












      2








      2








      I am not able to get region text from address id,



       <?php $_pAddsses = $block->getDefaultBilling() ?>
      <?php echo $block->getAddressById($_pAddsses)->getRegionId() ?>
      // output 5



      <?php echo $block->getAddressById($_pAddsses)->getRegion() ?>
      //output ""(empty)


      And for my question, I don't have any region code, as many countries don't have region dropdown, like - India country dropdown doesn't have region dropdown, so in the database, the region id is 0 and region is whatever we filled in the text box for the region.



      enter image description here



      I checked the database it does contain region text.



      I need region text to populate the region text box for which region dropdown is not available for countries.



      I am not able to figure out what am I doing wrong.










      share|improve this question
















      I am not able to get region text from address id,



       <?php $_pAddsses = $block->getDefaultBilling() ?>
      <?php echo $block->getAddressById($_pAddsses)->getRegionId() ?>
      // output 5



      <?php echo $block->getAddressById($_pAddsses)->getRegion() ?>
      //output ""(empty)


      And for my question, I don't have any region code, as many countries don't have region dropdown, like - India country dropdown doesn't have region dropdown, so in the database, the region id is 0 and region is whatever we filled in the text box for the region.



      enter image description here



      I checked the database it does contain region text.



      I need region text to populate the region text box for which region dropdown is not available for countries.



      I am not able to figure out what am I doing wrong.







      magento2 customer-address address regions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 4 at 9:32







      summu

















      asked Mar 4 at 7:39









      summusummu

      3259




      3259






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You can try following code to get the region from the address id.



          $address = $this->addressRepository->getById($addressId);
          $address->getRegion()->getRegion();


          where $this->addressRepository is the object of MagentoCustomerApiAddressRepositoryInterface
          $address->getRegion() will give return you the object of MagentoCustomerApiDataRegionInterface

          and then calling getRegion() on it will give you string.






          share|improve this answer


























          • I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:06













          • i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:08













          • Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

            – Anshu Mishra
            Mar 4 at 10:17











          • why two time getRegion()

            – summu
            Mar 4 at 10:17











          • Check the updated answer.

            – Anshu Mishra
            Mar 4 at 10:18



















          2














          In Block File :-



          protected $AddressRepoInterface;

          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $AddressRepoInterface

          ){
          $this->AddressRepoInterface = $AddressRepoInterface;
          }
          public function getRegionName() {
          return $this->AddressRepoInterface->getById($addressId)->getRegion();
          }


          In phtml File :-



          $block->getRegionName();





          share|improve this answer


























          • I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

            – summu
            Mar 4 at 9:20













          • This is my block file MagentoCustomerBlockAddressBook

            – summu
            Mar 4 at 9:21











          • check my updated answer

            – Ronak Rathod
            Mar 4 at 9:26











          • from where do I get $regionId

            – summu
            Mar 4 at 9:27











          • And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

            – summu
            Mar 4 at 9:30












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264250%2fhow-to-get-region-text-from-address-id-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          You can try following code to get the region from the address id.



          $address = $this->addressRepository->getById($addressId);
          $address->getRegion()->getRegion();


          where $this->addressRepository is the object of MagentoCustomerApiAddressRepositoryInterface
          $address->getRegion() will give return you the object of MagentoCustomerApiDataRegionInterface

          and then calling getRegion() on it will give you string.






          share|improve this answer


























          • I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:06













          • i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:08













          • Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

            – Anshu Mishra
            Mar 4 at 10:17











          • why two time getRegion()

            – summu
            Mar 4 at 10:17











          • Check the updated answer.

            – Anshu Mishra
            Mar 4 at 10:18
















          2














          You can try following code to get the region from the address id.



          $address = $this->addressRepository->getById($addressId);
          $address->getRegion()->getRegion();


          where $this->addressRepository is the object of MagentoCustomerApiAddressRepositoryInterface
          $address->getRegion() will give return you the object of MagentoCustomerApiDataRegionInterface

          and then calling getRegion() on it will give you string.






          share|improve this answer


























          • I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:06













          • i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:08













          • Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

            – Anshu Mishra
            Mar 4 at 10:17











          • why two time getRegion()

            – summu
            Mar 4 at 10:17











          • Check the updated answer.

            – Anshu Mishra
            Mar 4 at 10:18














          2












          2








          2







          You can try following code to get the region from the address id.



          $address = $this->addressRepository->getById($addressId);
          $address->getRegion()->getRegion();


          where $this->addressRepository is the object of MagentoCustomerApiAddressRepositoryInterface
          $address->getRegion() will give return you the object of MagentoCustomerApiDataRegionInterface

          and then calling getRegion() on it will give you string.






          share|improve this answer















          You can try following code to get the region from the address id.



          $address = $this->addressRepository->getById($addressId);
          $address->getRegion()->getRegion();


          where $this->addressRepository is the object of MagentoCustomerApiAddressRepositoryInterface
          $address->getRegion() will give return you the object of MagentoCustomerApiDataRegionInterface

          and then calling getRegion() on it will give you string.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 4 at 10:18

























          answered Mar 4 at 9:39









          Anshu MishraAnshu Mishra

          5,64652662




          5,64652662













          • I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:06













          • i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:08













          • Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

            – Anshu Mishra
            Mar 4 at 10:17











          • why two time getRegion()

            – summu
            Mar 4 at 10:17











          • Check the updated answer.

            – Anshu Mishra
            Mar 4 at 10:18



















          • I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:06













          • i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

            – summu
            Mar 4 at 10:08













          • Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

            – Anshu Mishra
            Mar 4 at 10:17











          • why two time getRegion()

            – summu
            Mar 4 at 10:17











          • Check the updated answer.

            – Anshu Mishra
            Mar 4 at 10:18

















          I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

          – summu
          Mar 4 at 10:06







          I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

          – summu
          Mar 4 at 10:06















          i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

          – summu
          Mar 4 at 10:08







          i did this <?php $regionName = $orderHelper->getRegionName($_pAddsses) ?> <?php echo "region " .$regionName ?> Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string

          – summu
          Mar 4 at 10:08















          Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

          – Anshu Mishra
          Mar 4 at 10:17





          Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.

          – Anshu Mishra
          Mar 4 at 10:17













          why two time getRegion()

          – summu
          Mar 4 at 10:17





          why two time getRegion()

          – summu
          Mar 4 at 10:17













          Check the updated answer.

          – Anshu Mishra
          Mar 4 at 10:18





          Check the updated answer.

          – Anshu Mishra
          Mar 4 at 10:18













          2














          In Block File :-



          protected $AddressRepoInterface;

          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $AddressRepoInterface

          ){
          $this->AddressRepoInterface = $AddressRepoInterface;
          }
          public function getRegionName() {
          return $this->AddressRepoInterface->getById($addressId)->getRegion();
          }


          In phtml File :-



          $block->getRegionName();





          share|improve this answer


























          • I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

            – summu
            Mar 4 at 9:20













          • This is my block file MagentoCustomerBlockAddressBook

            – summu
            Mar 4 at 9:21











          • check my updated answer

            – Ronak Rathod
            Mar 4 at 9:26











          • from where do I get $regionId

            – summu
            Mar 4 at 9:27











          • And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

            – summu
            Mar 4 at 9:30
















          2














          In Block File :-



          protected $AddressRepoInterface;

          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $AddressRepoInterface

          ){
          $this->AddressRepoInterface = $AddressRepoInterface;
          }
          public function getRegionName() {
          return $this->AddressRepoInterface->getById($addressId)->getRegion();
          }


          In phtml File :-



          $block->getRegionName();





          share|improve this answer


























          • I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

            – summu
            Mar 4 at 9:20













          • This is my block file MagentoCustomerBlockAddressBook

            – summu
            Mar 4 at 9:21











          • check my updated answer

            – Ronak Rathod
            Mar 4 at 9:26











          • from where do I get $regionId

            – summu
            Mar 4 at 9:27











          • And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

            – summu
            Mar 4 at 9:30














          2












          2








          2







          In Block File :-



          protected $AddressRepoInterface;

          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $AddressRepoInterface

          ){
          $this->AddressRepoInterface = $AddressRepoInterface;
          }
          public function getRegionName() {
          return $this->AddressRepoInterface->getById($addressId)->getRegion();
          }


          In phtml File :-



          $block->getRegionName();





          share|improve this answer















          In Block File :-



          protected $AddressRepoInterface;

          public function __construct(
          MagentoCustomerApiAddressRepositoryInterface $AddressRepoInterface

          ){
          $this->AddressRepoInterface = $AddressRepoInterface;
          }
          public function getRegionName() {
          return $this->AddressRepoInterface->getById($addressId)->getRegion();
          }


          In phtml File :-



          $block->getRegionName();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 13 at 11:52

























          answered Mar 4 at 7:52









          Ronak RathodRonak Rathod

          1,125213




          1,125213













          • I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

            – summu
            Mar 4 at 9:20













          • This is my block file MagentoCustomerBlockAddressBook

            – summu
            Mar 4 at 9:21











          • check my updated answer

            – Ronak Rathod
            Mar 4 at 9:26











          • from where do I get $regionId

            – summu
            Mar 4 at 9:27











          • And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

            – summu
            Mar 4 at 9:30



















          • I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

            – summu
            Mar 4 at 9:20













          • This is my block file MagentoCustomerBlockAddressBook

            – summu
            Mar 4 at 9:21











          • check my updated answer

            – Ronak Rathod
            Mar 4 at 9:26











          • from where do I get $regionId

            – summu
            Mar 4 at 9:27











          • And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

            – summu
            Mar 4 at 9:30

















          I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

          – summu
          Mar 4 at 9:20







          I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()

          – summu
          Mar 4 at 9:20















          This is my block file MagentoCustomerBlockAddressBook

          – summu
          Mar 4 at 9:21





          This is my block file MagentoCustomerBlockAddressBook

          – summu
          Mar 4 at 9:21













          check my updated answer

          – Ronak Rathod
          Mar 4 at 9:26





          check my updated answer

          – Ronak Rathod
          Mar 4 at 9:26













          from where do I get $regionId

          – summu
          Mar 4 at 9:27





          from where do I get $regionId

          – summu
          Mar 4 at 9:27













          And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

          – summu
          Mar 4 at 9:30





          And for my question, i dont have any region code, as many countries doesnt have region dropdown, like - India country dropdown doesnt have region dropdown, so in database region code is 0 and region is whatever we filled in text box for region

          – summu
          Mar 4 at 9:30


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f264250%2fhow-to-get-region-text-from-address-id-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Aardman Animations

          Are they similar matrix

          “minimization” problem in Euclidean space related to orthonormal basis