【问题标题】:Filter customers collection by country id按国家/地区 ID 过滤客户集合
【发布时间】:2015-07-13 06:47:43
【问题描述】:

我正在按性别和姓名收集客户。我需要按国家 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();

【问题讨论】:

  • 如果您觉得有帮助,请采纳答案

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


【解决方案1】:
$collection = Mage::getResourceModel('customer/customer_collection')
    ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')
    ->addFieldToFilter('billing_country_id','US')
    ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-27
    • 1970-01-01
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-16
    • 2022-01-20
    相关资源
    最近更新 更多