0

I have this custom module which allows mass status update from admin grid. There is a field of stores as well. So when i update the status, it works fine the status gets changed but the store views all change to "All store views" instead of their previous custom stores applied to each row of data. here is my mass status change function in the controller:

 public function massStatusAction() {
    $testimonialIds = $this->getRequest()->getParam('testimonial');
    if(!is_array($testimonialIds)) {
        Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
    } else {
        try {
            foreach ($testimonialIds as $testimonialId) {
                $current_status= $this->_getTestimonial()->load($testimonialId)->getStatus();
                $updated_status= $this->getRequest()->getParam('status');
                if ((Mage::getStoreConfig('testimonial/email_configuration/send_email_after_approve_testimonial', Mage::app()->getStore())=="1")and ($current_status=="3" and $updated_status=="1") ) {
                    $to = array('email'=>$this->_getTestimonial()->load($testimonialId)->getEmail(), 'name'=>$this->_getTestimonial()->load($testimonialId)->getName());
                    $this->sendemailAction($to, $templateConfigPath=self::XML_PATH_EMAIL_SELECT_TEMPLATE_AFTER_APPROVE,$testimonialId);
                    Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Admin has just sent the email to customer for approving their testimonials'));
                }

                $testimonial = Mage::getModel('testimonial/testimonial')->load($testimonialId);
                $testimonial                         
                    ->setStatus($this->getRequest()->getParam('status'))
                    ->setStores('')
                    ->setIsMassupdate(true)
                    ->save();
            }
            $this->_getSession()->addSuccess(
                $this->__('Total of %d record(s) were successfully updated', count($testimonialIds))
            );
        }catch (Exception $e) {
            $this->_getSession()->addError($e->getMessage());
        }
    }
    $this->_redirect('*/*/index');
}

Can you please guide me where I am going wrong?

1

This is wrong: ->setStores(''). You set the stores to nothing. And I assume that if the stores are empty, your testimonials are by default available for all stores.
I strongly recommend you to give this a try: Ultimate Module Creator. It will build you extension as you need, including a way to display your entities (testimonials in your case) on what stores you desire. It also includes a 'mass action' feature for changing the status. The only think you need to add by yourself is the email sending.

  • I hope this is not considered as 'self promotion', because the extension is free and I get no financial benefits from it. If someone thinks otherwise, please edit my answer and I promise not to recommend it anymore on this website. – Marius Jul 10 '13 at 7:05
  • I don't think it's self promotion. In fact i have used it before. Thanks for creating it. But i have already created this module and just want to fix this error. I removed the store setting to nothing but still same thing. Also one odd behavior is that when select mass action only first selected item gets changed and the remaining stays the same. I have compared my code to other modules that work and it's the same. – jdhaar Jul 10 '13 at 8:47
  • if the error persists, then you have to take a look on how the testimonial looks after calling '->load()'. In order to save properly it should already have the stores referenced in a member variable. I suggest to take a look on how the cms pages work when calling ->load on them and do something similar. – Marius Jul 10 '13 at 8:52

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.