2

I made a customer log-in to the site programmatically... I am properly returned the session values in form of an object.

Now i want this data carried over and returned from the function in JSON format.

I know magento has its own encoding and decoding functions... But this conversion does not some how take place properly.

I mean session object contains customer's email, first, last name,etc. But these are not reflected in converted json... So how do I convert this properly??

Thanks in advance

Here is my code..

<?php

function loginUser( $email, $password )
{
    require_once ("../../app/Mage.php");
    umask(0);
    ob_start();
    session_start();
    Mage::app('default');
    Mage::getSingleton("core/session", array("name" => "frontend"));

    $websiteId = Mage::app()->getWebsite()->getId();
    $store = Mage::app()->getStore();
    $customer = Mage::getModel("customer/customer");
    $customer->website_id = $websiteId;
    $customer->setStore($store);
    try {
        $customer->loadByEmail($email);
        $session = Mage::getSingleton('customer/session');
        $session->login($email, $password);
        $session->setCustomerAsLoggedIn($customer);
        $jsonData = Mage::helper('core')->jsonEncode($session);
        var_dump($jsonData);

    }catch(Exception $e){
        return $e->getMessage();
    }


  } 

    $test = loginUser("[email protected]","testigex");
    //var_dump($test);
?>
1
  • I can't help, but little tip: add in your question what you're really getting as opposed to what you want to get. Makes the question more understandable
    – Yorrd
    May 13, 2015 at 8:05

1 Answer 1

4

It is not good idea to return a php object to json value.As per as,php concept json is convert a string varible and an array of string variables to json object.

Json does not capable to convert a php to json object.

If you want data then need to return customer data in array format.

just like:

$jsonData = Mage::helper('core')->jsonEncode($customer->getData());

getData() is give Customer data in array format.

1

Your Answer

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

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