Thứ Ba, 30 tháng 11, 2010

How to get Customer group id in magento


while i was working on one magento site one of my client wants to show a page only for wholesale customer.I knew How to assign customer group in magento But didn't know how to check it.I had to make this condition on Aw_blog module page, I opened that module and wrote the Following code and worked correctly.



First I check whether a Customer logged in or not ,then I fetch the value of customer group id to know in which cutomer group visited this page.In my website Wholesale customer Id was 2.


<?php

$login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); //Check if User is Logged In

if($login)

{

$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); //Get Customers Group ID

if($groupId == 2) //My wholesale customer id was 2 So I checked for 2. You can check according to your requirement

{

echo 'You are a wholesale Customer';

}

}

?>

Không có nhận xét nào:

Đăng nhận xét