mysql - 从 magento 数据库获取客户姓名和电子邮件

标签 mysql magento

我正在尝试从 magento 中获取我们客户的所有姓名和电子邮件。

我有以下代码,但我不确定如何获取邮件

SELECT entity_id, GROUP_CONCAT( VALUE
SEPARATOR  ' ' ) AS fullname
FROM customer_address_entity_varchar AS val
INNER JOIN eav_attribute AS attr ON attr.attribute_id = val.attribute_id
WHERE attr.attribute_code
IN (
'firstname',  'lastname',  'email'
)
GROUP BY entity_id
LIMIT 0 , 30

最佳答案

电子邮件存储在 customer_entity 表中,而不是 eav 表中。

试试这个查询:

select ce.entity_id, concat(cevf.value, ' ', cevl.value) fullname, ce.email
from customer_entity ce
inner join customer_entity_varchar cevf
    on ce.entity_id = cevf.entity_id
inner join eav_attribute eaf
    on eaf.attribute_id = cevf.attribute_id
inner join customer_entity_varchar cevl
    on ce.entity_id = cevl.entity_id
inner join eav_attribute eal
    on eal.attribute_id = cevl.attribute_id
inner join eav_entity_type eet
    on eet.entity_type_id = eal.entity_type_id = eaf.entity_type_id
where
    eet.entity_type_code = 'customer'
    and eaf.attribute_code = 'firstname'
    and eal.attribute_code = 'lastname'
order by ce.entity_id

如果您对此感兴趣,可以使用 Magento 的工厂方法通过 PHP 完成

<?php

include 'app/Mage.php';
Mage::app();
$customerCollection = Mage::getModel('customer/customer')
    ->getCollection()
    ->addAttributeToSelect('firstname')
    ->addAttributeToSelect('lastname');
echo $customerCollection->getSelect();
// foreach ($customerCollection as $customer) print_r($customer->getData());

这会给你类似的东西

SELECT `e`.*, `at_firstname`.`value` AS `firstname`, `at_lastname`.`value` AS `lastname` FROM `customer_entity` AS `e`
 INNER JOIN `customer_entity_varchar` AS `at_firstname` ON (`at_firstname`.`entity_id` = `e`.`entity_id`) AND (`at_firstname`.`attribute_id` = '5')
 INNER JOIN `customer_entity_varchar` AS `at_lastname` ON (`at_lastname`.`entity_id` = `e`.`entity_id`) AND (`at_lastname`.`attribute_id` = '7') WHERE (`e`.`entity_type_id` = '1') AND (at_firstname.value = '') AND (at_lastname.value = '')

关于mysql - 从 magento 数据库获取客户姓名和电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23253894/

相关文章:

javascript - 自定义产品选项 - 修改基于百分比的定价逻辑 : Magento

mysql - 如何在 MySQL 的 JSON 路径中使用 CONCAT?

mysql - 需要用我的系统IP进行mysql远程访问

php - 使用 SUM() 问题选择付款的简单单选按钮

mysql - 使用 "SELECT"显示分组结果

mysql - 客户必须至少有 3 封电子邮件

Magento createBlock 方法不起作用,显示静态 block 数据

image - Magento:在订单电子邮件中显示产品图像

magento订单ID增量跳转

html - 将圆形 Logo 添加到 magento 2 标题