2011-12-28 43 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)) 
相关问题