Welcome Guest, Not a member yet? Register   Sign In
Pulling Magento content into CodeIgniter
#1

[eluser]Unknown[/eluser]
I am trying to display information from a Magento installation (like the cart contents) on a CodeIgniter website. I have code working, but when I try and use it in a CodeIgniter controller it doesn't seem to pull the information from the session. Not sure if there is a problem with the Magento sessions vs the CodeIgniter sessions?

My original php/Magento code, this works outside of CodeIgniter.

Code:
<?php

$mageFilename = 'app/Mage.php';
require_once $mageFilename;

umask(0);
Mage::app();


Mage::getSingleton('core/session', array('name'=>'frontend'));



$session = Mage::getSingleton('checkout/session');

$output = "";

foreach ($session->getQuote()->getAllItems() as $item) {
    
    $output .= $item->getSku() . "<br>";
    $output .= $item->getName() . "<br>";
    $output .= $item->getDescription() . "<br>";
    $output .= $item->getQty() . "<br>";
    $output .= $item->getBaseCalculationPrice() . "<br>";
    $output .= "<br>";
}

print $output;
?&gt;


My CodeIgniter controller, this runs with no errors but doesn't output any data.

Code:
&lt;?php

class Magento extends Controller {

    function Magento()
    {
        parent::Controller();

    }

    function index()
    {
        $mageFilename = 'magento/app/Mage.php';
        require_once $mageFilename;

        umask(0);
        Mage::app();
        Mage::getSingleton('core/session', array('name'=>'frontend'));
        
        $session = Mage::getSingleton('checkout/session');

        $output = "";

        foreach ($session->getQuote()->getAllItems() as $item) {
          
            $output .= $item->getSku() . "<br>";
            $output .= $item->getName() . "<br>";
            $output .= $item->getDescription() . "<br>";
            $output .= $item->getQty() . "<br>";
            $output .= $item->getBaseCalculationPrice() . "<br>";
            $output .= "<br>";
        }

        print $output;
        echo '<a href="/timecarpet/magento/checkout/cart/add?product=1qty=1">Add card to basket</a>';
        }
    }

/* End of file magento */
/* Location: ./mcp/application/controllers/magento.php */

Am I missing something stupid or is it likely to be a session issue?

Any help would be much appreciated!

Thanks,

James
#2

[eluser]danmontgomery[/eluser]
CodeIgniter's session library replaces native sessions with cookies. If you want to use native sessions, try $_SESSION or the the native session library
#3

[eluser]Unknown[/eluser]
I've put the Native Sessions library in the application/libraries folder and renamed the Session.php in the system/libraries folder. As both of the files are called Session.php I can leave autoload.php as is presumably?

It doesn't seem to have made any difference to my demo, my code in CodeIgniter still isn't pulling any details from the Magento session.

Any ideas?
#4

[eluser]landitus[/eluser]
Have you read this post? http://stackoverflow.com/questions/10988...de-magento
It may help, let me know!!




Theme © iAndrew 2016 - Forum software by © MyBB