Magento 2, address->getRegion() return object instead of stringCustomer address data not showing all countriesMagento2 add custom address attributeBilling Address Custom FieldHow to programmatically add a “region” to the “addresInformation” on the page of the “checkout” when ordering?Magento 2 checkout page how to get country_id from selected shipping addresses?M2 : After magento upgrade not able to save “state” form address edit pageAddress update get street problem magento 2Magento 2 : DHL shipping is not giving rates for UAE webiteHow to get Region text from address id (Magento 2)

Is it possible to create light that imparts a greater proportion of its energy as momentum rather than heat?

Theorems that impeded progress

How to draw the figure with four pentagons?

Facing a paradox: Earnshaw's theorem in one dimension

Is it legal for company to use my work email to pretend I still work there?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

Will google still index a page if I use a $_SESSION variable?

Can one be a co-translator of a book, if he does not know the language that the book is translated into?

I'm flying to France today and my passport expires in less than 2 months

How do I write bicross product symbols in latex?

What exploit are these user agents trying to use?

90's TV series where a boy goes to another dimension through portal near power lines

How can I tell someone that I want to be his or her friend?

AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?

Why doesn't H₄O²⁺ exist?

SSH "lag" in LAN on some machines, mixed distros

What is going on with Captain Marvel's blood colour?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

What do you call someone who asks many questions?

CEO ridiculed me with gay jokes and grabbed me and wouldn't let go - now getting pushed out of company

Is it inappropriate for a student to attend their mentor's dissertation defense?

Twin primes whose sum is a cube

How could indestructible materials be used in power generation?

Intersection of two sorted vectors in C++



Magento 2, address->getRegion() return object instead of string


Customer address data not showing all countriesMagento2 add custom address attributeBilling Address Custom FieldHow to programmatically add a “region” to the “addresInformation” on the page of the “checkout” when ordering?Magento 2 checkout page how to get country_id from selected shipping addresses?M2 : After magento upgrade not able to save “state” form address edit pageAddress update get street problem magento 2Magento 2 : DHL shipping is not giving rates for UAE webiteHow 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'm trying to get Region from shipping address.
Here's the code :



$customer = $this->customerRepository->get('xxx@xxx.com');
$shippingAddressId = $customer->getDefaultShipping();
$shippingAddress = $this->addressRepository->getById($shippingAddressId);
$shippingAddress->getRegion();


But I'm not getting string of region name, instead I got Object from MagentoCustomerModelDataRegion



The country is not United States, so Region is simply string ( input text form ) instead of select, so no Region Id / Region Code when I created the customer from admin.



