如何使用sql列出所有禁用的产品?


Answers:


25

作为magento产品的EAV结构

您需要在和表之间编写查询eav_attributecatalog_product_entity_int

Magento将产品状态保存在表表catalog_product_entity_int中。将其另存为1和2。

  • 1启用
  • 2表示禁用。

您需要使用属性代码获取状态属性id status,基本上是96。

查询:

从`catalog_product_entity_int`中选择Entity_id
在哪里attribute_id =(
    从`eav_attribute`中选择attribute_id
    在`attribute_code`类似'status'的情况下
)AND`catalog_product_entity_int`.value = 2

5

Magento查询

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

MySQL查询

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-我需要找到那些“ Disabled”项目(值2)。这是当前的mysql查询,其中包含一些额外的字段,我曾用它们来麻烦一下实际需要“启用”哪些产品

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 ...感谢您的格式化。其他人使用起来容易得多。
David G. Varela,

0

@Amit Bera的答案是最好的,但是如果您有多个名为“ status”的属性代码(在我的情况下,我总共有5行“ status”),则SQL请求不起作用,MySQL将返回您:#1242 - Subquery returns more than 1 row错误。

因此,我通过将source_model添加为“ catalog / product_status”来完成SQL查询,如下所示:

从`catalog_product_entity_int`中选择Entity_id
在哪里attribute_id =(
   从`eav_attribute`中选择attribute_id
   在`attribute_code`类似'status'的情况下
   AND`source_model`就像'catalog / product_status'
)AND`catalog_product_entity_int`.value = 2
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.