1.获取当前店铺基本信息
if($routeName == 'cms' && $identifier == 'home') {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
//获取店铺对象
Mage::app()->getStore();
//获取当前店铺ID
Mage::app()->getStore()->getStoreId();
//获取当前店铺Code,该Code在创建店铺时填写
Mage::app()->getStore()->getCode();
//获取当前店铺所属的Website ID
Mage::app()->getStore()->getWebsiteId();
//获取当前店铺的Name
Mage::app()->getStore()->getName();
//获取当前店铺的状态
Mage::app()->getStore()->getIsActive();
//获取当前店铺的URL
Mage::app()->getStore()->getHomeUrl();
Mage::app()->getStore();
//获取当前店铺ID
Mage::app()->getStore()->getStoreId();
//获取当前店铺Code,该Code在创建店铺时填写
Mage::app()->getStore()->getCode();
//获取当前店铺所属的Website ID
Mage::app()->getStore()->getWebsiteId();
//获取当前店铺的Name
Mage::app()->getStore()->getName();
//获取当前店铺的状态
Mage::app()->getStore()->getIsActive();
//获取当前店铺的URL
Mage::app()->getStore()->getHomeUrl();
2.Magento判断当前页是否为首页
Here is a quick code to check if the current page is homepage or not:
if($this->getIsHomePage()) {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
Below is an alternative way to check for homapage:
$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo 'You are in Homepage!';
} else {
echo 'You are NOT in Homepage!';
}
3.Magento获取当前页面URL地址
在Magento中,可以通过core/url helper类中的getCurrentUrl()方法获取当前页面URL地址:
$currentUrl = $this->
helper('core/url')->getCurrentUrl();
应用实例:
//在社会化分享中,当前页面的URL地址非常有用
<a addthis:url="<?php echo $this->helper('core/url')->getCurrentUrl(); ?>">Share on Facebook</a><span>
4.Magento获取当前分类 Get the current category in Magento
名称
Mage::registry('current_category')->getName();
或者
$this->getCurrentCategory();
应用实例:
$_category = Mage::registry('current_category');
print_r($_category);
打印结果:
[_data:protected] => Array
(
[store_id] => 1
[entity_id] => 10
[entity_type_id] => 3
[attribute_set_id] => 3
[parent_id] => 3
[created_at] => 2012-09-12 14:20:11
[updated_at] => 2012-09-12 14:20:11
[path] => 1/2/3/10
[position] => 1
[level] => 3
[children_count] => 0
[name] => Ballet Flats
[url_key] => ballet-flats
[meta_title] =>
[display_mode] => PRODUCTS
[custom_design] =>
[page_layout] =>
[url_path] => collection/ballet-flats.html
[is_active] => 1
[include_in_menu] => 1
[landing_page] =>
[is_anchor] => 0
[custom_use_parent_settings] => 0
[custom_apply_to_products] => 0
[description] =>
[meta_keywords] =>
[meta_description] =>
[custom_layout_update] =>
[available_sort_by] =>
[custom_design_from] =>
[custom_design_to] =>
[filter_price_range] =>
[path_ids] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 10
)
)
print_r($_category);
打印结果:
[_data:protected] => Array
(
[store_id] => 1
[entity_id] => 10
[entity_type_id] => 3
[attribute_set_id] => 3
[parent_id] => 3
[created_at] => 2012-09-12 14:20:11
[updated_at] => 2012-09-12 14:20:11
[path] => 1/2/3/10
[position] => 1
[level] => 3
[children_count] => 0
[name] => Ballet Flats
[url_key] => ballet-flats
[meta_title] =>
[display_mode] => PRODUCTS
[custom_design] =>
[page_layout] =>
[url_path] => collection/ballet-flats.html
[is_active] => 1
[include_in_menu] => 1
[landing_page] =>
[is_anchor] => 0
[custom_use_parent_settings] => 0
[custom_apply_to_products] => 0
[description] =>
[meta_keywords] =>
[meta_description] =>
[custom_layout_update] =>
[available_sort_by] =>
[custom_design_from] =>
[custom_design_to] =>
[filter_price_range] =>
[path_ids] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 10
)
)