1

So this is my module structure:

enter image description here

This is the content of config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Netgr_Gradd>
            <version>1.0.0</version>
        </Netgr_Gradd>
    </modules>
    <global>
        <blocks>
            <netgr_gradd>
                <class>Netgr_Gradd_Block</class>
            </netgr_gradd>
            <adminhtml>
                <rewrite>
                    <catalog_product_attribute_set_main>Netgr_Gradd_Block_Adminhtml_Addgroup</catalog_product_attribute_set_main>
                </rewrite>
            </adminhtml>
        </blocks>
        <helpers>
            <netgr_gradd>
                <class>Netgr_Gradd_Helper</class>
            </netgr_gradd>
        </helpers>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <netgr_gradd after="Mage_Adminhtml">Netgr_Gradd_Adminhtml</netgr_gradd>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

This is the content of adminhtml.xml :

<?xml version="1.0"?>
<config>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <netgr_gradd before ="Mage_Adminhtml">Netgr_Gradd_Adminhtml</netgr_gradd>
                    </modules>
                </args>
            </adminhtml>
        </routers>

    </admin>

</config>

This is the content of the Addgroup.php from my Block :

class Netgr_Gradd_Block_Adminhtml_Addgroup extends Mage_Adminhtml_Block_Catalog_Product_Attribute_Set_Main
{

    protected function _construct() {
        //This should just be a copy of catalog/product/attribute/set/main.phtml so you can edit it
        $this->setTemplate('netgr/gradd/group.phtml');
    }

    public function _prepareLayout() {
        $this->setChild('my_button',
            $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array(
                'label'     => Mage::helper('catalog')->__('Add Group'),
                'onclick'   => 'editSet.addGroupFront();',
                'class'     => 'add-group'
        )));
        return parent::_prepareLayout();
    }

    public function getYourButtonHtml() {
        return $this->getChildHtml('my_button');
    }
}

It is an extended class. and this is the content of the controllers/Adminhtml/AddgroupController.php:

<?php

class Netgr_Gradd_Adminhtml_AddgroupController extends Mage_Adminhtml_Controller_Action
{

    public function indexAction(){

    }

    public function saveAction(){
        echo 111;
    }
}

I created a template, where i actually do the ajax stuff:

 save : function() {
                        $('messages').update();
                        TreePanels.rebuildTrees();
                        var _validator = new Validation('set_prop_form', {onSubmit:false});
                        if( !_validator.validate() ) {
                            return;
                        }
                        editSet.req.attribute_set_name = $('attribute_set_name').value;
                        if (!editSet.req.form_key) {
                            editSet.req.form_key = FORM_KEY;
                        } 
                        list_of_group = "";
                        $$(".add_new_frontend_group>a>span").each( function (val,i) {
                            list_of_group = list_of_group +"^"+ val.innerHTML;
                        });
                        alert('<?php echo $this->getMoveUrl() ?>');
                        var req = {data : Ext.util.JSON.encode(editSet.req)};
                        var con = new Ext.lib.Ajax.request('POST', 'http://attin.netlogiq.eu/magento_new/index.php/admo/netgr_gradd_adminhtml_addgroup/save', {
                            success:editSet.success,
                            failure:editSet.failure
                        }, req);
                    },

This stuff is prototype js. There is smth wrong with the ajax url, it gives me the 404 page. What is wrong with my url?

  • Basically what are you trying to achieve through your module ? – Rajeev K Tomy Aug 4 '14 at 11:09
  • When i press the Save attribute set button I want to go to my function not in <?php echo $this->getMoveUrl() ?>, which was set by default – Attila Naghi Aug 4 '14 at 11:11
1

Well, the way I work Ajax in Magento/Prototype is like this:

new Ajax.Request(url, {
    method: 'post',
    parameters: object,
    onComplete: function(transport) {
        //do stuff
    }
}

where the url should be a Magento controller url, set like

<?php echo $this->getUrl('controller_name/method_name') ?>

In your case the url ought to be

$this->getUrl('netgr_gradd/addgroup/save') or $this->getUrl('addgroup/save')

You are using an URL in the ajax request, not a class name, so there are no underscores except those you put into your names yourself, and you set your router to your file directory so that you do not have your directory reflected in your urls, so adminhtml should not be in the url I think (no indepth analysis of your xml on my part).

Edit: actually it could be

$this->getUrl('adminhtml/addgroup/save')

You seem to have named your router adminhtml.

  • you saved my day, thx a lot !!!! – Attila Naghi Aug 4 '14 at 12:24

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.