Wie liste ich alle deaktivierten Produkte mit SQL auf?


Antworten:


25

Als Magento-Produkt folgt die EAV-Struktur der

Sie müssen eine Abfrage zwischen eav_attributeund catalog_product_entity_intTabelle schreiben

Magento speichert den Produktstatus auf dem catalog_product_entity_intTisch. Speichern Sie es als 1 und 2.

  • 1 für enable
  • 2 für deaktivieren.

Sie müssen die Statusattribut-ID mit dem Attributcode abrufen status, im Grunde ist es 96.

Abfrage:

SELECT entity_id FROM `catalog_product_entity_int`
WHERE attribute_id = (
    SELECT attribute_id FROM `eav_attribute`
    WHERE `attribute_code` LIKE 'status'
) AND `catalog_product_entity_int`.value = 2

5

Magento-Abfrage

$productsCollection = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToFilter('status', 2); // added enabled

MySQL-Abfrage

SELECT `e`.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS `status` 
FROM `catalog_product_entity` AS `e` 
INNER JOIN `catalog_product_entity_int` AS `at_status_default` 
 ON (`at_status_default`.`entity_id` = `e`.`entity_id`)
  AND (`at_status_default`.`attribute_id` = '96') 
  AND `at_status_default`.`store_id` = 0 
LEFT JOIN `catalog_product_entity_int` AS `at_status` 
 ON (`at_status`.`entity_id` = `e`.`entity_id`) 
  AND (`at_status`.`attribute_id` = '96') 
  AND (`at_status`.`store_id` = 1) 
WHERE (IF(at_status.value_id > 0, at_status.value, at_status_default.value) = '2')

0

Per Amits Post - Ich musste diese "Deaktivierten" Gegenstände finden (Wert 2). Hier ist eine aktuelle MySQL-Abfrage mit ein paar zusätzlichen Feldern, mit denen ich herausgefunden habe, welche Produkte tatsächlich "aktiviert" werden müssen.

select
  `eav_attribute`.`attribute_id` AS `attribute_id`,
  `catalog_product_entity_int`.`entity_id` AS `entity_id`,
  `catalog_product_entity_int`.`value` AS `value`,
  `eav_attribute`.`attribute_code` AS `attribute_code`,
  `catalog_product_entity`.`sku` AS `sku`,
  `catalog_product_entity`.`created_at` AS `created_at`,
  `catalog_product_entity`.`updated_at` AS `updated_at`
from
  ((`eav_attribute`
  join `catalog_product_entity_int` on ((`eav_attribute`.`attribute_id` = `catalog_product_entity_int`.`attribute_id`)))
  join `catalog_product_entity` on ((`catalog_product_entity_int`.`entity_id` = `catalog_product_entity`.`entity_id`)))
where
  ((`eav_attribute`.`attribute_code` = 'status') and
  (`catalog_product_entity_int`.`value` = 2));

2
Fabian ... Danke für die Formatierung. Viel einfacher für andere zu bedienen.
David G. Varela

0

@Amit Bera Antwort ist die beste, aber SQL-Anfrage funktioniert nicht, wenn Sie mehr als einen Attributcode mit dem Namen "Status" haben (in meinem Fall habe ich insgesamt 5 Zeilen "Status") und MySQL wird Sie zurückgeben: #1242 - Subquery returns more than 1 rowFehler.

Daher vervollständige ich die SQL-Abfrage, indem ich das Quellmodell wie folgt als 'catalog / product_status' hinzufüge:

SELECT entity_id FROM `catalog_product_entity_int`
WHERE attribute_id = (
   SELECT attribute_id FROM `eav_attribute`
   WHERE `attribute_code` LIKE 'status'
   AND `source_model` LIKE 'catalog / product_status'
) AND `catalog_product_entity_int`.value = 2
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.