gpt4 book ai didi

php - 仅当用户登录并加入某些特定组时才在类别或产品页面上显示自定义 block

转载 作者:可可西里 更新时间:2023-11-01 13:26:06 26 4
gpt4 key购买 nike

我想在产品页面和产品列表页面上显示 magento 静态 block 的内容。

静态 block 仅对加入特定组的 LOGGED IN USERS 可见(例如,reseller 内的logged in 用户, generalclients,不在 testingguests 内。

附言我还需要将它添加到侧边栏中,我在其中进行了分层导航。

最佳答案

您好,您可以轻松做到这一点。

第 1 步:pp/design/frondtend/YourPackage/YourPackage/template/cms/

showstatic.phtml >

第 2 步:在此 phtml 上,您可以检查客户登录及其组 ID,然后使用 show Static block 。

代码是:

<?php 
$loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
// add Handler when customer is loggedin
if($loggedIn):
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
//Get customer Group name

$group = Mage::getModel('customer/group')->load($groupId);

$Groupcode=$group->getData('customer_group_code');
/* static customer group code array for which static block will call */
$Enableforgroup=array(13, 2, 8, 7); // call static array
if (in_array($Groupcode, $Enableforgroup)){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
}

endif;

?>

现在你在category,product by处调用这个phtml

类别:

类别页面位于 app/design/frondtend/YourPackage/YourPackage/template/catalog/category/view.phtml

echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/showstatic.phtml')->toHtml();

产品:

产品页面位于 app/design/frondtend/YourPackage/YourPackage/template/catalog/product/view.phtml

echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/showstatic.phtml')->toHtml();

作为 magento 进程:

app/design/frondtend/YourPackage/YourPackage/layout/ 创建 local.xml 文件

代码是:

<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<!-- add this handler for show all category pages -->
<catalog_category_view>
<reference name="content">
<!-- reference block for page where you want show
the static block
-->
<block type="core/template" name="showstatic" template="cms/showstatic.phtml">
<block type="cms/block" name="showstatichow" >
<!--
The content of this block is taken from the database by its block_id.
You can manage it in admin CMS -> Static Blocks
-->
<action method="setBlockId"><block_id>footer_links_company</block_id></action>
</block>

</block>
</reference>
</catalog_category_view>


<!-- add this handler for show all product pages -->
<catalog_product_view>
<reference name="content">
<!-- reference block for page where you want show
the static block
-->
<block type="core/template" name="showstatic" template="cms/showstatic.phtml">
<block type="cms/block" name="showstatichow" >
<!--
The content of this block is taken from the database by its block_id.
You can manage it in admin CMS -> Static Blocks
-->
<action method="setBlockId"><block_id>footer_links_company</block_id></action>
</block>

</block>
</reference>
</catalog_product_view>


</layout>

pp/design/frondtend/YourPackage/YourPackage/template/cms/

创建模板文件 showstatic.phtml

代码:

<?php 
$loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
// show cms blocks when customer is loggedin
if($loggedIn):
// get Customer group id from session
echo $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
/* $Enableforgroup is array for reseller, general and clients
* group ids
*/
$Enableforgroup=array(13, 2, 1, 7); // call static array
if (in_array($groupId, $Enableforgroup)){
echo $this->getChildHtml("showstatichow");
}


endif;

?>

关于php - 仅当用户登录并加入某些特定组时才在类别或产品页面上显示自定义 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30598802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com