2

I want to alter the message of delete confirm in custom extension and I don't know how. Someone can help me?

enter image description here

DutyController.php

class Nothing_Duty_Adminhtml_DutyController extends Mage_Adminhtml_Controller_Action
{

    protected function _initAction()
    {
        $this->loadLayout()->_setActiveMenu("duty/duty")->_addBreadcrumb(Mage::helper("adminhtml")->__("Duty  Manager"),Mage::helper("adminhtml")->__("Duty Manager"));
        return $this;
    }


    public function indexAction() 
    {
        $this->_title($this->__("Duty"));
        $this->_title($this->__("Teste Criação de Grid"));

        $this->_initAction();
        $this->renderLayout();
    }


    public function editAction()
    {               
        $this->_title($this->__("Editar Item"));

        $id = $this->getRequest()->getParam("id");
        $model = Mage::getModel("duty/cake")->load($id);
        if ($model->getId()) {
            Mage::register("duty_data", $model);
            $this->loadLayout();
            $this->_setActiveMenu("duty/duty");
            $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Duty Manager"), Mage::helper("adminhtml")->__("Duty Manager"));
            $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Duty Description"), Mage::helper("adminhtml")->__("Duty Description"));
            $this->getLayout()->getBlock("head")->setCanLoadExtJs(true);
            $this->_addContent($this->getLayout()->createBlock("duty/adminhtml_duty_edit"))->_addLeft($this->getLayout()->createBlock("duty/adminhtml_duty_edit_tabs"));
            $this->renderLayout();
        } 
        else {
            Mage::getSingleton("adminhtml/session")->addError(Mage::helper("duty")->__("Item does not exist."));
            $this->_redirect("*/*/");
        }
    }

    public function newAction()
    {
        $this->_title($this->__("Novo item"));

        $id   = $this->getRequest()->getParam("id");
        $model  = Mage::getModel("duty/cake")->load($id);

        $data = Mage::getSingleton("adminhtml/session")->getFormData(true);
        if (!empty($data)) {
            $model->setData($data);
        }

        Mage::register("duty_data", $model);

        $this->loadLayout();
        $this->_setActiveMenu("duty/duty");

        $this->getLayout()->getBlock("head")->setCanLoadExtJs(true);

        $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Duty Manager"), Mage::helper("adminhtml")->__("Duty Manager"));
        $this->_addBreadcrumb(Mage::helper("adminhtml")->__("Duty Description"), Mage::helper("adminhtml")->__("Duty Description"));


        $this->_addContent($this->getLayout()->createBlock("duty/adminhtml_duty_edit"))->_addLeft($this->getLayout()->createBlock("duty/adminhtml_duty_edit_tabs"));

        $this->renderLayout();

    }

    public function saveAction()
    {

        $post_data=$this->getRequest()->getPost();


        if ($post_data) {

            try {   

                $model = Mage::getModel("duty/cake")
                ->addData($post_data)
                ->setId($this->getRequest()->getParam("id"))
                ->save();

                Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("O item foi salvo com sucesso!"));
                Mage::getSingleton("adminhtml/session")->setDutyData(false);

                if ($this->getRequest()->getParam("back")) {
                    $this->_redirect("*/*/edit", array("id" => $model->getId()));
                    return;
                }

                $this->_redirect("*/*/");
                return;
            } 
            catch (Exception $e) {
                Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
                Mage::getSingleton("adminhtml/session")->setDutyData($this->getRequest()->getPost());
                $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
                return;
            }

        }
        $this->_redirect("*/*/");
    }



    public function deleteAction()
    {
        if( $this->getRequest()->getParam("id") > 0 ) {
            try {
                $model = Mage::getModel("duty/cake");
                $model->setId($this->getRequest()->getParam("id"))->delete();
                Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Item foi deletado com sucesso!"));
                $this->_redirect("*/*/");
            } 
            catch (Exception $e) {
                Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
                $this->_redirect("*/*/delete", array("id" => $this->getRequest()->getParam("id")));
            }
        }
        $this->_redirect("*/*/");
    }


    public function massRemoveAction()
    {
        try {
            $ids = $this->getRequest()->getPost('codigos', array());
            foreach ($ids as $id) {
                $model = Mage::getModel("duty/cake");
                $model->setId($id)->delete();
            }
            Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("Item removido com sucesso!"));
        }
        catch (Exception $e) {
            Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
        }
        $this->_redirect('*/*/');
    }


    public function exportCsvAction()
    {
        $fileName   = 'arquivocsv.csv';
        $grid       = $this->getLayout()->createBlock('duty/adminhtml_duty_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
    } 


    public function exportExcelAction()
    {
        $fileName   = 'arquivoxml.xml';
        $grid       = $this->getLayout()->createBlock('duty/adminhtml_duty_grid');
        $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
    }
}

Edit.php

class Nothing_Duty_Block_Adminhtml_Duty_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {

        parent::__construct();
        $this->_objectId = "codigo";
        $this->_blockGroup = "duty";
        $this->_controller = "adminhtml_duty";
        $this->_updateButton("save", "label", Mage::helper("duty")->__("Salvar Item"));
        $this->_updateButton("delete", "label", Mage::helper("duty")->__("Deletar Item"));

        $this->_addButton("saveandcontinue", array(
            "label"     => Mage::helper("duty")->__("Salvar e Continuar a Editar"),
            "onclick"   => "saveAndContinueEdit()",
            "class"     => "save",
        ), -100);



        $this->_formScripts[] = "

        function saveAndContinueEdit(){
            editForm.submit($('edit_form').action+'back/edit/');
        }
        ";
    }

    public function getHeaderText()
    {
        if( Mage::registry("duty_data") && Mage::registry("duty_data")->getId() ){

            return Mage::helper("duty")->__("Editar Item '%s'", $this->htmlEscape(Mage::registry("duty_data")->getId()));

        } 
        else{

            return Mage::helper("duty")->__("Adicionar");

        }
    }
}

ps: The function of this button is DeleteAction

  • buttons are defined in Edit.php file which extends class Mage_Adminhtml_Block_Widget_Form_Container , check that file – Piyush Apr 2 '18 at 13:21
  • I updated the question. I tried changing the Edit.php, but what I tried does not work – Andressa Rodrigues Apr 2 '18 at 13:27
3

Add the following, just below parent::__construct();, in Nothing_Duty_Block_Adminhtml_Duty_Edit::__construct():

$objId = $this->getRequest()->getParam($this->_objectId);

if (! empty($objId)) {
    $this->_updateButton('delete', null, array(
        'label'     => Mage::helper('adminhtml')->__('Delete'),
        'class'     => 'delete',
        'onclick'   => 'deleteConfirm(\''
            . Mage::helper('core')->jsQuoteEscape(
                Mage::helper('adminhtml')->__('Are you sure you want to do this?')
            )
            .'\', \''
            . $this->getDeleteUrl()
            . '\')',
    ));
}

Then, you can edit the "Are you sure..." string.

  • 1
    That's exactly what I wanted. Worked perfectly! Thank you very much! – Andressa Rodrigues Apr 2 '18 at 13: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.