1

我希望直接在 Magento 数据库上编写一个 SQL 查询,以获取所有具有“单独不可见”可见性属性的简单产品,我相信其值为 1。

有人能帮忙吗?到目前为止,我发现表中设置了可见性值

catalog_product_entity_int

但一直无法进一步进步。谢谢

4

2 回答 2

4

没有 ORM有很多理由这样做,所有这些都可能(或可能不)适用于您的需求(存储过滤器、从正确的表中读取数据等)。至少,您可以使用产品集合对象来构建您将运行的查询:

$coll = Mage::getModel('catalog/product')->getCollection();
$coll->addAttributeToFilter('visibility' , Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE);
echo $coll->getSelect();

结果查询将如下所示:

SELECT `e`.*, IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) AS `visibility`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_product_entity_int` AS `at_visibility_default`
    ON (`at_visibility_default`.`entity_id` = `e`.`entity_id`)
    AND (`at_visibility_default`.`attribute_id` = '526')
    AND `at_visibility_default`.`store_id` = 0
LEFT JOIN `catalog_product_entity_int` AS `at_visibility` ON (`at_visibility`.`entity_id` = `e`.`entity_id`)
    AND (`at_visibility`.`attribute_id` = '526')
    AND (`at_visibility`.`store_id` = 1)
WHERE (IF(at_visibility.value_id > 0, at_visibility.value, at_visibility_default.value) = '1')
于 2012-12-13T15:50:05.683 回答
1

我希望这可能未经测试。

$sql = "SELECT * FROM catalog_product_entity_int WHERE visibility=1";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
foreach ($connection->fetchAll($sql) as $arraytest) {
    echo $arraytest['name'];
}
于 2012-12-13T14:56:30.347 回答