0

I have added an external file as same as index.php & having below code.

 require_once 'app/Mage.php';
Mage::app();
$isLoggedIn = 0;
$isCartItems = 0;

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $isLoggedIn = 1;
}

$isCartItems = Mage::helper('checkout/cart')->getSummaryCount();

echo $isCartItems;
echo $isLoggedIn;

But, unfortunately i can't get correct values of above variables. Its always returning 0

Can anyone help please.

1

try this code

<?php 
require_once 'app/Mage.php';
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $isLoggedIn = 1;
}

$isCartItems = Mage::helper('checkout/cart')->getSummaryCount();

echo $isCartItems;
echo $isLoggedIn;
  • Thanks for the answer. But still same result. – PHP Nov 23 '16 at 7:56
  • $isLoggedIn is returning 0 & $isCartItems returns nothing. I am logged in & having 1 cart item in frontend. – PHP Nov 23 '16 at 7:57
  • use Mage::app('default'); because i am using this code and working for me – Fme Extensions Nov 23 '16 at 8:00
  • Tried this also but no luck. – PHP Nov 23 '16 at 9:52
0

I had the same problem and i read in the session data by hand. Try the following:

<?php
require_once("{$_SERVER['DOCUMENT_ROOT']}/shop/app/Mage.php");

$cookie_exists = isset($_COOKIE['frontend']);

if($cookie_exists){
    $file = "{$_SERVER['DOCUMENT_ROOT']}/shop/var/session/sess_{$_COOKIE['frontend']}";
    if(file_exists($file)){
        $data = file_get_contents("{$_SERVER['DOCUMENT_ROOT']}/shop/var/session/sess_{$_COOKIE['frontend']}");
        session_decode($data);
    }
}

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

if($cookie_exists) {
    if (file_exists($file)) {
        Mage::getSingleton('core/session', array('value' => $_COOKIE['frontend']));
    }
}

$isLoogedIn = 0;

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $isLoggedIn = 1;
}

$isCartItems = Mage::helper('checkout/cart')->getSummaryCount();

echo $isCartItems;
echo $isLoggedIn;

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.