hi I have this If else statement in magento. It always landed on the else statement even though the value of the variable is 10.

Please I need all the help I can.

{{if var customer_group_id }} == 10
         Print CGD
         Print ICT  <------always landed here
  • I donno which code language is this, but you can try {{if var customer_group_id == 10 }} instead {{if var customer_group_id }} == 10 Commented Sep 2, 2017 at 12:05
  • what you have try above Can you specify this in detail. Commented Sep 2, 2017 at 12:06
  • @AnilSuthar - Either does not work Commented Sep 2, 2017 at 12:10
  • which code language is this ? Where have u written this code ? Which file ? Commented Sep 2, 2017 at 12:11
  • I have this PDF Invoice Plus extension installed. Then in the edit function of the pdf template you can actually write a code. When I wrote {{customer_group_id}} it shows the ID, then when I try to write {{customer_group_code}} it does not show anything so I thought of instead pushing to get the group_code I try to create an statement in which I can actully set group code staticly. Commented Sep 2, 2017 at 12:14

1 Answer 1


Your logic looks like correct, but it doesn't work in transactionnal templates, you can use {{if}}, {{depend}} but just to check if the variable is true !. so to do you logic, comparison with other values etc... you have to do it in a block, you create this block then you insert it in your PDF template like this:

This code goes into the PDF template :

{{block type='core/template' area='frontend' template='pdf/statement.phtml'}}

You create a file in :


Now you do your stuff inside something like this:

if ( Mage::getSingleton('customer/session')->isLoggedIn() )
    $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
    if ($groupId == 10)
        echo $this->__('CGD');
    } else {
       echo $this->__('ICT');
  • Can you help me out sir. app/design/frontend/default/default/template/pdf/statement.phtml and inside It I pasted the code you gave. Then I edited my PDF Template and put that block thing but nothing happened. Commented Sep 3, 2017 at 5:23
  • I did this$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); if ($groupId == 10) { echo $this->__('CGD'); } else { echo $this->__('ICT'); But it is always landing on the ICT i cannot get the $groupId it always return a 0 value Commented Sep 3, 2017 at 8:10
  • For information, $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId()‌​;means that you get the customer group id from session, so if the customer is not logged you will not get it ! this is why you return nothing with if ( Mage::getSingleton('customer/session')->isLoggedIn() ) ... if you are sending your PDF without the user being logged in, you can get the groupID not from session. look this exemple : magento.stackexchange.com/questions/55736/…
    – PЯINCƎ
    Commented Sep 3, 2017 at 9:06
  • How do I pass the customer_group_id from my PDF Template to my phtml? Commented Sep 3, 2017 at 11:13
  • echo Mage::getModel('customer/group')->load({customer_group_id})->getCustomerGroupCode(); if ($groupId == 10) { echo $this->__('CGD'); } else { echo $this->__('ICT'); } How do I pass Customer_Group_Id Commented Sep 3, 2017 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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