我正试图通过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
答案 0 :(得分:4)
电子邮件存储在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
如果您对此感兴趣,可以通过PHP使用Magento的工厂方法来完成
<?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 = '')