I am working in Drupal and Magento Integration

Whenever i try to get session data using this code

require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";

  $session = Mage::getSingleton("customer/session");

  if ($session->isLoggedIn()) {
    $block['content'] .= $session->getCustomer()->getName();
  else {
    $block['content'] = t('User not logged in');

it fails to fetch the data.

But when i run this from independent php code it works fine.

But magento's catalog objects are running perfectly inside Drupal

What could be the problem. Any suggestions

Am using D7


require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
      Mage::getSingleton('core/session', array('name' => 'frontend'));

      // switch off error reporting
      error_reporting(E_ALL & ~ E_NOTICE);

      // Brands category => ID = 101
      $brand = Mage::getModel('catalog/category')->load('4');
      $brands = $brand->getChildrenCategories();

      foreach ($brands as $node) {
        $items[] = array(
            'data' => t($node['name'])

      $block['content'] .= theme('item_list', array(
          'items' => $items

This is the code i use to get the catalog products from magento and display in drupal I don't use any package for that.This is working perfectly.

  • where are you putting this code? in any hook of your custom module? are you sure your code is being called? – AjitS Jan 7 '13 at 12:50
  • am putting this inside hook_block_view – zamil Jan 7 '13 at 12:53
  • Hi zamil, cross-site posting of questions is not allowed. Would you rather this one was closed or the one on Stack Overflow? – Clive Jan 7 '13 at 13:08
  • ok i will close it here.how to do that – zamil Jan 7 '13 at 13:57
  • 1
    Are you using a module to get the Magento catalog objects into Drupal, or are you doing that yourself in a method similar to above? I would guess that it has to do with how Drupal handle's the session itself (session_set_save_handler(), etc) and the Magento module includes code to marry the two. Just a guess – give us more info and I'll try to help. – Charlie Schliesser Jan 7 '13 at 15:21

Your Answer

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

Browse other questions tagged or ask your own question.