Php 从magento表结构获取客户信息
我想从magento表中获取所有客户详细信息的行 有人能问我这个问题吗 表格如下:Php 从magento表结构获取客户信息,php,magento,Php,Magento,我想从magento表中获取所有客户详细信息的行 有人能问我这个问题吗 表格如下: 客户单位 eav_属性 客户\实体\ varchar 您是在为这个或某些Magento代码寻找实际的SQL吗?实际的SQL将变得混乱,并且可能永远不会按照您希望的方式进行 由于MySQL中没有“pivot”,所以在实际查询中基本上可以忽略eav\u属性。您将查看它以找到所需的属性ID。下面是一个如何选择此数据的简单示例: select c.*, fn.value firstname from custo
- 客户单位
- eav_属性
- 客户\实体\ varchar
eav\u属性
。您将查看它以找到所需的属性ID。下面是一个如何选择此数据的简单示例:
select c.*, fn.value firstname
from customer_entity c
join customer_entity_varchar fn
on c.entity_id = fn.entity_id and fn.attribute_id = 5
;
继续为每个属性添加那些join子句,您将得到您的查询。基本上,EAV并没有针对这种访问进行优化
如果您能更详细地说明您正在尝试做什么(或者Magento中的PHP代码是否适用于您的目的),我们可能会进一步帮助您
希望有帮助
谢谢,
Joe可以从Magento MySQL数据库中提取一些数据,但在执行以下查询之前,请注意: 1) Magento是可配置的,因此您不能从MySQL获取数据,但必须使用Magento客户模块(模型、资源模型)和Magento配置数据来检索客户数据。任何直接查询都不能保证与不同的Magento版本兼容,甚至不能保证与相同版本的安装兼容 2) Magento EAV结构不允许您在一个查询中以良好的形式获取所有客户数据,因为表名与属性是动态匹配的 3) 您不能仅通过一个查询甚至多个查询来提取所有客户数据。因为许多信息对象是在模型中创建的,并且只有模型具有在一个客户对象中收集所有数据的逻辑。我会谈论发货/账单地址、商店信用、奖励积分(对于EE版本)等等 但是,为了获取所有客户的varchar属性,您可以使用以下代码(由于上文1中提到的原因,不保证工作): 也可以使用这样的查询来提取客户的所有属性
SELECT ce.*, ea.attribute_code,
CASE ea.backend_type
WHEN 'varchar' THEN ce_varchar.value
WHEN 'int' THEN ce_int.value
WHEN 'text' THEN ce_text.value
WHEN 'decimal' THEN ce_decimal.value
WHEN 'datetime' THEN ce_datetime.value
ELSE NULL
END AS value
FROM customer_entity AS ce
LEFT JOIN eav_attribute AS ea ON ce.entity_type_id = ea.entity_type_id
LEFT JOIN customer_entity_varchar AS ce_varchar ON ce.entity_id = ce_varchar.entity_id AND ea.attribute_id = ce_varchar.attribute_id AND ea.backend_type = 'varchar'
LEFT JOIN customer_entity_int AS ce_int ON ce.entity_id = ce_int.entity_id AND ea.attribute_id = ce_int.attribute_id AND ea.backend_type = 'int'
LEFT JOIN customer_entity_text AS ce_text ON ce.entity_id = ce_text.entity_id AND ea.attribute_id = ce_text.attribute_id AND ea.backend_type = 'text'
LEFT JOIN customer_entity_decimal AS ce_decimal ON ce.entity_id = ce_decimal.entity_id AND ea.attribute_id = ce_decimal.attribute_id AND ea.backend_type = 'decimal'
LEFT JOIN customer_entity_datetime AS ce_datetime ON ce.entity_id = ce_datetime.entity_id AND ea.attribute_id = ce_datetime.attribute_id AND ea.backend_type = 'datetime'
我读了上面的内容,知道有些人正试图解决我的问题,我感觉好多了。 嗯,你可能知道,你在magento后台办公室找不到关于你客户的全部信息。 我想有一个非常大的表,在那里我可以看到我所有的客户(那些拥有账户=已注册的客户)(以及那些刚刚注册到《新闻快报》时事通讯订户的客户) 因为我不知道magento是如何提供这些信息的,所以我编写了SOMSQL代码来提取数据 如上所述,您不可能在一个查询中获得有关客户端的所有信息。实际上,您将需要与客户机属性一样多的查询。 如果实体客户端有45个属性(名称、姓氏、中间名、电子邮件…) 然后您将需要45个查询来提取它们。。。 我的问题是如何 答案是观点!! 实际上,我编写了视图来提取每个属性信息。这意味着我写了45个纹理,每个视图选择一个属性 我不知道它是如何在您的数据库中完成的,但是,您可能知道每个实体都有一个实体类型id。 在我的例子中,我对customer\u实体和customer\u address\u实体感兴趣。 客户实体的实体类型id=1 客户地址实体具有实体类型id=2 每个实体都有属性。因此,如果要查看客户实体的可用属性,请运行查询:
从实体类型id=1的eav\u属性中选择属性代码、属性id、后端类型
地址实体也是这样,将1替换为2
列属性_id非常重要,因为这将使您能够通过表中的id查找属性:
实体\客户\ vachar、实体\客户\ int、实体\客户\文本、实体\客户\日期时间
您可能会在这个表中找到firstname属性_id=5,正如Joseph Mastey在他的查询中所写的那样
信息在上表中按类型发送。
当您运行上面的查询时,您将看到每个属性都有一个backendtype。这意味着您要查找的信息是由其类型作为后缀的表之一。
例如,如果您正在查找类型为varchar的firstname,那么您将在customer\u entity\u varchar中找到它,依此类推
如果你还在读书,那可能意味着你明白我在说什么。
另一方面,您需要了解EAV模型
以及magento 1.3.2.4数据库模式
我不能发布整个解决方案,因为它还没有准备好,如果可以的话,我会放一个zip文件
同时,如果有人知道如何使用带有php文件的magento对象在不编辑magento核心的情况下访问数据,那将是非常棒的!
谢谢这是一个从magento表中提取客户详细信息的小查询:
select c.*,
(select fn.value from customer_entity_varchar fn where c.entity_id = fn.entity_id and
fn.attribute_id = 5) as Name,
(select fn.value from customer_entity_varchar fn where c.entity_id = fn.entity_id and
fn.attribute_id = 7) as Lastname
from customer_entity c
我特别尝试从我的Magento商店出口客户的手机号码 首先,您可以使用扩展到客户数据集的数据配置文件来实现这一点 在我的例子中,data profiles函数由于某种原因无法正常工作,因为我没有时间弄清楚为什么我直接去MySQL获取数据 下面的MySQL查询将使您能够提取具有英国移动电话号码的客户。注意:您可能需要计算出所需数据的属性id,并在查询中相应地更新
attribute_id value
26 Country
19 First_Name
21 Surname
31 Telephone
查询:-
SELECT
`firstname`.`value` as `First_Name`,
`surname`.`value` as `Surname`,
`telephone`.`value` as `Telephone`,
`customer_entity`.`created_at`,
`customer_entity`.`updated_at`
FROM
`customer_address_entity_varchar` as `country`
INNER JOIN
`customer_address_entity_varchar` as `firstname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as `surname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as `telephone` USING (`entity_id`)
INNER JOIN
`customer_entity` USING (`entity_id`)
WHERE
`country`.`attribute_id` = 26 &&
`country`.`value`="GB" &&
`firstname`.`attribute_id` = 19 &&
`surname`.`attribute_id` = 21 &&
`telephone`.`attribute_id` = 31 &&
`telephone`.`value` LIKE "07%"
GROUP BY `telephone`.`value`
limit 0,10;
注意limit和where语句将结果限制为特定数据,组停止重复号码,因为我想要的实际数据是电话号码。您可以添加到输出文件中,以将结果集导出为CSV
希望这对某人有所帮助……我修改了安德烈·特塞库斯的伟大答案。并添加了一个新的WHERE子句。现在,您只需更换产品SKU,即可获得所有cu
SELECT
`firstname`.`value` as `First_Name`,
`surname`.`value` as `Surname`,
`telephone`.`value` as `Telephone`,
`customer_entity`.`created_at`,
`customer_entity`.`updated_at`
FROM
`customer_address_entity_varchar` as `country`
INNER JOIN
`customer_address_entity_varchar` as `firstname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as `surname` USING (`entity_id`)
INNER JOIN
`customer_address_entity_varchar` as `telephone` USING (`entity_id`)
INNER JOIN
`customer_entity` USING (`entity_id`)
WHERE
`country`.`attribute_id` = 26 &&
`country`.`value`="GB" &&
`firstname`.`attribute_id` = 19 &&
`surname`.`attribute_id` = 21 &&
`telephone`.`attribute_id` = 31 &&
`telephone`.`value` LIKE "07%"
GROUP BY `telephone`.`value`
limit 0,10;
/* Just replace the value for i.sku in line 32, with the corresponding sku of the product you want to get the buyers from*/
SELECT
`e`.*,
`at_prefix`.`value` AS `prefix`,
`at_firstname`.`value` AS `firstname`,
`at_middlename`.`value` AS `middlename`,
`at_lastname`.`value` AS `lastname`,
`at_suffix`.`value` AS `suffix`,
CONCAT(IF(at_prefix.value IS NOT NULL AND at_prefix.value != '',
CONCAT(LTRIM(RTRIM(at_prefix.value)), ' '),
''),
LTRIM(RTRIM(at_firstname.value)), ' ',
IF(at_middlename.value IS NOT NULL AND at_middlename.value != '',
CONCAT(LTRIM(RTRIM(at_middlename.value)), ' '),
''),
LTRIM(RTRIM(at_lastname.value)),
IF(at_suffix.value IS NOT NULL AND at_suffix.value != '',
CONCAT(' ', LTRIM(RTRIM(at_suffix.value))),
'')
) AS `name`
FROM `customer_entity` AS `e`
LEFT JOIN `customer_entity_varchar` AS `at_prefix` ON (`at_prefix`.`entity_id` = `e`.`entity_id`) AND (`at_prefix`.`attribute_id` = '4')
LEFT JOIN `customer_entity_varchar` AS `at_firstname` ON (`at_firstname`.`entity_id` = `e`.`entity_id`) AND (`at_firstname`.`attribute_id` = '5')
LEFT JOIN `customer_entity_varchar` AS `at_middlename` ON (`at_middlename`.`entity_id` = `e`.`entity_id`) AND (`at_middlename`.`attribute_id` = '6')
LEFT JOIN `customer_entity_varchar` AS `at_lastname` ON (`at_lastname`.`entity_id` = `e`.`entity_id`) AND (`at_lastname`.`attribute_id` = '7')
LEFT JOIN `customer_entity_varchar` AS `at_suffix` ON (`at_suffix`.`entity_id` = `e`.`entity_id`) AND (`at_suffix`.`attribute_id` = '8')
WHERE (`e`.`entity_type_id` = '1')
AND `e`.`entity_id` IN (
SELECT DISTINCT o.customer_id FROM sales_flat_order_item i
INNER JOIN sales_flat_order o ON o.entity_id = i.order_id
WHERE o.customer_id IS NOT NULL
AND i.sku = '10-10-10101-4'
)
LIMIT 1000
SELECT customer_address_entity_varchar.value, customer_entity.entity_id
FROM customer_address_entity_varchar
LEFT JOIN customer_address_entity
ON customer_address_entity_varchar.entity_id = customer_address_entity.entity_id
LEFT JOIN customer_entity
ON customer_address_entity.parent_id = customer_entity.entity_id
WHERE attribute_id =31
SELECT c.entity_id,c.email,
(
SELECT fn.value
FROM customer_entity_varchar fn
WHERE c.entity_id = fn.entity_id AND
fn.attribute_id = 12) AS password_hash,
(
SELECT fn.value
FROM customer_entity_varchar fn
WHERE c.entity_id = fn.entity_id AND
fn.attribute_id = 5) AS name,
(
SELECT fn.value
FROM customer_entity_varchar fn
WHERE c.entity_id = fn.entity_id AND
fn.attribute_id = 7) AS lastname,
(
SELECT fn.value
FROM customer_entity_varchar fn
WHERE c.entity_id = fn.entity_id AND
fn.attribute_id = 150) AS cpfcnpj,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 149) AS cpfcnpj2,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 145) AS rg,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 151) AS phone1,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 31) AS phone2,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 27) AS country,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 28) AS state,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 26) AS city,
cat.value AS address,
(
SELECT fn.value
FROM customer_address_entity_varchar fn
WHERE ca.entity_id = fn.entity_id AND
fn.attribute_id = 30) AS cep
FROM customer_entity AS c
LEFT JOIN customer_address_entity AS ca ON c.entity_id = ca.parent_id
LEFT JOIN customer_address_entity_text AS cat ON cat.entity_id = ca.entity_id
GROUP BY entity_id
SELECT c.email, cv.value as fname, cv2.value as lname
FROM customer_entity c, customer_entity_varchar cv, customer_entity_varchar cv2
WHERE c.entity_id = $user_id
AND c.entity_id = cv.entity_id
AND cv.attribute_id = 5
AND c.entity_id = cv2.entity_id
AND cv2.attribute_id = 7
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
Mage::log($customerData);}
Array
(
[entity_id] => 1
[entity_type_id] => 1
[attribute_set_id] => 0
[website_id] => 1
[email] => test@example.com
[group_id] => 1
[increment_id] => 000000001
[store_id] => 1
[created_at] => 2007-08-30 23:23:13
[updated_at] => 2008-08-08 12:28:24
[is_active] => 1
[firstname] => Test
[lastname] => User
[password_hash] => 204948a40200e4238db2277d5:eg
[prefix] =>
[middlename] =>
[suffix] =>
[taxvat] =>
[default_billing] => 274
[default_shipping] => 274
)
select c.entity_id, c.email,
a.attribute_id, a.attribute_code, a.frontend_label, a.backend_type, a.frontend_input,
case a.backend_type
when 'int' then coalesce(o.value, cei.value)
when 'varchar' then cev.value
end as value
from customer_entity c
left join eav_attribute a on a.entity_type_id = c.entity_type_id
left join customer_entity_int cei on a.backend_type = 'int' and cei.attribute_id = a.attribute_id and cei.entity_id = c.entity_id and cei.entity_type_id = c.entity_type_id
left join customer_entity_varchar cev on a.backend_type = 'varchar' and cev.attribute_id = a.attribute_id and cev.entity_id = c.entity_id and cev.entity_type_id = c.entity_type_id
left join eav_attribute_option_value o on a.backend_type = 'int' and a.frontend_input = 'select' /* and o.store_id = c.store_id */ and o.option_id = cei.value
-- where c.entity_id = 17651
having value is not null
order by c.entity_id, a.attribute_code;