我需要从Magento v1.9.2.1中的数据库表中获取特定数据我能够找到产品表但我不确定在哪里可以找到特定数据。
我有一个桌面应用程序,当您在Magento中查看特定产品时需要显示完全相同的数据
这些是我在Magento数据库中寻找的数据 - SKU,产品标题,价格,图像,简短描述,长描述
我很难理解它的数据库结构。如果有人能帮我查找数据,我真的很感激
答案 0 :(得分:1)
这可以帮助您入门。我使用LINQPad能够对我的Magneto数据库编码c#。它允许我针对数据库编写一些高级代码,但仍然可以看到生成的基础查询。
我有一个查询可以为我生成此结果:
+-----+-----+-------+---------------+-------------------+-----------------+
| sku | qty | price | special_price | special_from_date | special_to_date |
+-----+-----+-------+---------------+-------------------+-----------------+
| X1 | 5 | 13.99 | 8.99 | 2015-04-19 00:00 | |
| X2 | 12 | 10.99 | 7.99 | 2015-04-19 00:00 | |
| X3 | 9 | 9.99 | 5.99 | 2015-04-19 00:00 | |
+-----+-----+-------+---------------+-------------------+-----------------+
这是此数据的(略微简化的)c#查询:
var items =
from x in catalog_product_entity
join stock in cataloginventory_stock_item on x.entity_id equals stock.product_id
join price in catalog_product_entity_decimal.Where(_ => _.attribute_id == 75 && _.store_id == 0) on x.entity_id equals price.entity_id into prices
join special_price in catalog_product_entity_decimal.Where(_ => _.attribute_id == 76 && _.store_id == 0) on x.entity_id equals special_price.entity_id into special_prices
join special_from_date in catalog_product_entity_datetime.Where(_ => _.attribute_id == 77 && _.store_id == 0) on x.entity_id equals special_from_date.entity_id into special_from_dates
join special_to_date in catalog_product_entity_datetime.Where(_ => _.attribute_id == 78 && _.store_id == 0) on x.entity_id equals special_to_date.entity_id into special_to_dates
select new
{
x.sku,
stock.qty,
prices,
special_prices,
special_from_dates,
special_to_dates,
};
这会产生对DB的实际SQL调用:
SELECT t2.entity_id, t2.attribute_id, t2.entity_type_id, t2.store_id, t2.value, t2.value_id
FROM catalog_product_entity AS t0
INNER JOIN cataloginventory_stock_item AS t1
ON (t0.entity_id = t1.product_id)
LEFT OUTER JOIN catalog_product_entity_decimal AS t2
ON (((t2.attribute_id = 75) AND (t2.store_id = 0)) AND (t2.entity_id = t0.entity_id))
SELECT t2.entity_id, t2.attribute_id, t2.entity_type_id, t2.store_id, t2.value, t2.value_id
FROM catalog_product_entity AS t0
INNER JOIN cataloginventory_stock_item AS t1
ON (t0.entity_id = t1.product_id)
LEFT OUTER JOIN catalog_product_entity_decimal AS t2
ON (((t2.attribute_id = 76) AND (t2.store_id = 0)) AND (t2.entity_id = t0.entity_id))
SELECT t2.entity_id, t2.attribute_id, t2.entity_type_id, t2.store_id, t2.value, t2.value_id
FROM catalog_product_entity AS t0
INNER JOIN cataloginventory_stock_item AS t1
ON (t0.entity_id = t1.product_id)
LEFT OUTER JOIN catalog_product_entity_datetime AS t2
ON (((t2.attribute_id = 77) AND (t2.store_id = 0)) AND (t2.entity_id = t0.entity_id))
SELECT t2.entity_id, t2.attribute_id, t2.entity_type_id, t2.store_id, t2.value, t2.value_id
FROM catalog_product_entity AS t0
INNER JOIN cataloginventory_stock_item AS t1
ON (t0.entity_id = t1.product_id)
LEFT OUTER JOIN catalog_product_entity_datetime AS t2
ON (((t2.attribute_id = 78) AND (t2.store_id = 0)) AND (t2.entity_id = t0.entity_id))
SELECT t0.sku, t1.qty, t0.entity_id
FROM catalog_product_entity AS t0
INNER JOIN cataloginventory_stock_item AS t1
ON (t0.entity_id = t1.product_id)
现在,您需要知道数据库的attribute_id
值是什么。
我使用这个c#查询:
var query =
from et in eav_entity_type
where et.entity_model == "catalog/product"
join a in eav_attribute on et.entity_type_id equals a.entity_type_id
select new
{
a.attribute_id,
a.attribute_code,
a.backend_type
};
转换为此SQL:
SELECT t1.attribute_id, t1.attribute_code, t1.backend_type
FROM eav_entity_type AS t0
INNER JOIN eav_attribute AS t1
ON (t0.entity_type_id = t1.entity_type_id)
WHERE (t0.entity_model = @p0)
-- p0 = [catalog/product]
这给了我这样的结果:
+--------------+------------------------+--------------+
| attribute_id | attribute_code | backend_type |
+--------------+------------------------+--------------+
| 108 | category_ids | static |
| 92 | color | int |
| 79 | cost | decimal |
| 117 | country_of_manufacture | varchar |
| 115 | created_at | static |
| 103 | custom_design | varchar |
| 104 | custom_design_from | datetime |
| 105 | custom_design_to | datetime |
| 106 | custom_layout_update | text |
| 72 | description | text |
+--------------+------------------------+--------------+
然后使用后端类型生成SQL的LEFT OUTER JOIN catalog_product_entity_datetime AS t2 ON (((t2.attribute_id = 78)
snippits。