0

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";
  umask(0);
  Mage::app("default");

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

  if ($session->isLoggedIn()) {
    $block['content'] .= $session->getCustomer()->getName();
    #var_dump($session->getData());
  }
  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

EDIT

require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
      umask(0);
      Mage::app();
      Mage::app()->getTranslator()->init('frontend');
      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.

18
  • where are you putting this code? in any hook of your custom module? are you sure your code is being called?
    – AjitS
    Commented Jan 7, 2013 at 12:50
  • am putting this inside hook_block_view
    – zamil
    Commented Jan 7, 2013 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
    Commented Jan 7, 2013 at 13:08
  • ok i will close it here.how to do that
    – zamil
    Commented Jan 7, 2013 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. Commented Jan 7, 2013 at 15:21

0

Your Answer

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

Browse other questions tagged or ask your own question.