当您在URL栏中单击管理商店中的特定商店时,应该有一个像store_id之类的参数.这是您的商店ID.或者,如果将鼠标悬停在商店上,则在"管理商店"屏幕中,链接可能会显示在浏览器的右(左)角.在url中有store_id param.这是我猜的最容易的.
或者在数据库中有table:core_store.
务实地,您可以获取网站ID,网站名称,商店ID,商店名称和商店代码,如下所示:
<?php
echo "Website ID: " . Mage::app()->getWebsite()->getId() . "<br/>";
echo "Website Name: " . Mage::app()->getWebsite()->getName() . "<br/>";
echo "Store ID: " . Mage::app()->getStore()->getId() . "<br/>";
echo "Store Name: ".Mage::app()->getStore()->getName(). "<br/>";
echo "Store code: ". Mage::app()->getStore()->getCode()."<br/>";
?>
Run Code Online (Sandbox Code Playgroud)
这是一个循环遍历所有网站的示例,并打印您在Magento中设置的所有商店ID和商店名称:
<?php
foreach (Mage::app()->getWebsites() as $website) {
foreach ($website->getGroups() as $group) {
$stores = $group->getStores();
foreach ($stores as $store) {
echo $store->getId() ." ".$store->getName()."<br/>";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
要获得store_id
从store_code
使用:
echo Mage::app()->getStore('store_code')->getId();
Run Code Online (Sandbox Code Playgroud)