magento - Magento 通过 eav 选项值查询客户
问题描述
我们为出生日期创建了自定义客户属性:
dob_month, dob_day
它们是 select 的前端输入类型和 int 的后端类型。我们试图从客户那里获得以下字段:entity_id
、、dob
和store_id
(如果可能,一个dob
字段,否则,分为dob_month
和dob_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 仅用于测试以限制结果。
解决方案
万一有人想要它,我最好的办法就是通过 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'
推荐阅读
- r - 按自定义换行符聚合
- javascript - 使用 mocha 测试异步功能
- mapkit - 通过点击 pin 注释转到 SwiftUI 视图
- python - Python - 使用相同的键提取多个 json
- amazon-web-services - 允许外部访问 aws 上的堡垒主机
- sql - SQL 连接没有给我正确的总数
- camera - OpenCV:calibrateHandEye 函数的错误结果
- python - 如何修复未定义的“NameError”“Person”
- javascript - 用 react-intersection-observer 开玩笑测试反应组件
- python - 正则表达式将数字字符串替换为字符串