D7 and Magento 1.7 Integration

salimmohd82's picture

For past one month i have been working on integration of D7 and Magento 1.7.

It includes
User registration is thru D7 and it adds the D7 user as a customer in Magneto from D7.
Sign-in is thru D7. At the time of sign-in it should sign into Magento as well.
Show the category and products from Magento in D7 nodes, inside content and as blocks

Out of this
Point 1 is achieved
Point 2 is also achieved using Rules module.But i want to redo it using coding inside D7 which i continually fails to my dismay
Point 3 is also achieved

The biggest problem i am facing is with the session in magento.

require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
    umask(0);
      Mage::App('default');
   
   $session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
   try {
        $session->login($row['mail'], $row['field_magentopass_value']);
   
        $session->setCustomerAsLoggedIn($session->getCustomer());

   //Load the customer modules
    //$customer = Mage::getModel(’customer/customer’)->setWebsiteId(Mage::app()->getStore()->getWebsiteId());

    //load customer by email
   //$customer->loadByEmail('alvaro@test.com');
  header('Location: http://'.$_SERVER[SERVER_NAME].'/mage1/customer/account/?SID='.$session->getSessionId());
   
      
     } catch (Exception $e) {
     print_r($e);
       exit;
    }

This is how you sign-in to magento from outside magento.
But when ever i try to run this code from my D7 it fails miserably.
I put this code under hook_user_login which executes after a user has logged in, and once the execution reaches the above code it logs out of Drupal as well. so in effect i am not able to login to Drupal and Magento.

I know the problem is with this line
$session = Mage::getSingleton("customer/session");

There is some conflict occurring with the session of both the systems.

Can anybody put some insight to this problem i am facing

The problem in short is related to the session.Where ever u use this
$session = Mage::getSingleton("customer/session");
it fails to retrieve the supposed result

Comments

aendrew's picture

I had issues with this for ages, see: http://stackoverflow.com/questions/13588483/magento-and-drupal-sessions-...

In the end, I ultimately had to save Drupal's session to a temporary variable, destroy that session, start the Magento session, do whatever I needed to do in Magento, destroy that session and then restart the Drupal session from the data saved in the temporary variable.

Best advice I could give you would be to look through the Joomla! code the person who answered contributed and change all the Joomla! function calls to their Drupal equivalent.

--
ændrew rininsland
news, photos, data, code.
aendrew.com :: @aendrew

Any chance of sharing the

vortex6's picture

Any chance of sharing the code you used? I've looked at that Joomla implementation and tried to implement it but I'm not getting anywhere. I've not managed to find anyone who has posted a Drupal/Magento SSO solution online after days of searching.

Give me some time

salimmohd82's picture

I have no problem in sharing the code. since it never went into production i did not take care of the code much and it is lost in between. Its is my HDD but need some time to find it.

EDIT:

I don't have the code for registering users in magento while they sign in with D7. This thread has the code for SSO

http://magento.stackexchange.com/questions/4254/how-to-create-session-fo...

Thanks for the link, I can

vortex6's picture

Thanks for the link, I can log in to magento by redirecting to an external file with that code after the user logs in to drupal. The problem is the code does not work from within drupal and I cannot find a good way to pass the login information safely from drupal to the external magento login file.

Cart, Promotions & Orders

Maxime Topolov's picture

Guys !

As aendrew said I'm a ghost maintainer, I wanna contribute :)))

The most tricky part of Magento integration is :

  • Management of promotions
  • Management of orders
  • Cart management
  • Management of payment and shipping methods

This is the most complex part.

Maxime TOPOLOV
Adyax / http://www.adyax.com
+33 1 76 77 34 60

Magento

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: