0

I want to get specific percentage (i.e 5%) discount all products. how can I get the products?

I am using Magento 1.7.0.2 and trying with below code for all selected products:

    $_pro_collection = Mage::getModel('catalog/product')->getCollection();
    $_pro_collection->getSelect()->order('(price_index.final_price / price_index.price)', 'DESC');

Your help will be appreciated. Thanks in advanced.

0

You can use below code:

$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToFilter('special_price', array('gt' => 0));
$collection->addAttributeToFilter('price', array('gt' => 0));
$collection->addAttributeToFilter('special_price', array('eq' => new Zend_Db_Expr('`at_price`.`value`*0.95')));

/** for FLAT CATALOG use this line
$collection->addAttributeToFilter('special_price', array('eq' => new Zend_Db_Expr('e.price*0.95')));
**/

/**
ADD EXTRA FILTER HERE
**/

Adding From and To Date Filters

$date = strtotime(date('Y-m-d')); 
$current_date = date("Y-m-d hh:mm:ss",$date);
$collection= $specialcollection->addAttributeToFilter(array(
    array('attribute'=>'special_from_date','lteq'=>$current_date),
    array('attribute'=>'special_from_date','eq'=>''),
    array('attribute'=>'special_from_date','null'=>true)
),'','left')
->addAttributeToFilter(array(
    array('attribute'=>'special_to_date','gteq'=>$current_date),
    array('attribute'=>'special_to_date','eq'=>''),
    array('attribute'=>'special_to_date','null'=>true)
),'','left');
  • I am using version 1.7.0.2. Above code is not working in my setup. In which version you checked? – Benzir Hasan May 4 '16 at 6:54
  • Checked in 1702 also and it's working, What's an error you are getting ? – Anil Suthar May 4 '16 at 7:02
  • SQLSTATE[42S22]: Column not found: 1054 Unknown column 'at_price.value' in 'where clause' – Benzir Hasan May 4 '16 at 7:04
  • do echo $collection->getSelect() after this line $collection->addAttributeToFilter('special_price', array('eq' => new Zend_Db_Expr('at_price.value*0.95'))); and show here – Anil Suthar May 4 '16 at 7:05
  • SELECT 1 AS status, e.entity_id, e.type_id, e.attribute_set_id, e.special_price, e.price FROM catalog_product_flat_1 AS e WHERE (e.special_price > 0) AND (e.price > 0) AND (e.special_price = at_price.value*0.95) – Benzir Hasan May 4 '16 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.