繁体   English   中英

从magento数据库获取客户名称和电子邮件

[英]Get customer names and emails from magento database

我正在尝试从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 = '')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM