Magento获取当前店铺信息(首页,类别,地址等)

1.获取当前店铺基本信息
//获取店铺对象
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!';
}
Below is an alternative way to check for homapage:
$routeName = Mage::app()->getRequest()->getRouteName();
$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
                )

        )
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值