我们有两个属性check_in_stock和show_in_front。我想要magento等效查询:
where (check_in_stock > 0 OR (check_in_stock=0 and show_in_front=1))
。
请帮我找到等效的magento查询
答案 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_qty
。qty
,at_status
。value
AS status
,at_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_status
。at_status
= entity_id
。e
)AND(entity_id
。{{1 }} =' 96')AND(at_status
。attribute_id
= 0)
INNER JOIN at_status
AS store_id
ON(catalog_product_entity_int
。at_visibility
= at_visibility
。entity_id
)AND(e
。{{1 }} =' 102')AND(entity_id
。at_visibility
= 0)
内部联接attribute_id
为at_visibility
store_id
。cataloginventory_stock_status
= ss
。ss
)
其中product_id
。e
= 1和entity_id
。at_visibility
= 1
希望这有帮助,
如果没有,请给我发消息,
Jen Zorina
Itera研究