6 Replies - 1188 Views - Last Post: 01 March 2016 - 10:30 AM

#1 bradkyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 16

How to get magento customer data outside magento installation

Posted 29 February 2016 - 12:47 AM

Hi guys,
I have recently completed a successful close integration of Magento and vBulletin whereby a user can login/register to them both simultaneously and then dynamic user information from vbulletin can be retrieved in magento however I am having trouble replicating the results the other way around.
I have used the following code to instantiate the magento header and footer templates on the vBulletin installation.
    $mageFilename = $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';
require_once $mageFilename;
#Mage::setIsDeveloperMode(true);
#ini_set('display_errors', 1);
umask(0);
Mage::app();


$block              = Mage::getSingleton('core/layout');

# HEAD BLOCK
$headBlock          = $block->createBlock('page/html_head');// this wont give you the css/js inclusion
// add js
$headBlock->addJs('prototype/prototype.js');
$headBlock->addJs('lib/ccard.js');
$headBlock->addJs('prototype/validation.js');
$headBlock->addJs('scriptaculous/builder.js');
$headBlock->addJs('scriptaculous/effects.js');
$headBlock->addJs('scriptaculous/dragdrop.js');
$headBlock->addJs('scriptaculous/controls.js');
$headBlock->addJs('scriptaculous/slider.js');
$headBlock->addJs('varien/js.js');
$headBlock->addJs('varien/form.js');
$headBlock->addJs('varien/menu.js');
$headBlock->addJs('mage/translate.js');
$headBlock->addJs('mage/cookies.js');
# add css
$headBlock->addCss('css/styles.css');
$headBlock->getCssJsHtml();
$headBlock->getIncludes();

$template_hook['footer_test_hook'] = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml();
$template_hook['header_test_hook'] = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();


however when I try to get information about the current user I get a headers already sent error as seen in the attachment.
This is the modified code that I used to try get the user data.
/** 
 * @author      MagePsycho <[email protected]> 
 * @website     http://www.magepsycho.com 
 * @category    using Header / Footer outside of Magento 
 */ 
$mageFilename = $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php'; 
require_once $mageFilename; 
#Mage::setIsDeveloperMode(true); 
#ini_set('display_errors', 1); 
umask(0); 
Mage::app('default'); 

Mage::getSingleton('core/session', array('name'=>'frontend')); 
$customer =Mage::getSingleton('customer/session');
Zend_Debug::dump($customer->isLoggedIn());
echo $customer->getId();

$block              = Mage::getSingleton('core/layout'); 

  
# HEAD BLOCK 
$headBlock          = $block->createBlock('page/html_head');// this wont give you the css/js inclusion 
// add js 
$headBlock->addJs('prototype/prototype.js'); 
$headBlock->addJs('lib/ccard.js'); 
$headBlock->addJs('prototype/validation.js'); 
$headBlock->addJs('scriptaculous/builder.js'); 
$headBlock->addJs('scriptaculous/effects.js'); 
$headBlock->addJs('scriptaculous/dragdrop.js'); 
$headBlock->addJs('scriptaculous/controls.js'); 
$headBlock->addJs('scriptaculous/slider.js'); 
$headBlock->addJs('varien/js.js'); 
$headBlock->addJs('varien/form.js'); 
$headBlock->addJs('varien/menu.js'); 
$headBlock->addJs('mage/translate.js'); 
$headBlock->addJs('mage/cookies.js'); 
# add css 
$headBlock->addCss('css/styles.css'); 
$headBlock->getCssJsHtml(); 
$headBlock->getIncludes(); 

$template_hook['footer_test_hook'] = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml(); 
$template_hook['header_test_hook'] = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();  

What code should I use in order to access the magento user data ($customer) within vbulletin without causing errors.
If you need any additional information i'll be glad to add.
Thanks.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: How to get magento customer data outside magento installation

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2016
  • View blog
  • Posts: 6,142
  • Joined: 15-January 14

Re: How to get magento customer data outside magento installation

Posted 29 February 2016 - 12:05 PM

Sending output with Zend_Debug::dump or echo will cause headers to get sent, which will cause an error if you do something else that tries to send a header.
Was This Post Helpful? 0
  • +
  • -

#3 bradkyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 16

Re: How to get magento customer data outside magento installation

Posted 29 February 2016 - 02:22 PM

How would I get magento data then?
Was This Post Helpful? 0
  • +
  • -

#4 bradkyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 16

Re: How to get magento customer data outside magento installation

Posted 29 February 2016 - 02:49 PM

when I use the following code
Plugin PHP Code
/**  
 * @author      MagePsycho <[email protected]>  
 * @website     http://www.magepsycho.com  
 * @category    using Header / Footer outside of Magento  
 */  
