簡體   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