Php Magento按姓名搜索客户
我正在创建magento扩展,我需要根据客户的名字搜索他们。我知道我可以在sql的帮助下做到这一点。但我想使用magento的客户模型来完成这项工作 我已经使用了它,它返回了一个包含所有用户的数组,但是我想要的不是所有用户,而是符合条件的特定用户Php Magento按姓名搜索客户,php,e-commerce,magento-1.7,Php,E Commerce,Magento 1.7,我正在创建magento扩展,我需要根据客户的名字搜索他们。我知道我可以在sql的帮助下做到这一点。但我想使用magento的客户模型来完成这项工作 我已经使用了它,它返回了一个包含所有用户的数组,但是我想要的不是所有用户,而是符合条件的特定用户 $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*'); $c=Mage::getModel('custo
$collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
$c=Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('first_name',array('like'=>$the_name',you_想要找的_name'))
$c=Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('first_name',array('like'=>$you想要找的_name))
您必须使用类似于简单的WHERE
子句的方法,在该子句中您也可以使用通配符
<?php
include 'app/Mage.php';
Mage::app();
$query = "John";
$model = Mage::getSingleton('customer/customer');
$result = $model->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('firstname', array('like' => "%$query%"));
foreach($result as $r)
{
$customer = $model->load($r->getId());
echo '<b>'.$customer->getFirstname().' '.$customer->getLastname().'</b><br/>';
}
您必须使用类似于简单的WHERE
子句的方法,在该子句中您也可以使用通配符
<?php
include 'app/Mage.php';
Mage::app();
$query = "John";
$model = Mage::getSingleton('customer/customer');
$result = $model->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('firstname', array('like' => "%$query%"));
foreach($result as $r)
{
$customer = $model->load($r->getId());
echo '<b>'.$customer->getFirstname().' '.$customer->getLastname().'</b><br/>';
}
也许我不知道你怎么称呼你的属性,如果它是“firstname”或“first_name”,如果你不喜欢“like”,你可以用eq来代替。哦,当然getCollection()之后没有中断-也许我不知道你把属性称为什么,如果它是“firstname”或“first_name”,如果你不喜欢“like”-你可以使用eq来代替查询。哦,当然在getCollection()之后没有中断-嘿,你能告诉我把这个文件放在磁电机的什么地方吗?如何搜索表单将对该文件执行操作?嘿,你能告诉我将该文件放在磁电机的何处吗?如何搜索此文件上的表单?