$mageFilename = $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';  
require_once $mageFilename;  
#Mage::setIsDeveloperMode(true);  
#ini_set('display_errors', 1);  
umask(0);  
Mage::app('default');  


$block              = Mage::getSingleton('core/layout');  
Mage::getSingleton("core/session", array("name" => "frontend")); 
$session = Mage::getSingleton("customer/session"); 
if($session->isLoggedIn()){ 
   echo "LOGGED IN"; 
}else{ 
   echo "NOT LOGGED IN"; 
 }  
# HEAD BLOCK  
$headBlock          = $block->createBlock('page/html_head');// this wont give you the css/js inclusion  
// add js  
$headBlock->addJs('prototype/prototype.js');  
$headBlock->addJs('lib/ccard.js');  
$headBlock->addJs('prototype/validation.js');  
$headBlock->addJs('scriptaculous/builder.js');  
$headBlock->addJs('scriptaculous/effects.js');  
$headBlock->addJs('scriptaculous/dragdrop.js');  
$headBlock->addJs('scriptaculous/controls.js');  
$headBlock->addJs('scriptaculous/slider.js');  
$headBlock->addJs('varien/js.js');  
$headBlock->addJs('varien/form.js');  
$headBlock->addJs('varien/menu.js');  
$headBlock->addJs('mage/translate.js');  
$headBlock->addJs('mage/cookies.js');  
# add css  
$headBlock->addCss('css/styles.css');  
$headBlock->getCssJsHtml();  
$headBlock->getIncludes();  

$template_hook['footer_test_hook'] = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml();  
$template_hook['header_test_hook'] = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();  


I get the following error in magento
Decoding failed: Syntax error
#0 /home/flintpty/public_html/app/code/local/Integration/vBulletin/Model/Curl.php(44): Zend_Json::decode('NOT LOGGED IN{"...')
#1 /home/name/public_html/app/code/local/Integration/vBulletin/Model/Vbulletin/Mysql4/Abstract.php(199): Integration_vBulletin_Model_Curl->readJson()
#2 /home/name/public_html/app/code/local/Integration/vBulletin/Helper/Data.php(507): Integration_vBulletin_Model_Vbulletin_Mysql4_Abstract->getVbOptions()
#3 /home/name/public_html/app/code/local/Integration/vBulletin/Helper/Data.php(515): Integration_vBulletin_Helper_Data->isVbulletinActive()
#4 /home/name/public_html/app/code/local/Integration/vBulletin/Model/Observer.php(85): Integration_vBulletin_Helper_Data->isModuleVBEnabled()
#5 /home/name/public_html/app/code/core/Mage/Core/Model/App.php(1357): Integration_vBulletin_Model_Observer->addVbuserInfo(Object(Varien_Event_Observer))
#6 /home/name/public_html/app/code/core/Mage/Core/Model/App.php(1336): Mage_Core_Model_App->_callObserverMethod(Object(Integration_vBulletin_Model_Observer), 'addVbuserInfo', Object(Varien_Event_Observer))
#7 /home/name/public_html/app/Mage.php(452): Mage_Core_Model_App->dispatchEvent('customer_load_a...', Array)
#8 /home/name/public_html/app/code/core/Mage/Core/Model/Abstract.php(267): Mage::dispatchEvent('customer_load_a...', Array)
#9 /home/name/public_html/app/code/core/Mage/Core/Model/Abstract.php(226): Mage_Core_Model_Abstract->_afterLoad()
#10 /home/name/public_html/app/code/core/Mage/Customer/Model/Session.php(116): Mage_Core_Model_Abstract->load('1')
#11 /home/name/public_html/app/code/core/Mage/Checkout/Model/Session.php(165): Mage_Customer_Model_Session->getCustomer()
#12 /home/name/public_html/app/code/core/Mage/Checkout/Model/Cart.php(119): Mage_Checkout_Model_Session->getQuote()
#13 /home/name/public_html/app/code/core/Mage/Checkout/Model/Cart.php(546): Mage_Checkout_Model_Cart->getQuote()
#14 /home/name/public_html/app/code/core/Mage/Checkout/Model/Cart.php(521): Mage_Checkout_Model_Cart->getItemsQty()
#15 /home/name/public_html/app/code/core/Mage/Checkout/Helper/Cart.php(160): Mage_Checkout_Model_Cart->getSummaryQty()
#16 /home/name/public_html/app/code/core/Mage/Checkout/Block/Links.php(46): Mage_Checkout_Helper_Cart->getSummaryCount()
#17 [internal function]: Mage_Checkout_Block_Links->addCartLink()
#18 /home/name/public_html/app/code/community/Codnitive/Extifcon/Model/Core/Layout.php(132): call_user_func_array(Array, Array)
#19 /home/name/public_html/app/code/community/Codnitive/Extifcon/Model/Core/Layout.php(70): Codnitive_Extifcon_Model_Core_Layout->_runAction(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#20 /home/name/public_html/app/code/core/Mage/Core/Model/Layout.php(214): Codnitive_Extifcon_Model_Core_Layout->_generateAction(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#21 /home/name/public_html/app/code/core/Mage/Core/Model/Layout.php(206): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#22 /home/name/public_html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#23 /home/name/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#24 /home/name/public_html/app/code/core/Mage/Cms/Helper/Page.php(113): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#25 /home/name/public_html/app/code/core/Mage/Cms/Helper/Page.php(52): Mage_Cms_Helper_Page->_renderPage(Object(Mage_Cms_IndexController), 'home')
#26 /home/name/public_html/app/code/core/Mage/Cms/controllers/IndexController.php(45): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), 'home')
#27 /home/name/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Cms_IndexController->indexAction()
#28 /home/name/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
#29 /home/name/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#30 /home/name/public_html/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#31 /home/name/public_html/app/Mage.php(688): Mage_Core_Model_App->run(Array)
#32 /home/name/public_html/index.php(87): Mage::run('', 'store')
#33 {main}



Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2016
  • View blog
  • Posts: 6,142
  • Joined: 15-January 14

Re: How to get magento customer data outside magento installation

Posted 29 February 2016 - 03:50 PM

I'm not very familiar with developing with Magento, but it looks like it's expecting a JSON structure and it has a problem with the text you output:

Quote

#0 /home/flintpty/public_html/app/code/local/Integration/vBulletin/Model/Curl.php(44): Zend_Json::decode('NOT LOGGED IN{"...')

Was This Post Helpful? 0
  • +
  • -

#6 bradkyle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-February 16

Re: How to get magento customer data outside magento installation

Posted 01 March 2016 - 02:03 AM

I am trying to get the magento user ID in vbulletin but the current code that I am using returns null after 6 days of trying I was hoping someone on this forum would be able to help me.
this is the code I am currently using.
$mageFilename = $_SERVER['DOCUMENT_ROOT'].'/app/Mage.php';    
require_once $mageFilename;    
#ini_set('display_errors', 1);    
umask(0);    
Mage::app('default');    
Mage::app()->loadArea('frontend');  
Mage::getSingleton('core/session', array('name'=>'frontend'));  




$block              = Mage::getSingleton('core/layout');    



# HEAD BLOCK    
$headBlock          = $block->createBlock('page/html_head');// this wont give you the css/js inclusion    
// add js    
$headBlock->addJs('prototype/prototype.js');    
$headBlock->addJs('lib/ccard.js');    
$headBlock->addJs('prototype/validation.js');    
$headBlock->addJs('scriptaculous/builder.js');    
$headBlock->addJs('scriptaculous/effects.js');    
$headBlock->addJs('scriptaculous/dragdrop.js');    
$headBlock->addJs('scriptaculous/controls.js');    
$headBlock->addJs('scriptaculous/slider.js');    
$headBlock->addJs('varien/js.js');    
$headBlock->addJs('varien/form.js');    
$headBlock->addJs('varien/menu.js');    
$headBlock->addJs('mage/translate.js');    
$headBlock->addJs('mage/cookies.js');    
# add css    
$headBlock->addCss('css/styles.css');    
$headBlock->getCssJsHtml();    
$headBlock->getIncludes();    

$template_hook['footer_test_hook'] = $block->createBlock('page/html_footer')->setTemplate('page/html/footer.phtml')->toHtml();    
$template_hook['header_test_hook'] = $block->createBlock('page/html_header')->setTemplate('page/html/header.phtml')->toHtml();  

$customer = Mage::getSingleton('customer/session')->getCustomer(); 
echo $customer->getFirstname();//this returns null



Please can someone help me with this.
Let me know if you need any additional info.
Thanks a trillion.
Was This Post Helpful? 0
  • +
  • -

#7 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2016
  • View blog
  • Posts: 6,142
  • Joined: 15-January 14

Re: How to get magento customer data outside magento installation

Posted 01 March 2016 - 10:30 AM

You already have a topic for this, let's keep it all together.

Why do you have all of the layout code? Are you trying to print the page from Magento? Have you tried to get the customer data before doing all of the layout stuff? Do the domains match, when you log in to Magento and then go to VBulletin are they hosted on the same domain?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1