So, how correct way to get Region from shipping when there are no region id / region code?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.





















    2















    I'm trying to get Region from shipping address.
    Here's the code :



    $customer = $this->customerRepository->get('xxx@xxx.com');
    $shippingAddressId = $customer->getDefaultShipping();
    $shippingAddress = $this->addressRepository->getById($shippingAddressId);
    $shippingAddress->getRegion();


    But I'm not getting string of region name, instead I got Object from MagentoCustomerModelDataRegion



    The country is not United States, so Region is simply string ( input text form ) instead of select, so no Region Id / Region Code when I created the customer from admin.



    So, how correct way to get Region from shipping when there are no region id / region code?










    share|improve this question
















    bumped to the homepage by Community yesterday


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      2












      2








      2








      I'm trying to get Region from shipping address.
      Here's the code :



      $customer = $this->customerRepository->get('xxx@xxx.com');
      $shippingAddressId = $customer->getDefaultShipping();
      $shippingAddress = $this->addressRepository->getById($shippingAddressId);
      $shippingAddress->getRegion();


      But I'm not getting string of region name, instead I got Object from MagentoCustomerModelDataRegion



      The country is not United States, so Region is simply string ( input text form ) instead of select, so no Region Id / Region Code when I created the customer from admin.



      So, how correct way to get Region from shipping when there are no region id / region code?










      share|improve this question
















      I'm trying to get Region from shipping address.
      Here's the code :



      $customer = $this->customerRepository->get('xxx@xxx.com');
      $shippingAddressId = $customer->getDefaultShipping();
      $shippingAddress = $this->addressRepository->getById($shippingAddressId);
      $shippingAddress->getRegion();


      But I'm not getting string of region name, instead I got Object from MagentoCustomerModelDataRegion



      The country is not United States, so Region is simply string ( input text form ) instead of select, so no Region Id / Region Code when I created the customer from admin.



      So, how correct way to get Region from shipping when there are no region id / region code?







      magento2 customer-address






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 20 '18 at 11:01









      KamranKhan

      374216




      374216










      asked Mar 19 '18 at 22:08









      eluneelune

      1335




      1335





      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community yesterday


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






















          2 Answers
          2






          active

          oldest

          votes


















          0














          I tried to look inside MagentoCustomerModelDataRegion, and inside it there is a code :



          /**
          * Get region
          *
          * @return string
          */
          public function getRegion()

          return $this->_get(self::REGION);



          So I use $shippingAddress->getRegion()->getRegion(); to get correct region name.



          Still, the code look kinda weird, and I hope there are more answer to just use $shippingAddress->getRegion() and got the string of region name i need.






          share|improve this answer






























            0














            Try the below code to get Region from default shipping addresss



            protected $customerSession;

            public function __construct(
            ...
            MagentoCustomerModelSession $customerSession
            )

            ...
            $this->customerSession = $customerSession;
            parent::__construct($context);


            public function getRegion()
            $customer = $this->customerSession->getCustomer();
            if ($customer)
            $shippingAddress = $customer->getDefaultShippingAddress();
            if ($shippingAddress)
            return $shippingAddress->getRegion();


            return null;






            share|improve this answer























              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%2f218950%2fmagento-2-address-getregion-return-object-instead-of-string%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









              0














              I tried to look inside MagentoCustomerModelDataRegion, and inside it there is a code :



              /**
              * Get region
              *
              * @return string
              */
              public function getRegion()

              return $this->_get(self::REGION);



              So I use $shippingAddress->getRegion()->getRegion(); to get correct region name.



              Still, the code look kinda weird, and I hope there are more answer to just use $shippingAddress->getRegion() and got the string of region name i need.






              share|improve this answer



























                0














                I tried to look inside MagentoCustomerModelDataRegion, and inside it there is a code :



                /**
                * Get region
                *
                * @return string
                */
                public function getRegion()

                return $this->_get(self::REGION);



                So I use $shippingAddress->getRegion()->getRegion(); to get correct region name.



                Still, the code look kinda weird, and I hope there are more answer to just use $shippingAddress->getRegion() and got the string of region name i need.






                share|improve this answer

























                  0












                  0








                  0







                  I tried to look inside MagentoCustomerModelDataRegion, and inside it there is a code :



                  /**
                  * Get region
                  *
                  * @return string
                  */
                  public function getRegion()

                  return $this->_get(self::REGION);



                  So I use $shippingAddress->getRegion()->getRegion(); to get correct region name.



                  Still, the code look kinda weird, and I hope there are more answer to just use $shippingAddress->getRegion() and got the string of region name i need.






                  share|improve this answer













                  I tried to look inside MagentoCustomerModelDataRegion, and inside it there is a code :



                  /**
                  * Get region
                  *
                  * @return string
                  */
                  public function getRegion()

                  return $this->_get(self::REGION);



                  So I use $shippingAddress->getRegion()->getRegion(); to get correct region name.



                  Still, the code look kinda weird, and I hope there are more answer to just use $shippingAddress->getRegion() and got the string of region name i need.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 19 '18 at 22:17









                  eluneelune

                  1335




                  1335























                      0














                      Try the below code to get Region from default shipping addresss



                      protected $customerSession;

                      public function __construct(
                      ...
                      MagentoCustomerModelSession $customerSession
                      )

                      ...
                      $this->customerSession = $customerSession;
                      parent::__construct($context);


                      public function getRegion()
                      $customer = $this->customerSession->getCustomer();
                      if ($customer)
                      $shippingAddress = $customer->getDefaultShippingAddress();
                      if ($shippingAddress)
                      return $shippingAddress->getRegion();


                      return null;






                      share|improve this answer



























                        0














                        Try the below code to get Region from default shipping addresss



                        protected $customerSession;

                        public function __construct(
                        ...
                        MagentoCustomerModelSession $customerSession
                        )

                        ...
                        $this->customerSession = $customerSession;
                        parent::__construct($context);


                        public function getRegion()
                        $customer = $this->customerSession->getCustomer();
                        if ($customer)
                        $shippingAddress = $customer->getDefaultShippingAddress();
                        if ($shippingAddress)
                        return $shippingAddress->getRegion();


                        return null;






                        share|improve this answer

























                          0












                          0








                          0







                          Try the below code to get Region from default shipping addresss



                          protected $customerSession;

                          public function __construct(
                          ...
                          MagentoCustomerModelSession $customerSession
                          )

                          ...
                          $this->customerSession = $customerSession;
                          parent::__construct($context);


                          public function getRegion()
                          $customer = $this->customerSession->getCustomer();
                          if ($customer)
                          $shippingAddress = $customer->getDefaultShippingAddress();
                          if ($shippingAddress)
                          return $shippingAddress->getRegion();


                          return null;






                          share|improve this answer













                          Try the below code to get Region from default shipping addresss



                          protected $customerSession;

                          public function __construct(
                          ...
                          MagentoCustomerModelSession $customerSession
                          )

                          ...
                          $this->customerSession = $customerSession;
                          parent::__construct($context);


                          public function getRegion()
                          $customer = $this->customerSession->getCustomer();
                          if ($customer)
                          $shippingAddress = $customer->getDefaultShippingAddress();
                          if ($shippingAddress)
                          return $shippingAddress->getRegion();


                          return null;







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 20 '18 at 6:51









                          Shireen NShireen N

                          670411




                          670411



























                              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%2f218950%2fmagento-2-address-getregion-return-object-instead-of-string%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

                              Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                              Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                              Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form