按国家/地区ID过滤客户集合

时间:2015-07-13 06:47:44

标签: magento magento-1.7 magento-1.8 magento-1.9

我按性别和姓名收集客户。我需要按国家/地区ID添加过滤器,但每个客户的国家/地区ID都位于地址集合中。

$collection = Mage::getModel('customer/customer')->getCollection()
        ->addAttributeToSelect('*');
        ->addAttributeToFilter('firstname', $post['firstname']);
        ->addAttributeToFilter('gender', $post['gender']);
        ->load();

所以我需要这样的东西:

$collection = Mage::getModel('customer/customer')->getCollection()
        ->addAttributeToSelect('*');
        ->addAttributeToFilter('firstname', $post['firstname']);
        ->addAttributeToFilter('gender', $post['gender']);

        ->addAttributeToFilter('country_id', $post['country_id']);//US
        ->load();

1 个答案:

答案 0 :(得分:0)

$collection = Mage::getResourceModel('customer/customer_collection')
    ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
    ->addFieldToFilter('billing_country_id','US')
    ;