it-swarm.com.de

Wie kann man die gesamte Produkt-ID, den Skus, die Produktnamen und die Beschreibung in Magento nur mit Mysql abrufen?

Wie werde ich das gesamte Produkt oder den Skus, den Produktnamen (Titel) und die Beschreibung unter Verwendung von Mysql aus der Magento-Datenbank abrufen? Ich verwendete folgende Abfrage und erhielt alle Attribute außer Produktnamen.

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'
14
user3580780

Der Titel kann sich von einer Store-Ansicht zur anderen unterscheiden. Gleiches gilt für die Beschreibung. Außerdem können einige Geschäftsansichten die im Backend festgelegten Standardwerte verwenden. 

Hier finden Sie eine vollständige Abfrage, wie Sie die benötigten Daten (Produkt, Name, Beschreibung) für alle Produkte für eine bestimmte Geschäftsansicht (ID 1) erhalten. 

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) 

Wenn Sie es für eine andere Geschäftsansicht wünschen, ersetzen Sie einfach den Wert 1 durch Ihre gewünschte ID in den folgenden Zeilen

(`at_name`.`store_id` = 1) 

und 

(`at_description`.`store_id` = 1)

Ich weiß nicht, warum Sie dies in einem SQL-Format benötigen. Dies ist eine merkwürdige und große Fehlerquelle. Sie können es leicht durch Code erhalten: 

$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
}
29
Marius

Hier ist eine weitere Abfrage zum Anzeigen von 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'
    )
)
11
Umair

Zum Abrufen des Produktnamens versuchen Sie es bitte 

$sql = "SELECT `value`
FROM catalog_product_entity_varchar
WHERE 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'))";

$results = $readConnection->fetchAll($sql);
4
VishalPandita

Unten ist der einfache Weg.

select 
sku.entity_id, sku.sku, #get sku and entity
productName.value, #get name
description.value #get description
from 
catalog_product_entity as sku,
catalog_product_entity_varchar as productName,
catalog_product_entity_text as description
where
productName.attribute_id = 73 
and
sku.entity_id = productName.entity_id
and
description.attribute_id = 75
and
sku.entity_id = description.entity_id;
1

Diese Abfrage enthält Produkt name, image, price, quantity, description.

SET @etype = (SELECT 
                    entity_type_id
                FROM
                    eav_entity_type
                WHERE
                    entity_type_code = 'catalog_product');

Produkt name Attribut-ID

SET @name  = (SELECT 
            attribute_id
        FROM
            eav_attribute
        WHERE
            attribute_code = 'name'
                AND entity_type_id = @etype);

Produkt image Attribut-ID

SET @image  = (SELECT 
            attribute_id
        FROM
            eav_attribute
        WHERE
            attribute_code = 'image'
                AND entity_type_id = @etype);                

ID-Nummer für ein kleines Bild eines Produkts

SET @smallimage = (SELECT 
        attribute_id
        FROM 
           eav_attribute
        WHERE 
           attribute_code = 'small_image'
               AND entity_type_id = @etype);

Produkt price Attribut-ID

SET @price  = (SELECT 
            attribute_id
        FROM
            eav_attribute
        WHERE
            attribute_code = 'price'
                AND entity_type_id = @etype);

Produkt description Attribut-ID

SET @description  = (SELECT 
            attribute_id
        FROM
            eav_attribute
        WHERE
            attribute_code = 'description'
                AND entity_type_id = @etype);

- Admin-Store-ID -- SET @store = 0;

SELECT 
    e.entity_id AS 'id',
    e.sku,
    v1.value AS 'name',
    v2.value AS 'image',
    s2.value AS 'small_image',
    si.qty AS 'stock qty',
    d1.value AS 'price',
    s1.value AS 'description'
FROM
    catalog_product_entity e
        LEFT JOIN
    cataloginventory_stock_item si ON e.entity_id = si.product_id
        LEFT JOIN
    catalog_product_entity_varchar v1 ON e.entity_id = v1.entity_id
        AND v1.store_id IN (0,1,2)
        AND v1.attribute_id = @name
        LEFT JOIN
    catalog_product_entity_varchar v2 ON e.entity_id = v2.entity_id
        AND v2.store_id IN (0,1,2)
        AND v2.attribute_id = @image 
        LEFT JOIN        
    catalog_product_entity_varchar s2 ON e.`entity_id` = s2.entity_id
    AND s2.store_id IN (0,1,2)
    AND s2.`attribute_id` = @smallimage
    LEFT JOIN
    catalog_product_entity_decimal d1 ON e.entity_id = d1.entity_id
        AND d1.store_id IN (0,1,2)
        AND d1.attribute_id = @price
        LEFT JOIN
        catalog_product_entity_text s1 ON e.entity_id = s1.entity_id
       AND s1.store_id IN (0,1,2)
       AND s1.attribute_id = @description ;
1