获得"品牌"和"键入"来自Megento使用SQL查询

时间:2016-07-18 10:32:50

标签: sql magento

我的产品是magento的" Type"和"品牌"像这样

enter image description here

我从未与Magento合作过。我试图搜索谷歌,但这没有帮助。

我想写一个查询来获得" Brand"和"键入"特定产品。

3 个答案:

答案 0 :(得分:1)

您可以使用以下代码,但在此之前您需要知道品牌和类型的属性代码是什么。并且您需要将该代码与此代码相关联。

$_product = Mage::getModel('catalog/product')->getResource()->getIdBySku('your sku');
$Type = $_product->getAttributeText('[Type_attribute_code]');
$Brand = $_product->getAttributeText('[Brand_attribute_code]');
  

您需要使用您的产品ID替换entityid,您将获得所有属性值。

SET @entityid = 203;

SELECT ea.attribute_code, eav.value AS 'value', 'varchar' AS 'type'
FROM catalog_product_entity e
JOIN catalog_product_entity_varchar eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE e.entity_id = @entityid
UNION
SELECT ea.attribute_code, eav.value AS 'value', 'int' AS 'type'
FROM catalog_product_entity e
JOIN catalog_product_entity_int eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE e.entity_id = @entityid
UNION
SELECT ea.attribute_code, eav.value AS 'value', 'decimal' AS 'type'
FROM catalog_product_entity e
JOIN catalog_product_entity_decimal eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE e.entity_id = @entityid
UNION
SELECT ea.attribute_code, eav.value AS 'value', 'datetime' AS 'type'
FROM catalog_product_entity e
JOIN catalog_product_entity_datetime eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE e.entity_id = @entityid
UNION
SELECT ea.attribute_code, eav.value AS 'value', 'text' AS 'type'
FROM catalog_product_entity e
JOIN catalog_product_entity_text eav
  ON e.entity_id = eav.entity_id
JOIN eav_attribute ea
  ON eav.attribute_id = ea.attribute_id
WHERE e.entity_id = @entityid

答案 1 :(得分:1)

根据这一点应该有效:

SELECT cpe.entity_id, cpe.sku, cpev.value, eaov.value, ea.attribute_code 
FROM magento.catalog_product_entity cpe 
inner join magento.catalog_product_entity_varchar cpev on cpev.entity_id = cpe.entity_id 
inner join magento.eav_attribute ea on ea.attribute_id = cpev.attribute_id 
inner join magento.eav_attribute_option_value eaov on eaov.option_id = cpev.value
where ea.frontend_label regexp  'Type|Brand';

您可能需要更改数据库名称(我的是magento)以匹配您的设置。

答案 2 :(得分:0)

SELECT
    eav_attribute_option_value.option_id,
    eav_attribute_option_value.`value`,
    catalog_product_index_eav_idx.attribute_id,
    catalog_product_index_eav_idx.entity_id
FROM
    eav_attribute_option_value
INNER JOIN catalog_product_index_eav_idx ON catalog_product_index_eav_idx.`value` = eav_attribute_option_value.option_id
AND catalog_product_index_eav_idx.entity_id = 3566
GROUP BY
    eav_attribute_option_value.option_id

这是可以通过指定entity_id = 3566

来获取具有ID的特定产品的属性的查询