网站magento的默认商店ID

问题描述 投票:15回答:3

我想获取当前活动网站的默认商店ID。我试过了

Mage::app()->getStoreId()

. It gets the current store but not the default store id of the current website. How to get it ? Any sugessions will be appreciated
php magento-1.6
3个回答
17
投票

假设您正在谈论每个商店组定义的默认商店ID,那么例如像这样:

$iDefaultStoreId = Mage::app()
    ->getWebsite()
    ->getDefaultGroup()
    ->getDefaultStoreId();

最初的问题是如何检索当前活动网站的默认商店ID,所以答案是正确的。但是,为了从管理面板中获取默认前端商店ID,您需要将参数true传递给方法getWebsite()

$iDefaultStoreId = Mage::app()
    ->getWebsite(true)
    ->getDefaultGroup()
    ->getDefaultStoreId();

6
投票

要回答@Tahir Yasin的评论,它在Admin上不起作用,这是因为Admin默认的website_id是0,所以store_id也是如此,所以在那里不太有用。管理员需要的是指定网站ID。

$iDefaultStoreId = Mage::app()
    ->getWebsite($websiteId)
    ->getDefaultGroup()
    ->getDefaultStoreId();

希望这有助于一些Google员工。


1
投票

你可以得到如下的默认商店ID:

Mage_Core_Model_App::ADMIN_STORE_ID
© www.soinside.com 2019 - 2024. All rights reserved.