Magento Product Collection Less Than the Original Price

magento-1.9product-collectionspecial-price

How to get Special price less or not

  <?php 

$categoryIds = array(469);//category id

$todayDate = date('m/d/y');
        $tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
        $tomorrowDate = date('m/d/y', $tomorrow);

$collection = Mage::getModel('catalog/product')
                             ->getCollection()
                             ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
                             ->addMinimalPrice()->addFinalPrice()
                             ->addAttributeToSelect('*')
                             ->addAttributeToFilter('category_id', array('in' => $categoryIds))
                             ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))

                             ->addFinalPrice()

                   ->getSelect()
                   ->where('price_index.final_price < price_index.price')


                             ->addAttributeToFilter('special_to_date', array('or'=> array(
                                0 => array('date' => true, 'from' => $tomorrowDate))
                                ), 'left')




?>

I want to display if special price less then the original price how to get that ?

Best Answer

    $categoryIds = array(469);//category id



    $products = Mage::getResourceModel('catalog/product_collection')

->addCategoryFilter(Mage::getModel('catalog/category')->load($categoryIds));
$_productCollection = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('in' => $products->getAllIds()));;
$_productCollection->addAttributeToSelect(array(
                                   'image',
                                   'name',
                                   'short_description'
                   ))
                   ->addFieldToFilter('visibility', array(
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                               Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                   )) 
                   ->addFinalPrice()

                   ->getSelect()
                   ->where('price_index.final_price < price_index.price')


                   print_r($_productCollection->getAllIds());
Related Topic