skip to Main Content

I not able to get the customersID am I calling it correctly with Mage::getModel

$customer = Mage::getModel('customer/customer')
    ->setWebsiteId(2)
    ->load($this->getRequest()->getParam('customer'));

$customer_id = $customer->getId();
$sku = 'BOX3151';

$sql = "SELECT sfoi.item_id FROM sales_flat_order_item sfoi INNER JOIN sales_flat_order sfo
ON sfo.entity_id = sfoi.order_id WHERE sfo.customer_id = '$customer_id' AND sfoi.sku = '$sku'";
$read_db = Mage::getSingleton('core/resource')->getConnection('core_read');
$result = $read_db->fetchAll($sql);
$total_rows = count($result);
    if($total_rows >= 1):
        echo ' Found ';
    else:
        echo ' Empty ';
    endif;
endif;

2

Answers


  1. Please check for available data in
    $this->getRequest()->getParam(‘customer’)

    if you have $customerId there you can use the load() method.

    $customer = Mage::getModel('customer/customer')
        ->setWebsiteId(2)
        ->load($customerId)
    

    also you can get customer object by $email.

    $customer = Mage::getModel('customer/customer')
        ->setWebsiteId(2)
        ->loadByEmail($email);
    
    Login or Signup to reply.
  2. <?php
    $email = "[email protected]";
    $customer = Mage::getModel("customer/customer")->setWebsiteId(Mage::app()->getWebsite()->getId())->loadByEmail($email);
    //use
    echo $customer->getId();
    echo $customer->getEmail(); 
    echo $customer->getFirstname(); 
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search