Get Product with the filter using OR operator
In Magento,
I want to get the product withname
attribute is Product开发者_运维技巧 1
*OR* Product 2
$product = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('name','Product 1')
->setPageSize(1)
->load()
->getFirstItem();
//OR
if( !$product->getId() )
{
$product = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('name','Product 2')
->setPageSize(1)
->load()
->getFirstItem();
}
How can I just using one statement to do?
refer to this article http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-8-varien-data-collections in magento knowledgeBase
精彩评论