Get Store/Website by Language/Country
Im searching since a week how i can get a store_id / website_id for a given language.
Like:
$countryId = 'DE'; // or country = Germany
foreach (Mage::app()->getStores() as $store) {
if($store->getCountryId() === $countryId){
return $store;
}
}
How could i solve this?
EDIT: 03022016
Im now using the general/country/allow config (system/general/allowed countries)
This will get the first store that is using the given country.
Ofc the country could be used on multiply stores, but any other solution i found got the same problem.
The point why im using this solution is that the IDs are real country_id s (not editable codes-strings).
public function getStoreIdByCustomerCountryId($countryIdCustomer)
{
$countryIdReturn = null;
$countryIdCustomer = trim((string)$countryIdCustomer);
if (!strlen($countryIdCustomer)) {
return false;
}
foreach (Mage::app()->getStores() as $store) {
if (!$store->getIsActive()) {
continue;
}
foreach (
explode(',', $store->getConfig('general/country/allow'))
as $countryId
) {
if (trim((string)$countryId) === $countryIdCustomer) {
$countryIdReturn = $store->getId();
break 2;
}
}
}
return $countryIdReturn;
}
magento-1.9 language stores country-regions
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.
add a comment |
Im searching since a week how i can get a store_id / website_id for a given language.
Like:
$countryId = 'DE'; // or country = Germany
foreach (Mage::app()->getStores() as $store) {
if($store->getCountryId() === $countryId){
return $store;
}
}
How could i solve this?
EDIT: 03022016
Im now using the general/country/allow config (system/general/allowed countries)
This will get the first store that is using the given country.
Ofc the country could be used on multiply stores, but any other solution i found got the same problem.
The point why im using this solution is that the IDs are real country_id s (not editable codes-strings).
public function getStoreIdByCustomerCountryId($countryIdCustomer)
{
$countryIdReturn = null;
$countryIdCustomer = trim((string)$countryIdCustomer);
if (!strlen($countryIdCustomer)) {
return false;
}
foreach (Mage::app()->getStores() as $store) {
if (!$store->getIsActive()) {
continue;
}
foreach (
explode(',', $store->getConfig('general/country/allow'))
as $countryId
) {
if (trim((string)$countryId) === $countryIdCustomer) {
$countryIdReturn = $store->getId();
break 2;
}
}
}
return $countryIdReturn;
}
magento-1.9 language stores country-regions
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.
add a comment |
Im searching since a week how i can get a store_id / website_id for a given language.
Like:
$countryId = 'DE'; // or country = Germany
foreach (Mage::app()->getStores() as $store) {
if($store->getCountryId() === $countryId){
return $store;
}
}
How could i solve this?
EDIT: 03022016
Im now using the general/country/allow config (system/general/allowed countries)
This will get the first store that is using the given country.
Ofc the country could be used on multiply stores, but any other solution i found got the same problem.
The point why im using this solution is that the IDs are real country_id s (not editable codes-strings).
public function getStoreIdByCustomerCountryId($countryIdCustomer)
{
$countryIdReturn = null;
$countryIdCustomer = trim((string)$countryIdCustomer);
if (!strlen($countryIdCustomer)) {
return false;
}
foreach (Mage::app()->getStores() as $store) {
if (!$store->getIsActive()) {
continue;
}
foreach (
explode(',', $store->getConfig('general/country/allow'))
as $countryId
) {
if (trim((string)$countryId) === $countryIdCustomer) {
$countryIdReturn = $store->getId();
break 2;
}
}
}
return $countryIdReturn;
}
magento-1.9 language stores country-regions
Im searching since a week how i can get a store_id / website_id for a given language.
Like:
$countryId = 'DE'; // or country = Germany
foreach (Mage::app()->getStores() as $store) {
if($store->getCountryId() === $countryId){
return $store;
}
}
How could i solve this?
EDIT: 03022016
Im now using the general/country/allow config (system/general/allowed countries)
This will get the first store that is using the given country.
Ofc the country could be used on multiply stores, but any other solution i found got the same problem.
The point why im using this solution is that the IDs are real country_id s (not editable codes-strings).
public function getStoreIdByCustomerCountryId($countryIdCustomer)
{
$countryIdReturn = null;
$countryIdCustomer = trim((string)$countryIdCustomer);
if (!strlen($countryIdCustomer)) {
return false;
}
foreach (Mage::app()->getStores() as $store) {
if (!$store->getIsActive()) {
continue;
}
foreach (
explode(',', $store->getConfig('general/country/allow'))
as $countryId
) {
if (trim((string)$countryId) === $countryIdCustomer) {
$countryIdReturn = $store->getId();
break 2;
}
}
}
return $countryIdReturn;
}
magento-1.9 language stores country-regions
magento-1.9 language stores country-regions
edited Feb 3 '16 at 11:06
asked Jan 29 '16 at 13:26
cottton
1637
1637
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.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Try like that (in some phtml file, but you can rearange it to fit only in your php function):
<ul>
<?php foreach(Mage::app()->getWebsites() as $website): ?>
<?php foreach ($website->getGroups() as $group): ?>
<?php $stores = $group->getStores();
foreach ($stores as $store): ?>
<li class="<?php echo Mage::app()->getStore($store->getStoreId())->getCode();?>"><a href="<?php echo Mage::app()->getStore($store->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>"></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
Now, with $store->getStoreId()
you are able to get the store id.
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
add a comment |
If you have access to the Admin Panel, go to System -> Manage Stores -> choose a store view and add a code of the country in there. For example:
In php you can get this code with Mage::app()->getStore($store->getStoreId())->getCode();
and you can compare this:
if (Mage::app()->getStore($store->getStoreId())->getCode() == $countryId) {
return Mage::app()->getStore($store->getStoreId());
}
Is this what you wanted?
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
add a comment |
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%2f99582%2fget-store-website-by-language-country%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
Try like that (in some phtml file, but you can rearange it to fit only in your php function):
<ul>
<?php foreach(Mage::app()->getWebsites() as $website): ?>
<?php foreach ($website->getGroups() as $group): ?>
<?php $stores = $group->getStores();
foreach ($stores as $store): ?>
<li class="<?php echo Mage::app()->getStore($store->getStoreId())->getCode();?>"><a href="<?php echo Mage::app()->getStore($store->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>"></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
Now, with $store->getStoreId()
you are able to get the store id.
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
add a comment |
Try like that (in some phtml file, but you can rearange it to fit only in your php function):
<ul>
<?php foreach(Mage::app()->getWebsites() as $website): ?>
<?php foreach ($website->getGroups() as $group): ?>
<?php $stores = $group->getStores();
foreach ($stores as $store): ?>
<li class="<?php echo Mage::app()->getStore($store->getStoreId())->getCode();?>"><a href="<?php echo Mage::app()->getStore($store->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>"></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
Now, with $store->getStoreId()
you are able to get the store id.
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
add a comment |
Try like that (in some phtml file, but you can rearange it to fit only in your php function):
<ul>
<?php foreach(Mage::app()->getWebsites() as $website): ?>
<?php foreach ($website->getGroups() as $group): ?>
<?php $stores = $group->getStores();
foreach ($stores as $store): ?>
<li class="<?php echo Mage::app()->getStore($store->getStoreId())->getCode();?>"><a href="<?php echo Mage::app()->getStore($store->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>"></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
Now, with $store->getStoreId()
you are able to get the store id.
Try like that (in some phtml file, but you can rearange it to fit only in your php function):
<ul>
<?php foreach(Mage::app()->getWebsites() as $website): ?>
<?php foreach ($website->getGroups() as $group): ?>
<?php $stores = $group->getStores();
foreach ($stores as $store): ?>
<li class="<?php echo Mage::app()->getStore($store->getStoreId())->getCode();?>"><a href="<?php echo Mage::app()->getStore($store->getStoreId())->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>"></a></li>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul>
Now, with $store->getStoreId()
you are able to get the store id.
answered Jan 29 '16 at 14:48
anitr
6418
6418
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
add a comment |
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
Not sure if you got my question right. How should i now get a storeId by a countryId ?
– cottton
Jan 29 '16 at 18:16
add a comment |
If you have access to the Admin Panel, go to System -> Manage Stores -> choose a store view and add a code of the country in there. For example:
In php you can get this code with Mage::app()->getStore($store->getStoreId())->getCode();
and you can compare this:
if (Mage::app()->getStore($store->getStoreId())->getCode() == $countryId) {
return Mage::app()->getStore($store->getStoreId());
}
Is this what you wanted?
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
add a comment |
If you have access to the Admin Panel, go to System -> Manage Stores -> choose a store view and add a code of the country in there. For example:
In php you can get this code with Mage::app()->getStore($store->getStoreId())->getCode();
and you can compare this:
if (Mage::app()->getStore($store->getStoreId())->getCode() == $countryId) {
return Mage::app()->getStore($store->getStoreId());
}
Is this what you wanted?
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
add a comment |
If you have access to the Admin Panel, go to System -> Manage Stores -> choose a store view and add a code of the country in there. For example:
In php you can get this code with Mage::app()->getStore($store->getStoreId())->getCode();
and you can compare this:
if (Mage::app()->getStore($store->getStoreId())->getCode() == $countryId) {
return Mage::app()->getStore($store->getStoreId());
}
Is this what you wanted?
If you have access to the Admin Panel, go to System -> Manage Stores -> choose a store view and add a code of the country in there. For example:
In php you can get this code with Mage::app()->getStore($store->getStoreId())->getCode();
and you can compare this:
if (Mage::app()->getStore($store->getStoreId())->getCode() == $countryId) {
return Mage::app()->getStore($store->getStoreId());
}
Is this what you wanted?
edited Oct 23 '17 at 5:20
Aasim Goriya
2,5421733
2,5421733
answered Feb 1 '16 at 7:42
anitr
6418
6418
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
add a comment |
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
(Sorry for the delay) Thank you, this would work but depends on access/able to change the store code (which i can/should not). I edited my question and added the solution i found.
– cottton
Feb 3 '16 at 10:57
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f99582%2fget-store-website-by-language-country%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