Magento – How to add a saveAndContinueEdit type button in admin view order

admincontrollersmodulesales-order

I have created a module to implement a new product option type.
This product option can be configured from the admin view order page :

and for each product that has this option, I have a radio button form :

    …
<FORM id="file_state_sel" method="post">
        <INPUT type= "radio" name="<?php echo $_label;?>" value="Checking" <?php echo $_checked_verif;?>> Being verified
        <INPUT type= "radio" name="<?php echo $_label;?>" value="Files_OK" <?php echo $_checked_ok;?>> Files OK
        <INPUT type= "radio" name="<?php echo $_label;?>" value="Files_not_OK" <?php echo $_checked_notok;?>> Files not OK
</FORM>

I added in the view order page a Save Order button :

module config.xml

    <blocks>
        <custoptiontype>
            <class>Mine_Custoptiontype_Block</class>
        </custoptiontype>
        <adminhtml>
...
            <rewrite>
                <sales_order_view>Mine_Custoptiontype_Block_Adminhtml_Sales_Order_View</sales_order_view>
            </rewrite>
        </adminhtml>
    </blocks>

and the class

class Mine_Custoptiontype_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {

    public function  __construct() {
        $this->_addButton('updatebutton', array(
            'label'     => Mage::helper('Sales')->__('SAVE ORDER'),
            'onclick'   => 
            'class'     => 'scalable save'
        ), 0, 100, 'header', 'header');

        parent::__construct();

    }}

As you can see, the 'onclick' parameter stays a mystery to me… I tried hundreds of things, but none of them worked…

The goal is to make a a saveAndContinueEdit type function :
– get the radio button configuration
– update the options values
– save the order
– reload the order view page

I tried making a module controller, with no success :

in the config.xml

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <mine_custoptiontype after="Mage_Adminhtml">Mine_Custoptiontype_Adminhtml</mine_custoptiontype>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

with

<?php
class Mine_Custoptiontype_Adminhtml_FilesstateController extends Mage_Adminhtml_Controller_Action
{
    public function updateAction()
    {
        echo "ca va updater!";
    }    
}
?>

but I do not manage to call it properly…

I you could help me please, I am getting mad…

Thanks very much,

Alex

Best Answer

partial answer

I manage to call my module controller via the button :

the controller class became :

class Mine_Custoptiontype_FilesstateController extends Mage_Adminhtml_Controller_Action
{
    public function updateAction()
    {   
        echo "ca va updater!";
    }    
}

the class instanciation in config.xml

...
 </global>

      <admin>
        <routers>
            <mine_custoptiontype>
                <use>admin</use>
                <args>
                    <module>Mine_Custoptiontype</module>
                    <frontName>custoptiontype</frontName>
                </args>
            </mine_custoptiontype>
        </routers>
    </admin>
</config>

and the button :

class Mine_Custoptiontype_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View {

    public function  __construct() {
        $this->_addButton('updatebutton', array(
            'label'     => Mage::helper('adminhtml')->__('SAVE ORDER'),
            'onclick'   => 'setLocation(\''.Mage::helper("adminhtml")->getUrl("custoptiontype/filesstate/update").'\')',
            'class'     => 'scalable save'
        ), 0, 100, 'header', 'header');

        parent::__construct();
    }

Now I need to post the radio input value and update the order… I am still surching for a solution. I read several posts on form submission using something like

$this->_addButton('save_and_continue', array(
             'label' => Mage::helper('blog')->__('Save And Continue Edit'),
             'onclick' => 'saveAndContinueEdit()',
             'class' => 'save' 
         ), -100);
         $this->_formScripts[] = "
             function saveAndContinueEdit(){
                editForm.submit($('edit_form').action + 'back/edit/');
             }
             ";

but I am not even sure I declared my input radio button correctly… As they are used as a product option configuration, maybe I should have used something like :

<input type="radio" class="input-text" name="product[options][{{option_id}}][label]" value="Checking">
<input type="radio" class="input-text" name="product[options][{{option_id}}][label]" value="Files_OK"></td>
<input type="radio" class="input-text" name="product[options][{{option_id}}][label]" value="Files_not_OK">

I would really appreciate any help please...

Related Topic