1

"PHP message: PHP Fatal error: Uncaught TypeError: Argument 2 passed to Mage::dispatchEvent() must be of the type array, object given, called in TestimonialController.php on line 26"

I am facing above error, i have upgraded my php version to 7.1 with magento 9.1.0

here is my function

/*TestimonialController.php starts*/
public function editAction()
{
    $this->_title($this->__("Testimonials"));
    $this->_title($this->__("Testimonial"));
    $this->_title($this->__("Edit Item"));
    $id = $this->getRequest()->getParam("id");
    $model = Mage::getModel("testimonials/testimonial")->load($id);
    Mage::dispatchEvent('testimonial_save_before', $model);//Line No.->26

    if ($model->getId()) {
        Mage::register("testimonial_data", $model);
        $this->loadLayout();
        $this->_setActiveMenu("testimonials/testimonial");
        $this->_addBreadcrumb(Mage::helper("adminhtml")->__('Testimonial Manager"), Mage::helper("adminhtml")->__("Testimonial Manager"));
        $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Testimonial Description"), Mage::helper("adminhtml")->__("Testimonial Description"));
        $this->getLayout()->getBlock("head")->setCanLoadExtJs(true);
        $this->_addContent($this->getLayout()->createBlock("testimonials/adminhtml_testimonial_edit"))->_addLeft($this->getLayout()->createBlock("testimonials/adminhtml_testimonial_edit_tabs"));
        $this->renderLayout();
    }
    else {
        Mage::getSingleton("adminhtml/session")->addError(Mage::helper("testimonials")->__("Item does not exist."));
        $this->_redirect("*/*/");
    }
}
/*TestimonialController.php starts*/ 





/*Observer.php starts*/

class Ravi_Testimonials_Model_Observer extends Mage_Core_Model_Abstract
{

const COUPON_ACTIVE = 'testimonial/couponcode/activecoupon';   
public function testimonialSaveBefore($observer){


    //echo $observer->getEvent()->getData()->getId();

    //echo $observer->getEvent()->getData()->getStatus();



    $tId = $observer->getEvent()->getData()->getId(); //line 33
    Mage::getSingleton('core/session')->setTid($tId);
    Mage::getSingleton('core/session')->setSt($observer->getEvent()->getData()->getStatus());


}



public function testimonialSaveAfter($observer){


$testimonialId = Mage::getSingleton('core/session')->getTid();
$status = Mage::getSingleton('core/session')->getSt();


if($status == 0 && $observer->getStatus() == 0){

    return;

}

if($status == 0 && $observer->getStatus() == 1){

    return;

}

if($status == 1 && $observer->getStatus() == 0){

//If status goes from disable to enable, notify customer via email. Write codd for send emails.
//return;
if(Mage::getStoreConfig(self::COUPON_ACTIVE) == 1){
Mage::helper('testimonials')->sendCustomerNotificationEmail($testimonialId);
}else{

    return;
}

}


}
}
/*Observer.php ends*/

1 Answer 1

1

This line

Mage::dispatchEvent('testimonial_save_before', $model);

Should be

Mage::dispatchEvent('testimonial_save_before', array('testimonial' => $model));

And you need to modify the observer also.
Make the method testimonialSaveBefore look like this:

public function testimonialSaveBefore($observer)
{
    $testimonial = $observer->getEvent()->getTestimonial();
    $tId = $testimonial->getId(); 
    Mage::getSingleton('core/session')->setTid($tId);
    Mage::getSingleton('core/session')->setSt($testimonial->getStatus());
}

But, the way you have your code right now, the testimonial id will always be null, because there is no id allocated to the testimonial before it is saved in the database.

9
  • I have tried that but, now getting following error. "PHP message: PHP Fatal error: Uncaught Error: Call to a member function getId() on array in Observer.php"
    – Suyog
    Commented Dec 7, 2016 at 13:53
  • Then add the observer code to your question
    – Marius
    Commented Dec 7, 2016 at 13:54
  • please check, i have added
    – Suyog
    Commented Dec 7, 2016 at 14:03
  • It's showing issue with line 33.
    – Suyog
    Commented Dec 7, 2016 at 14:06
  • 1
    I've updated my answer with my last try.
    – Marius
    Commented Dec 7, 2016 at 14:25

Your Answer

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

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