Search code examples
magentomagento-soap-api

Magento SOAP API v2: Get currently logged in customer email address


Is it possible to get the currently logged in customer's email address using the SOAP API?
I will NOT have the CustomerID.

I will be calling this from our ExpressionEngine installation.


Solution

  • This change in /code/core/Mage/Customer/Model/Customer/Api.php should return the currently logged in customer with all their info. I cannot currently test because I don't have SOAP installed in my PHP 5.2.14 installation.

    public function info($customerId, $attributes = null)
    {
        // if we didn't pass a $customerId
        if (!$customerId) {
            // get current customer session
            $custsess = Mage::getSingleton('customer/session');
            // if the customer is logged in
            if($custsess->isLoggedIn() == true) {
                // get their ID to load below
                $customerId = $custsess->getId();
                unset($custsess);
            }
        }
    
        $customer = Mage::getModel('customer/customer')->load($customerId);
    
        if (!$customer->getId()) {
            $this->_fault('not_exists');
        }
    
        if (!is_null($attributes) && !is_array($attributes)) {
            $attributes = array($attributes);
        }
    
        $result = array();
    
        foreach ($this->_mapAttributes as $attributeAlias=>$attributeCode) {
            $result[$attributeAlias] = $customer->getData($attributeCode);
        }
    
        foreach ($this->getAllowedAttributes($customer, $attributes) as $attributeCode=>$attribute) {
            $result[$attributeCode] = $customer->getData($attributeCode);
        }
    
        return $result;
    }