0

I am in the admin and my structure of the scopes is the following:

-> Default
----> Website A
--------> Store DE
--------> Store FR
----> Website B
--------> Store DE
--------> Store FR

So, now I am simply reloading the page and in the _afterLoad() method, in my custom Model, which extends the core backend model where, which redirects to my _afterLoad method, I want to get the ID of the current website, that I am loading (when I change the Scope from the upper left drop-down menu).

Mage::app()->getWebsite()->getId() does not help, because it always returns 0. I can get the store code, when I am loading one of the store scopes, and from this get their IDs, but the websites don't have codes, so this cannot help me either. Mage::getModel('core/website')->getWebsite->getId() does not work either.

I know that the IDs of website A and website B are respectively 1 and 2, but I don't know how to acquire them, when I am in the admin.

Syspect
  • 1,283
  • 4
  • 22
  • 37
  • How does the url look like when you select a website from the dropdown? – Marius Jun 04 '14 at 14:19
  • @Marius - mydomain/admin/system_config/edit/section/xmlimport/website/base/key/b12439235f4523df996e9fd79a1b6cb398883ec8dd3d1b0501b730858a52d79f/ – Syspect Jun 04 '14 at 14:31
  • @Marius - I now saw that when I get to website B the url is .../website/nameOfWebsiteB/.... Do you suggest I get the code of the website from the URL with a GET ? – Syspect Jun 04 '14 at 14:33
  • 1
    yep...that's what I'm suggesting. See my answer. – Marius Jun 04 '14 at 14:35

1 Answers1

6

Try like this:

$websiteCode = Mage::app()->getRequest()->getParam('website');
if ($websiteCode) {
    $website = Mage::getModel('core/website')->load($websiteCode);
    $websiteId = $website->getId();
    //do your magic with $websiteId
}
else {
    //it means you didn't select a website - either you selected a store view or default.
}
Marius
  • 197,939
  • 53
  • 422
  • 830