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

发布于 2024-10-22 11:34:16 字数 439 浏览 2 评论 0原文

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

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

我需要帮助获取产品网址|价格|图片网址|描述|制造商

Magento uses the EAV structure in its database system. I have this query that gives me product_id and name of products in my magento store.

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

I need help in getting product_url|price|image_url|description|manufacturer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒中人 2024-10-29 11:34:16

我不会发布整个 SQL 查询,因为尝试通过数据库手动从 Magento 中获取数据太乏味了,但我会说你走在正确的轨道上。为了减少此类事情的联接数量,我从 eav 表中检索 attribute_ids 并直接使用它们。这意味着我的查询仅适用于安装的 Magento,但这对我来说不是问题。

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');

产量:

+----------------+--------------+--------------+
| 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 查询(您的查询实际上不需要针对产品加入,因为您使用实体_id 进行加入...)转换为:

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;

继续添加新的加入语句|where-子句|选择子句设置直到您拥有最初想要的所有联接。

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

希望有帮助!

谢谢,

I'm not going to post the entire SQL query because it is far too tedious trying to get data out of Magento manually via the database, but I will say you're on the right track. To cut down on the number of joins for this sort of thing, I retrieve my attribute_ids from the eav table and use them directly. This means that my query will only work on my install of Magento, but that hasn't been an issue for me.

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');

Yields:

+----------------+--------------+--------------+
| 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      |
+----------------+--------------+--------------+

Now you're ready for tedium! For each attribute code, join against the backend table (catalog_product_entity_$BACKEND_TYPE) on your given attribute ID. For me, this would turn a sku/name/id query (your query actually doesn't need to join against products, since you use the entity_id to make the join...) into:

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;

Continue adding new join-statement|where-clause|select-clause sets until you have all the joins you wanted originally.

That said, Jonathan is correct that using the Magento framework to manage this data would be far easier than doing it manually via the database. Unless you have an extreme number of products that you need to load all at once (note there are two assumptions there, and you can work to reduce either), it would be far more robust to use the framework.

Hope that helps!

Thanks,
Joe

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文