I want to display an image in corner of our product images if a customer is logged into a specific group and that group has a special price.
I have got the code for checking whether a customer is logged in and also check what group they are in. and I have got this to add a if it is true. This is the code I have for this.
<?php
$_isLoggedIn = $this->helper('customer')->isLoggedIn();
if($_isLoggedIn == true){
$_myGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if($_myGroupId == 5){
?><div class="special"> </div><?php
}
}
?>
However, I need another IF statement to check if that product also has a special price for that customer group. I have done this before in the price.phtml using this code
<?php $login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); //Check if User is Logged In
if($login && Mage::getSingleton('customer/session')->getCustomerGroupId()==5)
{
$groupPrices = $_product->getData('group_price');
$Groupprice= $groupPrices;
if (is_null($groupPrices)) {
$attribute = $_product->getResource()->getAttribute('group_price');
if ($attribute){
$attribute->getBackend()->afterLoad($_product);
$groupPrices = $_product->getData('group_price');}}
/* check group price exit nor not */
if (!is_null($groupPrices) || is_array($groupPrices)) {
foreach ($groupPrices as $groupPrice) {
if($groupPrice['cust_group'] == Mage::getSingleton('customer/session')->getCustomerGroupId()){
$Groupprice = $groupPrice['website_price'];
$Groupprice=$groupPrice['cust_group'];
break;}} }
/* $Groupprice is null mean group price is not exit*/
if(!is_null($Groupprice)){
//group price exits ?>
<span class="price-label"><?php echo "Your Special Price " ?></span><?php}?>
But this code doesn't work in the view.phtml. I have had a little play around and I can't seem to get it to work, Could someone help me adding another IF statement to my original IF statement.
If I am not being clear please let me know. and Thank you in advance.
Best Answer
Hi You need change product object to $_product as product page then you did not load afterLoad function