0

I try to get a collection of Mage::getModel('catalogrule/rule') but when I do Mage::getModel('catalogrule/rule')->getCollection() I have an error because can't call a function of boolean.

I do a if:

if(Mage::getModel('catalogrule/rule')) echo "hello"; else echo "no";

Always say "no".

2
  • check my answer and tell me what you get?
    – Divyesh
    May 11, 2018 at 8:20
  • I get nothing, empty value
    – str_lml
    May 11, 2018 at 8:25

3 Answers 3

0

Use below code:

$rules = Mage::getModel('catalogrule/rule')->getCollection()->addFieldToFilter('is_active', 1);

if($rules): 
    echo "hello"; 
else: 
    echo "no";
endif;
1
  • i get this: Call to a member function getCollection() on boolean
    – str_lml
    May 11, 2018 at 8:26
0

Working code:

$catalogrules = Mage::getModel('catalogrule/rule')->getCollection()->addFieldToFilter('is_active', 1);

foreach($catalogrules as $rule){
    echo '<pre>'; 
    print_r($rule->getData());
    echo '</pre>';
}

if(count($catalogrules)>0){
   echo "hello"; 
}
else{
   echo "no"; 
}

You will get all active catalogPrice rules with rules data.

0

First, try have you got class?

 echo get_class(Mage::getModel('catalogrule/rule'));die;

if you got empty value your module is inactive.

Please, active your Module:-

app/etc/modules/Mage_All.xml

is your module

Mage_CatalogRule

is <active>true</active> ?

OR

System > Configuration > Advanced > Disable modules output

Check your module is active?

9
  • I can't call the method getCollection because when I call to Mage::getModel('catalogrule/rule') return false.
    – str_lml
    May 11, 2018 at 8:07
  • But is a core module no?. How can i active this module?
    – str_lml
    May 11, 2018 at 8:31
  • i just update my answer, please check @str_lml
    – Divyesh
    May 11, 2018 at 8:37
  • Yes, I have all modules active. I have 3 environments, Production, Quality and Local. In production and local i can use Mage::getModel('catalogrule/rule') but in Quality i can't
    – str_lml
    May 11, 2018 at 9:05
  • Yes, I have in the file Mage_All.xml the Mage_CatalogRule active
    – str_lml
    May 11, 2018 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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