magento使用属性值选择SKU

时间:2012-05-03 12:28:29

标签: mysql magento

enter image description here

  

我需要选择SKU,其中partno = MEM1600-2U6D,brandname = Cisco   和条件=新

任何人都可以为我提供解决方案。

2 个答案:

答案 0 :(得分:2)

$collection = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter(array(
    array('attribute'=>'partno','eq'=>'MEM1600-2U6D'),
))
->addFieldToFilter(array(
    array('attribute'=>'brandname','eq'=>'Cisco'),
))
->addFieldToFilter(array(
    array('attribute'=>'condition','eq'=>'New'),
))

我不确定。此外,您可以尝试使用UNION来实现目标。

好吧,我会尝试一下这个:

SELECT sku 
FROM catalog_product_entity 
WHERE 
entity_id in (
     SELECT entity_id from catalog_product_entity_varchar WHERE attribute_id = (SELECT attribute_id from eav_attribute WHERE name='Partno' LIMIT 1) AND value = 'MEM1600-2U6D'
     UNION
     SELECT entity_id from catalog_product_entity_varchar WHERE attribute_id = (SELECT attribute_id from eav_attribute WHERE name='brandname' LIMIT 1) AND value = 'Cisco'
     UNION
     SELECT entity_id from catalog_product_entity_varchar WHERE attribute_id = (SELECT attribute_id from eav_attribute WHERE name='Condition' LIMIT 1) AND value = 'new'
)

嗯,你可能

 GROUP by entity_id HAVING COUNT(*) = 3
像这样的事情。这意味着如果我们对entity_id有3个entriies,那就意味着它会影响我们的情况。

答案 1 :(得分:0)

条件栏在哪里?

编辑:N / m,我刚看到。您无法使用该表设置执行此操作。条件/品牌必须是单独的列或表,而不是值。使用值列中的条件,它有自己的SKU,因此您有2个SKU,一个用于产品,另一个用于条件。

相关问题