【问题标题】:Magento querying customers by eav option valueMagento 通过 eav 选项值查询客户
【发布时间】:2018-05-09 19:06:30
【问题描述】:

我们为出生日期创建了自定义客户属性:

dob_month, dob_day

它们是 select 的前端输入类型和 int 的后端类型。我们正在尝试从客户那里获取以下字段:entity_iddobstore_id(如果可能,一个 dob 字段,否则,分为 dob_monthdob_day)。

这是我们正在苦苦挣扎的情况,我们想按这些选项值进行过滤。示例:dob_month = 05 和 dob_day = 08

我们尝试过的所有操作要么必须按存储在 customer_entity_int 中的值进行过滤,例如:1125 = eav_option_value of 05,要么我们只能检索存储在 customer_entity_int 中的值。

我想一定有办法。您能提供的任何帮助将不胜感激。

这是我得到的最接近的:

$collection = Mage::getResourceModel('customer/customer_collection')
                ->addAttributeToSelect('email')
                ->addAttributeToSelect('dob_month', 'left')
                ->addAttributeToSelect('dob_day', 'left')
                ->addExpressionAttributeToSelect('dob', "CONCAT({{dob_month}}, '-',{{dob_day}})", array(
                'dob_month', 'dob_day'
                ))
->addAttributeToFilter('dob_month', array(
    array('eq' => '1125')
))
/*->addAttributeToFilter('dob_day', array(
    array('eq' => '08')
))*/
->setPageSize(20)
->setCurPage(1);

注意:PageSize 和 CurPage 仅用于测试限制结果。

【问题讨论】:

  • 我不太明白你的意思是只能按 dob_month 或 dob_day 过滤而不是同时过滤它们。你得到的查询是什么?执行 echo $collection->getSelect() 以查看最终查询是什么
  • 我们希望能够通过eav_option_value 而不是customer_entity_int 进行过滤。在我们的示例中,customer_entity_int 的值为 1125,等于 05 的 eav_option_value。我们正在尝试找出一种方法来过滤 05 的 eav_option_value

标签: magento


【解决方案1】:

如果有人想要它,我最好的办法就是通过 SQL 来完成:

SELECT e.entity_id,CONCAT(dob_month_eav.value, '-',dob_day.dob_day) as dob,e.store_id FROM customer_entity AS e
LEFT JOIN customer_entity_int AS cv 
ON ( cv.attribute_id = (
    SELECT attribute_id FROM eav_attribute 
    WHERE entity_type_id = e.entity_type_id 
    AND attribute_code = 'dob_month'
    )
AND cv.entity_id = e.entity_id)
LEFT JOIN `eav_attribute_option_value` as `dob_month_eav` ON dob_month_eav.option_id=cv.value 
LEFT JOIN (SELECT e.entity_id,dob_day_eav.value as dob_day,e.store_id FROM customer_entity AS e
LEFT JOIN customer_entity_int AS cv 
ON ( cv.attribute_id = (
    SELECT attribute_id FROM eav_attribute 
    WHERE entity_type_id = e.entity_type_id 
    AND attribute_code = 'dob_day'
    )
AND cv.entity_id = e.entity_id)
LEFT JOIN `eav_attribute_option_value` as `dob_day_eav` ON dob_day_eav.option_id=cv.value) as dob_day ON dob_day.entity_id=e.entity_id
WHERE dob_month_eav.store_id=0 AND dob_month_eav.value='05' AND dob_day='08'

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多