在Magento后台,我们可以找到客户群。
首先你要注册你的模型。我假设你已经知道如何完成,或者你已经有现成的可用。 现在,为你的模型创建一个配置文件。我这里使用的示例模型是存在于'Alwayly'命名空间下的'Customergroup‘,下面是代码: app/code/community/Alwayly/Customergroup/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Alwayly_Customergroup>
<version>1.0.0</version>
</Alwayly_Customergroup>
</modules>
<global>
<events>
<controller_action_layout_generate_blocks_after>
<observers>
<alwayly_customergroup>
<type>singleton</type>
<class>alwayly_Customergroup_Model_Observer</class>
<method>placeCustomJs</method>
</alwayly_customergroup>
</observers>
</controller_action_layout_generate_blocks_after>
</events>
</global>
</config>
然后,我们创建观察者。 app/code/community/Alwayly/Customergroup/Model/Observer.php
<?php
class Alwayly_Customergroup_Model_Observer
{
public function placeCustomJs()
{
$roleId = Mage::getSingleton('customer/session')->getCustomerGroupId();
$role = Mage::getSingleton('customer/group')->load($roleId)->getData('customer_group_code');
$role = strtolower($role);
$headBlock = Mage::app()->getLayout()->getBlock('head');
if($headBlock && $role=='wholesale')
{
$headBlock->addJs('test/myScript.js');
}
return $this;
}
}
我展示只是一种用例。你可以在任何合适的地方使用它。比如给特定的用户组显示一条信息,一个不一样的订阅框,等等…… 一定要注意:如果用户没有登录,$role将会等于 ‘not logged in‘。 (责任编辑:最模板) |


ecshop仿米奇网化妆品2014网
人气:549
ecshop眼镜商城|ecshop红色模
人气:1241
特价红色Ecmall综合多用户
人气:1430
Prestashop跨境电子商务Sty
人气:286
ecshop秒杀插件
人气:4582
织梦dedecms复古红黑建筑风
人气:1115