0

Some of my forms submit via AJAX and reload the page on complete. I have the $this->_initLayoutMessages(‘core/session’); line in my controller when the page loads, but the success/error messages never appear on my form page. They appear throughout the rest of the site – the home page, customer account pages, etc. Any ideas on what I’m missing that might allow them to appear on the page itself? I have a call to global messages in the template of the page that I am using as well...

Page is located at /marketplacepolicies/marketplaceaccount/editpolicies/

Here is the controller for the page:

    public function editpoliciesAction(){
$this->loadLayout( array('default','marketplacepolicies_marketplaceaccount_editpolicies'));
            $this->_initLayoutMessages('customer/session');
            $this->_initLayoutMessages('catalog/session');
            $this->getLayout()->getBlock('head')->setTitle( Mage::helper('marketplace')->__('Seller Policies'));
            $this->renderLayout();
    }

and the form submit action:

public function saveAction(){

            $wholedata=$this->getRequest()->getParams();

            if(!(empty($wholedata['info']))){
            $data = json_decode($wholedata['info'], true);

            $partnerid=Mage::getSingleton('customer/session')->getCustomer()->getId();

            foreach($data as $set){
                if (is_null($set[0])){
                    $policies=Mage::getModel('zerobars_marketplacepolicies/marketplacepolicies');
                    $policies->setData('policy_title', $set[1]);
                    $policies->setData('policy_details', $set[2]);
                    $policies->setData('partner_id', $partnerid);
                    $policies->save();
                }
                else {
                    $collection=Mage::getModel('zerobars_marketplacepolicies/marketplacepolicies')->getCollection()
                            ->addFieldToFilter('policy_id',array('eq'=>$set[0]))
                            ->addFieldToFilter('partner_id',array('eq'=>$partnerid));
                    if(count($collection)>0){
                        foreach($collection as $c){
                            $c->setData('policy_title', $set[1]);
                            $c->setData('policy_details', $set[2]);
                            $c->save();
                        }
                    }
                }
            }

        $this->_getSession()
                ->addSuccess('Your new policies have been saved.');
        $this->_redirectUrl('marketplacepolicies/marketplaceaccount/editpolicies', array('_secure' => true));

        }
    }

In response to alex_b - here is what is in my _getsession after I delete a policy:

Mage_Customer_Model_Session Object ( [_customer:protected] => [_isCustomerIdChecked:protected] => 1 [_persistentCustomerGroupId:protected] => [_skipSessionIdFlag:protected] => [_data:protected] => Array ( [_session_validator_data] => Array ( [remote_addr] =>  [http_via] => [http_x_forwarded_for] => [http_user_agent] => Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36 ) [session_hosts] => Array ( [dev.zero-bars.com] => 1 ) [messages] => Mage_Core_Model_Message_Collection Object ( [_messages:protected] => Array ( ) [_lastAddedMessage:protected] => Mage_Core_Model_Message_Success Object ( [_type:protected] => success [_code:protected] => The policy has been deleted. [_class:protected] => [_method:protected] => [_identifier:protected] => [_isSticky:protected] => ) ) [customer_id] => [customer_group_id] => [id] => 6 [wishlist_display_type] => 0 [display_out_of_stock_products] => 1 [wishlist_item_count] => 0 ) [_hasDataChanges:protected] => 1 [_origData:protected] => [_idFieldName:protected] => [_isDeleted:protected] => [_oldFieldsMap:protected] => Array ( ) [_syncFieldsMap:protected] => Array ( ) )
  • Show how you add these messages and also show your controller method for page where messages should be shown – alex_b Oct 29 '14 at 22:36
  • Added code for both – KRay Oct 30 '14 at 18:30
  • What do you have in _getSession? – alex_b Oct 30 '14 at 18:59
  • Not sure - how can I tell? – KRay Oct 30 '14 at 20:16
  • That method should be implemented in controller class – alex_b Oct 31 '14 at 10:13
0

Added the following line to my .phtml file and it is working now.

<?php echo $this->getMessagesBlock()->getGroupedHtml(); ?>
| improve this answer | |

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.