從Megento獲得「品牌」和「類型」我對我們的產品在Magento與「類型」和「品牌」這樣的使用SQL查詢
我從來沒有與Magento的工作。我試圖搜索谷歌,但沒有幫助。
我想寫查詢以獲得某個產品的「品牌」和「類型」。
從Megento獲得「品牌」和「類型」我對我們的產品在Magento與「類型」和「品牌」這樣的使用SQL查詢
我從來沒有與Magento的工作。我試圖搜索谷歌,但沒有幫助。
我想寫查詢以獲得某個產品的「品牌」和「類型」。
您可以使用下面的代碼,但在此之前您需要知道品牌和類型的屬性代碼是什麼。你需要將這些代碼與這段代碼聯繫起來。
$_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
東西沿着這一行應該工作:
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的),以符合你的配置。
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
我不想PHP代碼,因爲我不發起Magento的...我需要RAW SQL查詢 – Umair
我認爲這是獲取某種產品與ID的屬性查詢您的有用鏈接[http://www.elevateweb.co.uk/magento-ecommerce/magento-direct-sql-query-get-attribute-values](http://www.elevateweb.co.uk/magento-ecommerce/magento-direct-sql-query-get-attribute-values) –
返回空結果 – Umair