1

I just want to fetch customer id with email as parameter from the mysql database. How can i hit the sql query to get the customer_id.

 $passphrase = "password";
 $salt = "SC";
 $password = md5($salt . $passphrase) . ":SC";

 $write->query("update customer_entity_varchar set value='$password' where entity_id=$customer_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type=1)");

This is the code which i been using to update password , I need dynamic customer id.

this is full code

<?php 
include('app/Mage.php');
Mage::app();  
if($_POST && $_POST["email"])
    {


          $collection = mage::getModel('customer/customer')->getCollection()      ->addAttributeToSelect('email')
         ->addAttributeToFilter('myemail@domain.com') 
         ->addAttributeToSort('email', 'ASC');
          var_dump((string)$collection->getSelect());
                         die();

                       $passphrase = "password";
                       $salt = "SC";
                       $password = md5($salt . $passphrase) . ":SC";

                       $write->query("update customer_entity_varchar set value='$password' where entity_id=$customer_id and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type=1)");


                      $send_data["success"]=true;
                      $send_data["message"]="Login Success";
                      $send_data["customer_id"]=$customer_id;

    }
    else
    {
            $send_data["success"]=false;
            $send_data["message"]="Enter both Email and Password";
    }
     Mage::getSingleton('customer/session')->loginById($send_data["customer_id"]);
    echo json_encode($send_data);

    ?>
  • Have a look at my updated answer change this line ->addAttributeToFilter('email',$_POST['email']) – Murtuza Zabuawala Sep 2 '16 at 11:00
1

You can try below code in magento

$collection = mage::getModel('customer/customer')->getCollection()
 ->addAttributeToSelect('email')
 ->addAttributeToFilter('email',$_POST['email']) 
 ->addAttributeToSort('email', 'ASC');
 var_dump((string)$collection->getSelect());

this will print following query

SELECT e.*, at_firstname.value AS firstname FROM customer_entity AS e INNER JOIN customer_entity_varchar AS at_firstname ON (at_firstname.entity_id = e.entity_id) AND (at_firstname.attribute_id = '5') WHERE (e.entity_type_id = '1') AND (at_firstname.value = 'sander') ORDER BY e.email ASC
|improve this answer|||||
  • and where i have to pass customer email ? – Man S. Sep 2 '16 at 7:47
  • In above code you will get Email for all customer in foreach loop or you want to filter on email bases ? – Murtuza Zabuawala Sep 2 '16 at 7:50
  • yes i want to filter with email , i want 1 record base on email , which should return customer_id. – Man S. Sep 2 '16 at 8:01
  • please look at my updated collection – Murtuza Zabuawala Sep 2 '16 at 8:04
  • earlier it was returning a query , but now its been throwing 500 in ajax – Man S. Sep 2 '16 at 9:37
0

You can change your password in following way. It is fetching dynamic customer id on the basis of customer email Id.

$email = $_POST["email"]; //Customer email id
        $customer = Mage::getModel("customer/customer");
        $customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
        $customer->loadByEmail($email);
        $passphrase = "123456";
        $salt = "SC";
        $password = md5($salt . $passphrase) . ":SC";
        $resource = Mage::getSingleton('core/resource');
        $query = "update customer_entity_varchar set value='" . $password . "' where entity_id=" . $customer->getId() . " and attribute_id in (select attribute_id from eav_attribute where attribute_code='password_hash' and entity_type_id=1)";
        $connection = $resource->getConnection('core_write');
        $connection->query($query);
|improve this answer|||||

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.