首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >使用SQL查询从数据库导入Magento产品

使用SQL查询从数据库导入Magento产品
EN

Stack Overflow用户
提问于 2011-03-16 17:15:20
回答 1查看 6.1K关注 0票数 2

Magento在其数据库系统中使用EAV结构。我有这个查询,它给出了我的magento商店中的product_id和产品名称。

代码语言:javascript
代码运行次数:0
运行
复制
SELECT e.entity_id AS product_id, var.value AS product_name
FROM catalog_product_entity e, eav_attribute eav, catalog_product_entity_varchar var
WHERE
   e.entity_type_id = eav.entity_type_id
   AND eav.attribute_code = 'name'
   AND eav.attribute_id = var.attribute_id
   AND var.entity_id = e.entity_id

我需要帮助来获取product_url|price|image_url|description|manufacturer

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-16 21:51:38

我不打算发布整个SQL查询,因为尝试通过数据库手动从Magento中获取数据太乏味了,但我会说您走对了路。为了减少此类连接的数量,我从eav表中检索attribute_ids并直接使用它们。这意味着我的查询只适用于我安装的Magento,但这对我来说不是问题。

代码语言:javascript
代码运行次数:0
运行
复制
select attribute_code, attribute_id, backend_type from eav_attribute
    where entity_type_id = (select entity_type_id from eav_entity_type where entity_type_code = 'catalog_product')
      and attribute_code in ('name', 'url_path', 'price', 'image', 'description', 'manufacturer');

收益率:

代码语言:javascript
代码运行次数:0
运行
复制
+----------------+--------------+--------------+
| attribute_code | attribute_id | backend_type |
+----------------+--------------+--------------+
| description    |           61 | text         |
| image          |           74 | varchar      |
| manufacturer   |           70 | int          |
| name           |           60 | varchar      |
| price          |           64 | decimal      |
| url_path       |           87 | varchar      |
+----------------+--------------+--------------+

现在你可以开始单调乏味了!对于每个属性代码,对给定属性ID的后端表(catalog_product_entity_$BACKEND_TYPE)进行连接。对我来说,这将变成一个sku/name/id查询(您的查询实际上不需要连接产品,因为您使用entity_id进行连接...)进入:

代码语言:javascript
代码运行次数:0
运行
复制
select p.sku, p.entity_id, n.value name
    from catalog_product_entity p
    join catalog_product_entity_varchar n on n.entity_id = p.entity_id
  where n.attribute_id = 60;

继续添加新的join-statement|where-子句|select-子句集,直到您拥有了最初需要的所有连接。

也就是说,Jonathan是正确的,使用Magento框架来管理这些数据比通过数据库手动管理要容易得多。除非您需要一次性加载大量的产品(请注意,这里有两个假设,您可以努力减少这两个假设),否则使用框架会更加健壮。

希望这能有所帮助!

谢谢,乔

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5323102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档