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;
}
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 Mar 4 at 9:32
summu
asked Mar 4 at 7:39
summusummu
3259
3259
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
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
|
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
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
|
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
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
|
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
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
|
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 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
|
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
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
|
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
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
|
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
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
|
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 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
|
show 2 more comments
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
|
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