Magento和OR查询

时间:2015-02-02 13:06:20

标签: magento

我们有两个属性check_in_stock和show_in_front。我想要magento等效查询: where (check_in_stock > 0 OR (check_in_stock=0 and show_in_front=1))

请帮我找到等效的magento查询

2 个答案:

答案 0 :(得分:1)

您可以使用以下SQL查询:

Mage::getModel("catalog/product")->getCollection()->getSelect()->where('check_in_stock > 0 OR (check_in_stock=0 and show_in_front=1)')

这将创建一个sql输出,如:

"SELECT `e`.* FROM `catalog_product_entity` AS `e` WHERE (check_in_stock > 0 OR (check_in_stock=0 and show_in_front=1))"

答案 1 :(得分:0)

来自Itera Research的问候,

我很高兴分享我们Magento团队负责人的回复,请查看以下内容:

"首先,您需要查找可见性和状态属性ID

attribute_id中选择eav_attribute attribute_code =' visibility';

在我的情况下,它返回102

attribute_id选择eav_attribute attribute_code =' status';

在我的情况下,它返回96

并将这些ID替换为以下查询

SELECT e。*,at_qtyqtyat_statusvalue AS statusat_visibility。{{ 1}} AS value FROM visibility AS catalog_product_entity  LEFT JOIN e AS cataloginventory_stock_item ON(at_qty。at_qty = e.entity_id)AND(at_qty.stock_id = 1)  INNER JOIN product_id AS catalog_product_entity_int ON(at_statusat_status = entity_ide)AND(entity_id。{{1 }} =' 96')AND(at_statusattribute_id = 0)  INNER JOIN at_status AS store_id ON(catalog_product_entity_intat_visibility = at_visibilityentity_id)AND(e。{{1 }} =' 102')AND(entity_idat_visibility = 0)  内部联接attribute_idat_visibility store_idcataloginventory_stock_status = ssss)  其中product_ide = 1和entity_idat_visibility = 1

希望这有帮助,

如果没有,请给我发消息,

Jen Zorina

Itera研究