Questions tagged [controllers]

Denotes questions about controllers and action methods

Filter by
Sorted by
Tagged with
19 votes
3 answers
16k views

Magento 2: rewrite controller

how can i rewrite a controller (that's actually an action) in Magento 2? I tried, as instructed here like this: I have my own module called Namespace_Module with a di.xml file, that is taken into ...
  • 196k
12 votes
1 answer
47k views

How to make a simple ajax call in Magento 2.1.0

I have added a simple button in one of my phtml file. <input type='button' name='emq_zip_btn' class='emq_zip_btn' value='Go'> I have added one custom js file ("emq.js") from a custom module (...
  • 837
7 votes
3 answers
32k views

Magento 2 - Send form data to Controller using AJAX and return Result to PHTML

I am working on a simple custom module, where user can input height and the weight/BMI will be shown as output on form submit. The page where user enters input is Calculation Page while output is ...
12 votes
1 answer
18k views

How to override the controller AccountController

I need to override a method Controller Core/Mage/Customer/controllers/AccountController.php and add a new method. Since this controller to edit is wrong - it should be overridden. According to ...
12 votes
4 answers
21k views

Magento2 - Custom Controller throws error

I created a module shown in this post. But my own controller doesn't work. I've got this error message: Recoverable Error: Argument 1 passed to MP\MyModule\Controller\Index\CheckUserName::...
  • 1,763
34 votes
5 answers
50k views

Magento 2: How to get controller, module, action and router name?

Magento 2: How to get controller, module, action and router name?
  • 1,180
7 votes
2 answers
15k views

How to call a controller action outside magento?

We can create php scripts which runs outside magento. And also use magento functionalities by using the following code snippet in it. define('ROOT', ''); $mage_php_url = ROOT.'app/Mage.php'; ...
  • 9,857
5 votes
3 answers
12k views

Trying to override a controller

I am trying to override a Mage controller which is in Mage/Catalog/controllers/CategoryController.php. The folder structure which I created in trying to override the above controller is as follows: -...
  • 1,585
7 votes
2 answers
17k views

Override a controller in Adminhtml

Currently I'm trying to override the GroupController of Mage_Adminhtml_Customer so I can add some code for saving my custom field in the Customer Groups menu. As you can think it doesn't really work ...
  • 135
1 vote
1 answer
871 views

How to change Wishlist button color once product added to Wishlist using controller

How to change the wishlist button color once the products added to the wishlist.I am getting an error while using a controller. Ref: 1)https://magento.stackexchange.com/a/256570/57334 2)https://...
  • 105
8 votes
2 answers
8k views

Magento 1 : how to override/rewrite a core controller class?

Note: This is intended as a canonical question that fully explains how controller rewrites work and can be used as duplicate target for more specific "How do I override controller X" or "Why does my ...
18 votes
5 answers
57k views

How to get media directory path in a phtml file in magento 2?

Used the below method in order to get the media directory path, but it returns an error. $om = \Magento\Core\Model\ObjectManager::getInstance(); $directoryList = $om->get(\Magento\App\Filesystem\...
  • 1,752
7 votes
3 answers
37k views

Magento2 - How to get JSON response from Controller [closed]

I've created my custom controller and I want to return the result formated with JSON. I always get a JSON parse error "JSON.parse: unexpected character at line 1 column 1 of the JSON data" and the ...
  • 1,763
7 votes
2 answers
8k views

Overriding a core controller's preDispatch method

I need to override a core controller's preDispatch method. The core controller inherits from Mage_Checkout_Controller_Action, which itself has a preDispatch method that needs to be called. Since I'm ...
7 votes
2 answers
2k views

AccountController override not working on new Action and doing 302 redirection

I am try add new action on AccountController Now: AccountController is override properly But it is whenever hit new Action (ajaxLoginPostAction) is redirect to 302. I add ajaxLoginPost() as open ...
  • 76k
4 votes
1 answer
2k views

Magento2: how to remove all cart's items from controller?

Please, how can i remove all cart's items from controller? namespace Demo\Demo\Controller\Demo; class Demo extends \Magento\Framework\App\Action\Action { public function execute() { ...
0 votes
2 answers
706 views

Custom module not working on live server

I made a custom module for seller management. It is working fine on local server but not on the live server. I am getting an error in loading my block. Controller.php protected function _initAction()...
23 votes
5 answers
33k views

Send data from the controller to phtml

I have this controller: ... public function insertAction() { $something = 'testcase'; $this->loadLayout(); $this->_title($this->__("the title")); $this->renderLayout(); } ....
7 votes
3 answers
9k views

magento2.3 controller won't handle post method

This is something I used to be able to do in 2.2, but in 2.3 I can't. A simple controller to handle a POST method, and only receive and send application/json content type. It works for GET/PUT ...
  • 306
7 votes
4 answers
13k views

Call action after "Save Config" was clicked in the admin

How can I call an action of my controller in a custom module after "Save Config" was clicked in System --> Configuration --> Catalog? (image) Settings of my module are inside that section, and I need ...
  • 2,172
7 votes
3 answers
17k views

Magento 2 - Ajax is not calling Controller

I tried to make a simple ajax-call to my controller. Somehow I don't get a valid response. MyCompany/MyModule/Index/GetAjax.php namespace MyCompany\MyModule\Controller\Index; class GetAjax extends ...
  • 604
6 votes
1 answer
6k views

magento 2 run function on every page

I have a function that retrieves a visiting user's country name by doing an ip lookup. I currently have this function running through the execute method in my module's controller. The problem is ...
  • 1,632
4 votes
3 answers
772 views

Bind subdomain to a Magento Controller

I am working on an application for which I want to create few sub-domains in system, which will be served by Magento application. One example scenario can be creating separate sub-domains for system ...
  • 319
4 votes
2 answers
3k views

Copy core file to app/code/local/Mage can't overload!

I have 2 files need to be overload core/Mage/Admin/Model/Session.php and core/Mage/Adminhtml/controllers/IndexController.php I already copy it to local with same structure, but the bad news is it ...
  • 2,879
4 votes
1 answer
5k views

how to call controller using ajax in admin backend magento 2

I have to call the controller using Ajax in Admin backend of Magento 2. Can we directly call the controller or do we have to include any key values? Please help me.
  • 352
2 votes
3 answers
14k views

Add custom button to upload a file

I would like to add a custom button in a backend grid page, that let me upload a file in Magento. So basically it should give me a "file selector" and then file should be processed in a controller. ...
  • 6,875
6 votes
2 answers
24k views

Retreive and return response from controller in magento2

I have a problem in which I'm making an AJAX call to a controller. But, I am not able to check whether it is working or not. I also want to return data in response. But, it keeps throwing some errors. ...
2 votes
3 answers
7k views

Programmatically trigger admin save action on product

I have been troubleshooting a problem for hours. I can't explain why, but the problem is resolved when I go to the product in admin and click "Save" for that product (without changing anything). I am ...
  • 293
3 votes
2 answers
324 views

Help Overriding CartController

I've been pulling my hair out with this... I've looked at probably 20 different tutorials and StackOverflow posts and I can NOT see what is wrong with my code. I'm trying to override CartController....
  • 53
2 votes
2 answers
13k views

Override core checkout cart controller

I have already included a custom controller in my local module. The config.xml snippet for it is: <routers> <subscription> <use>standard</use> ...
1 vote
2 answers
785 views

Save file that customer submits through a form

I have a form: <form class="customDocs" method="post" action="<?php echo $this->getUrl('customdocuments/index/send') ?>"> <h2>Upload Seller's Permit Here:</h2> <...
1 vote
1 answer
2k views

how to call controller method from block file

I am calling a method written in controller file from a block file as shown in below code-- BLOCK FILE class Assel_Sms_Block_Adminhtml_Sendpushmsg extends ...
1 vote
2 answers
814 views

How to override customer AccountController in magento1.9

I was used below code but not work in-effect it removes my login and registration link from the top links. Config.xml <?xml version="1.0"?> <config> <modules> <...
  • 1,483
1 vote
3 answers
4k views

Add multiple items to cart in Magento2

I am implementing add to cart functionality from ajax using product id. This is my code of template file <tr class="border_bottom child-items selected"> <td >...
  • 1,759
1 vote
0 answers
428 views

Show Discount Block in Cart Totals using Ajax [closed]

I am working on a custom module where I need to show my discount in cart totals. I am following Classyllama and Turnkey blog posts in order to achieve the same. I have come to a point where my custom ...
  • 303
0 votes
1 answer
562 views

Contact Post Controller overridden in Custom Module not working

I have override contact form post controller in custom module. It is calling from my module but i am getting error as Fatal error: Uncaught Error: Call to a member function send() private function ...
  • 1,454
0 votes
1 answer
340 views

Where can I edit the post product review action/handler?

I'm trying to resolve this ridiculous issue that nobody can shed any light on Unable to post product reviews on secondary store site; displays recaptcha error but no recaptcha is present in form? It'...
0 votes
1 answer
698 views

Magento 2: ACL Permission Call Manually for Logged In Admin

Magento 2: ACL Permission for Admin Module In magento\app\code\Custom\Module\Controller\Adminhtml\Posts\Index.php namespace Custom\Module\Controller\Adminhtml\Posts; use Magento\Framework\View\...
  • 9,543
43 votes
1 answer
7k views

Difference between /Controller and /controllers

A question I've been meaning to ask for ages, more theoretical than anything else. I'm fully versed in developing Extensions using the normal Magento module file structure. I've noticed though when ...
4 votes
1 answer
11k views

Magento 2 : How do I create my own action in controller to call url from Ajax in Magento 2.x

How Do I create my own Action in Controller to call url from Ajax in Magento 2.0. Like in Magento 1.9 we can create any Action an any Controller and call that from URL.
29 votes
2 answers
2k views

Why c is lowercase in controllers of Magento?

Why is c lowercase in controllers folder name? Whereas Model, Block and Helper are starting with an uppercase letter?
  • 293
4 votes
1 answer
2k views

How Magento 2 Routing Works

I need to know how magento 2 Routing Works... I want to know that when we request for any task in magento 2 then how its process to controller... Like I used command line console...' Then how my ...
  • 1,125
9 votes
1 answer
6k views

Magento 2 : Modal Popup using Ajax

How to use model popup using ajax? Can any one help for this. Here below my code. How can i apply in this code model popup? And also post data get in popup. How it possible? app/code/Vendor/Complany/...
  • 1,483
7 votes
2 answers
15k views

Form Key Value in template and controller

The following function is used to get the form key in templates with type hidden. My customerController.php does not validate the form key with the method _validateFormKey(). When I echo the following ...
7 votes
1 answer
7k views

Dynamic create block in magento 2 and send as ajax call response?

I want replacement of following in magento 2.x $block = $this->getLayout()->createBlock('customer/form_login')->setTemplate('persistent/customer/form/login.phtml'); $this->getResponse()-&...
  • 3,048
2 votes
2 answers
536 views

Using __call in a controller

Is there any examples of using __call in a controller to replace a specific action method. I have a situation where I need to provide different endpoints to the same controller. A reference to each ...
  • 2,184
7 votes
2 answers
18k views

How to get RefererUrl in magento 2 observer?

How to get RefererUrl (source page url) in Observer file? Actually by using this; $this->_redirect->getRefererUrl(); I am getting Referer Url in magento 2 controller file.But in Observer file ...
  • 1,367
5 votes
3 answers
7k views

Modify catalogsearch module to search by attribute values

I have attempted for quite a number of hours to solve this but I can't find the solution. I want to allow users to search by certain attribute values, for example ingredients, brand OR product name. ...
  • 151
1 vote
2 answers
2k views

Magento Design Exceptions - switching back to desktop

I am using Magento's design exceptions to set the theme as mobile for mobile devices. Since I am not using a separate store view or website, is it possible to provide to the user a 'Switch to Desktop'...
  • 2,963
9 votes
3 answers
10k views

Creating custom module in magento2 show fatal error

I working on creating custom module in magento 2, but it's not working. Could you please suggest me where i went wrong?. My module code: app/etc/config.php: 'modules' => array ( '...
  • 91