2

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.

  • Adam,is it products view page? – Amit Bera Oct 8 '14 at 9:32
  • yea i have put the code in my view.phtml – Adam Allen Oct 8 '14 at 9:42
4

Hi You need change product object to $_product as product page then you did not load afterLoad function

    <?php 
    $login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); 
//Check if User is Logged In
            if($login)
            {
            $groupPrices = $_product->getData('group_price');
            $Groupprice= $groupPrices;
                /* check group price exit nor not */
                 if (!is_null($groupPrices) || is_array($groupPrices)) {
                    foreach ($groupPrices as $groupPrice) {
                    /* match with current customer group */
                    if($groupPrice['cust_group'] == Mage::getSingleton('customer/session')->getCustomerGroupId()){
                    echo $Groupprice = $groupPrice['website_price'];
                    echo "<br/>";   
                    echo $Groupprice=$groupPrice['cust_group'];
                    break;
                    }
                    }

                 }
                 /* $Groupprice  is null mean group price is not  exit*/
                 if(!is_null($Groupprice)){
                     //group price eixts
                     ?>
                     <span class="price-label"><?php echo "Special Group Price " ?></span>
                    <?php 
                 }else{
                     //Group price is exits.
                     ?>
                     <span class="price-label"><?php echo "Now" ?></span> 
                 <?php }
            ?>
  • After a bit of tinkering it works perfect. Once again you save the day. Thank you :) – Adam Allen Oct 8 '14 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.