开发者

Get Product with the filter using OR operator

开发者 https://www.devze.com 2023-04-10 10:51 出处:网络
In Magento, I want to get the product with name attribute is Product开发者_运维技巧 1 *OR* Product 2

In Magento,

I want to get the product with name 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

0

精彩评论

暂无评论...
验证码 换一张
取 消