如何使用mysql拉出所有产品id,skus,产品名称,magento中的描述?

use*_*780 14 mysql magento

我将如何使用Magento数据库中的mysql提取所有产品ir,skus,产品名称(标题)和desxription?我使用了以下查询并获得了除产品名称之外的所有属性.

SELECT e.entity_id, e.sku, eav.value AS 'description'
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 ea.attribute_code = 'description'
Run Code Online (Sandbox Code Playgroud)

Mar*_*ius 30

标题可以从一个商店视图到另一个商店视图不同.同样适用于描述.此外,某些商店视图可以使用后端中设置的默认值.

以下是有关如何获取特定商店视图(ID 1)的所有产品所需数据(sku,名称,描述)的完整查询.

SELECT 
    `e`.`sku`, 
    IF(at_name.value_id > 0, at_name.value, at_name_default.value) AS `name`,
    IF(at_description.value_id > 0, at_description.value, at_description_default.value) AS `description`

FROM 
   `catalog_product_entity` AS `e` 
    INNER JOIN 
         `catalog_product_entity_varchar` AS `at_name_default` 
               ON (`at_name_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_name_default`.`store_id` = 0 
    LEFT JOIN 
          `catalog_product_entity_varchar` AS `at_name` 
               ON (`at_name`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_name`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'name' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_name`.`store_id` = 1) 
    INNER JOIN 
         `catalog_product_entity_text` AS `at_description_default` 
               ON (`at_description_default`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description_default`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  `at_description_default`.`store_id` = 0 
    LEFT JOIN 
          `catalog_product_entity_text` AS `at_description` 
               ON (`at_description`.`entity_id` = `e`.`entity_id`) AND 
                  (`at_description`.`attribute_id` = (SELECT attribute_id FROM `eav_attribute` ea LEFT JOIN `eav_entity_type` et ON ea.entity_type_id = et.entity_type_id  WHERE `ea`.`attribute_code` = 'description' AND et.entity_type_code = 'catalog_product')) AND 
                  (`at_description`.`store_id` = 1) 
Run Code Online (Sandbox Code Playgroud)

如果您希望将其用于其他商店视图,只需将值替换1为以下行中所需的ID

(`at_name`.`store_id` = 1) 
Run Code Online (Sandbox Code Playgroud)

(`at_description`.`store_id` = 1)
Run Code Online (Sandbox Code Playgroud)

我不知道你为什么需要这种格式的sql格式.这是一个奇怪的错误来源.您可以轻松地通过代码获取它:

$collection = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToSelect(array('sku', 'name', 'description'));
foreach ($collection as $item) {
    $sku = $item->getSku();
    $name = $item->getName();
    $description = $item->getDescription(); 
    //do something with $sku, $name & $description
}
Run Code Online (Sandbox Code Playgroud)

  • @ user3580780.它有效,请接受答案.不要留下松散的一端. (2认同)

Uma*_*air 11

这是另一个要显示的查询 entity_id, product_name, sku

SELECT
    catalog_product_entity_varchar.entity_id,
    catalog_product_entity_varchar.`value` AS product_name,
    catalog_product_entity.sku
FROM
    catalog_product_entity_varchar
INNER JOIN catalog_product_entity ON catalog_product_entity_varchar.entity_id = catalog_product_entity.entity_id
WHERE
    catalog_product_entity_varchar.entity_type_id = (
        SELECT
            entity_type_id
        FROM
            eav_entity_type
        WHERE
            entity_type_code = 'catalog_product'
    )
AND attribute_id = (
    SELECT
        attribute_id
    FROM
        eav_attribute
    WHERE
        attribute_code = 'name'
    AND entity_type_id = (
        SELECT
            entity_type_id
        FROM
            eav_entity_type
        WHERE
            entity_type_code = 'catalog_product'
    )
)
Run Code Online (Sandbox Code Playgroud)