2011-12-28 67 views
0

我使用magento 1.6.1通過自定義字段篩選客戶

我只有手機號碼和客戶名稱。我需要加載這些客戶。

如何在magento中選擇這些客戶。

+1

目前尚不清楚問什麼。如果您需要一個客戶集合,只需使用'$ collection = Mage :: getResourceModel('customer/customer_collection');'作爲起點,然後您可以根據需要進行過濾;見http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/using_collections_in_magento – benmarks 2011-12-28 13:09:28

+0

是的本,其工作... – 2011-12-29 07:23:57

回答

0

以下代碼可幫助我過濾客戶。

$customers = Mage::getResourceModel('customer/customer_collection') 
       ->addAttributeToSelect('*') 
       ->addAttributeToFilter('firstname', $firstName) 
0

$customers = Mage::getResourceModel('customer/customer_collection') ->addAttributeToSelect('*') ->addAttributeToFilter('firstname', $firstName)

上面的代碼將只加載集合。

要通過名字獲取客戶詳細信息,我們需要遍歷客戶收集對象,然後獲取客戶ID。最後只加載單個客戶對象,如下

$model = Mage::getSingleton('customer/customer'); 

$customerCollection = $model->getCollection() 
    ->addAttributeToSelect('*') 
    ->addAttributeToFilter('firstname', array('like' => $variableFirstName)); 

foreach($customerCollection as $customerObject) 
{  
    $customer = $model->load($customerObject->getId()); 
    echo '<b>'.$customer->getFirstname() . $customer->getLastname().'</b><br/>'; 
} 

在情況下,如果我們想通過名字來過濾,只需更改到

->addAttributeToFilter('lastname', array('like' => $variableLastName))