How to get Region text from address id (Magento 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.
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
add a comment |
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.
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
add a comment |
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.
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
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.
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
magento2 customer-address address regions
edited 13 hours ago
summu
asked 15 hours ago
summusummu
1418
1418
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
|
show 2 more comments
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();
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
|
show 2 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
|
show 2 more comments
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.
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
|
show 2 more comments
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.
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.
edited 12 hours ago
answered 13 hours ago
Anshu MishraAnshu Mishra
5,44652660
5,44652660
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
|
show 2 more comments
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
I am not able to print the return value $address->getRegion(); Recoverable Error: Object of class MagentoCustomerModelDataRegion could not be converted to string
– summu
13 hours ago
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
13 hours ago
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
13 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
Try $address->getRegion()->getRegion(); I have updated the same in my answer as well.
– Anshu Mishra
12 hours ago
why two time getRegion()
– summu
12 hours ago
why two time getRegion()
– summu
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
Check the updated answer.
– Anshu Mishra
12 hours ago
|
show 2 more comments
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();
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
|
show 2 more comments
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();
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
|
show 2 more comments
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();
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();
edited 13 hours ago
answered 15 hours ago
Ronak RathodRonak Rathod
1778
1778
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
|
show 2 more comments
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
I am getting this error Call to undefined method MagentoCustomerModelDataAddress::getRegionName()
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
This is my block file MagentoCustomerBlockAddressBook
– summu
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
check my updated answer
– Ronak Rathod
13 hours ago
from where do I get $regionId
– summu
13 hours ago
from where do I get $regionId
– summu
13 hours ago
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
13 hours ago
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
13 hours ago
|
show 2 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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