understanding adminhtml url paths - magento

I am following this tutorial from alan storm "magento_admin_hello_world_revisited" and it has been a great help in understanding the basics in putting together something for the admin section. Unfortunately, I'm left feeling a little confused on setting the URL path and as a result I have got a 404 error when I click on my link in the menu bar.
The tutorial says that I need to add
<action>adminhtml/Adminprefcentre/index</action>
to my adminHtml.xml for the menu link. Later in the tutorial it mentions that I need to add
<Adminprefcentre after="Mage_Adminhtml">Adminprefcentre</Adminprefcentre>
to my config.xml (NOTE: I have included the other relevant nodes described in the article into the config.xml).
As I was adding the <action> node I took that to mean the link which will be clicked on from the menu bar. As I added the <Adminprefcentre> node I believed that meant it was something to do with rewriting the admin frontName which is mentioned. Is this wrong?
I have created a controller in the usual way Name_Module_AdminprefcentreController and given it an action of indexAction.
When I click on my link in the menu bar i get .../admin/adminprefcentre/index/key/ae6a... and a 404 not found.
I am obviously misunderstanding what is being taught so
1 - what is the section that I am adding to my config.xml file doing?
2 - where should I look to resolve my 404 message?

In config.xml
<config>
.....
<admin>
<routers>
<adminhtml>
<use>admin</use>
<args>
<modules>
<MagePal_Adminprefcentre before="Mage_Adminhtml">MagePal_Adminprefcentre_Adminhtml</MagePal_Adminprefcentre>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Your Controller path
/app/code/local/MagePal/Adminprefcentre/controllers/Adminhtml/AdminprefcentreController.php
in adminhtml.xml
<children>
<adminprefcentre module="adminprefcentre">
<title>menu title</title>
<sort_order>15</sort_order>
<children>
<magepal_adminprefcentre module="adminprefcentre">
<title>Submenu Title</title>
<sort_order>15</sort_order>
<action>adminhtml/adminprefcentre</action> <!-- call index action in your controller -->

Related

How to rewrite that Magento admin action after applying 6788?

This is my old XML:
<config>
<menu>
<customactions_menu translate="title" module="giftcard">
<title>my title</title>
<sort_order>9999</sort_order>
<action>giftcard/admin/coupons</action>
</customactions_menu>
</menu>
</config>
This action does not work any longer after applying patch 6788. How do I have to write that action so it works again?
I already changed my route for the module in config.xml according to the suggestion from https://github.com/rhoerr/supee-6788-toolbox.
Thanks!
For a module controller structure like following
app\code\local\AW\Followupemail\controllers\Adminhtml\Followupemailadmin\
CouponsController.php
The action section will be like following (for index action)
<action>adminhtml/followupemailadmin_coupons</action>
If you can update your question with your config.xml and directory structure, I can try to help in better manner.

Magento - Custom admin router but with no menu item

I want to create an admin controller - without having any menu items associated with it.
Ideally I want to have my controller accessible via /index.php/admin/my_controller/.
So far I have rewritten the adminhtml controller as follows but i simnply get a 404 inside the admin console (i.e. not the main 404 page):
<admin>
<routers>
<my_module>
<use>admin</use>
<args>
<module>Me_Mymodule</module>
<frontName>my_controller</frontName>
</args>
</my_module>
<adminhtml>
<args>
<modules>
<my_module after="Mage_Adminhtml">Me_Mymodule</my_module>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Your current config technique has been obsolete since version 1.4. Instead it is more convenient to structure it like this.
<admin>
<routers>
<adminhtml>
<args>
<modules>
<my_module before="Mage_Adminhtml">Me_Mymodule_Adminhtml</my_module>
</modules>
</args>
</adminhtml>
</routers>
</admin>
Then to get the /index.php/admin/mymodule/ path create the class Me_Mymodule_Adminhtml_MymoduleController extends Mage_Adminhtml_Controller_Action in Me/Mymodule/controllers/Adminhtml/MymoduleController.php. In your example you used an underscore in the controller name, be careful of that as it will be used as a directory separator when searching for the correct class.
Remember to generate URLs for your controller like Mage::getUrl('adminhtml/mymodule') so that it adds the secret key to paths, this is necessary when making an admin controller or it will refuse the page.
If there are no menu items then it will not be possible to add them to the ACL. You do not need an adminhtml.xml file in this case.
For you goal xml config is redundant.
Use following to add your controller to /admin frontname
Company_Module_Adminhtml
Now every controller that will be created in controller/Adminhtml folder will accessed through admin like
/admin/yourfilename/index
The class name of controller should be Module_Module_Adminhtml_YourfilenameController and should extend Mage_Adminhtml_Controller_Action
That's the trick.
Even if you do not add your controller to menu, you still have to add acl section for your controller adminhtml.xml. Do not forget to relog to admin after that.

Custom Account Controller Causes 404 On Address Book

I've encountered a problem in our Magento installations that I've been having a really hard time tracking down. Whenever a customer goes to the "My Account" page and clicks the "Address Book" link, it sends them to the default 404 CMS page. I searched around Google and found a few similar problems, but they weren't quite the same. However, one solution that was offered was that a custom login redirect module was the cause.
So I started disabling all of our custom modules one by one to see if that would fix the problem, and it turned out that disabling our custom Account Controller fixes the problem. I tried to track this down further by using Mage::log() in the overridden methods to see if they were getting called when trying to access /customer/address/, but nothing showed up in the logs.
The only lead I have left is that it's a problem with my controller configuration. This is the config.xml I have set up:
<?xml version="1.0"?>
<config>
<modules>
<mymodule_login>
<version>0.1.0</version>
</mymodule_login>
</modules>
<frontend>
<routers>
<mymodule_login>
<use>standard</use>
<args>
<module>MyModule_Login</module>
<frontName>customer</frontName>
</args>
</mymodule_login>
</routers>
</frontend>
<global>
<rewrite>
<mymodule_login>
<from><![CDATA[#^/account/#]]></from>
<to>/customer/account/</to>
</mymodule_login>
</rewrite>
<blocks>
<customer>
<rewrite>
<register-login>MyModule_Login_Block_View</register-login>
</rewrite>
</customer>
<login>
<class>RegisterLogin</class>
</login>
</blocks>
</global>
</config>
I think it might be a problem with the rewrite from #^/account/# to /customer/account/, but I don't know enough about Magento rewrites to determine if that's accurate or not. The methods I have overwritten are: loginPostAction, _loginPostRedirect, and _welcomeCustomer.
Dick Laurent was right - it was my configuration. All I did was add a second controller that overrode Mage_Customer_AddressController and now it works fine. The problem was that my frontend name was "customer" so it was expecting to find the corresponding controller in my custom module for when it went to the URL /customer/address/.
I had to override Mage_Customer_AccountController, however you can't simply just override just one controller, you have to override the whole module.
So here is how you solve in this situation. You create files that reference the parent.
NOTE: Replace {Namespace} with your custom namespace.
Here is my config.xml: (inside the folder app/code/local/{Namespace}/Customer/etc)
<?xml version="1.0"?>
<config>
<modules>
<{Namespace}_Customer>
<version>0.1.0</version>
</{Namespace}_Customer>
</modules>
<frontend>
<routers>
<customer>
<use>standard</use>
<args>
<module before="Mage_Customer">{Namespace}_Customer</module>
<frontName>customer</frontName>
</args>
</customer>
</routers>
</frontend>
</config>
Now overriding Mage_Customer_AccountController: (inside the folder app/code/local/{Namespace}/Customer/controllers)
<?php
require_once ('Mage/Customer/controllers/AccountController.php');
class {Namespace}_Customer_AccountController extends Mage_Customer_AccountController
{
protected function _loginPostRedirect()
{
$session = $this->_getSession();
if($session->getBeforeAuthUrl() == Mage::getUrl('checkout/onepage/index')){
$session->setBeforeAuthUrl(Mage::getUrl('checkout/cart'));
$this->_redirectUrl($session->getBeforeAuthUrl(true));
return;
}
return parent::_loginPostRedirect();
}
}
This redirects the customer back to their cart page after they login though checkout. We did this, because if there is an item in their cart from a previous session, Magento will combine the recent cart items with the ones from the previous session and proceed to payment without telling the customer. So to avoid customer complaints we simply redirect back to cart so the customer can see that this happens.
Now because we are overriding the entire module, we have to create the aforementioned files that reference the parent. The two other controllers under Mage_Customer are Mage_Customer_AddressController and Mage_Customer_ReviewController. Your Magento instance may vary as versions change, so make sure you check the parent folder, located at (app/code/core/Mage/Customer/controllers), and NEVER DIRECTLY EDIT CORE!
Here we reference the parent for Mage_Customer_AddressController: (inside the folder app/code/local/{Namespace}/Customer/controllers)
<?php
require_once ('Mage/Customer/controllers/AddressController.php');
class {Namespace}_Customer_AddressController extends Mage_Customer_AddressController
{
}
Likewise for Mage_Customer_ReviewController: (same file location)
<?php
require_once ('Mage/Customer/controllers/ReviewController.php');
class {Namespace}_Customer_ReviewController extends Mage_Customer_ReviewController
{
}
Without these files Magento simply can't find the controllers and throws a 404.
Lastly, create a file under app/etc/modules called {Namespace}_Customer.xml to enable your override, and address book should no longer 404.

Rewriting Mage_Paypal_Model_Express_Checkout

I have run into a problem where shipping options are not making it to the PayPal Express review page. If the buyer enters a free shipping coupon and then uses PayPal Express, when they return from the PP website, the review page where the submit the order doesn't have the free shipping option.
I found a thread where this was answered by adding code to the Mage_Paypal_Model_Express_Checkout class. This change works, but modifying core code is a no-no, so I'm trying to rewrite the class and I'm having trouble. I've rewritten core classes before, but this one is different somehow and I can't figure it out. Can someone point me in the right direction?
here's the contents of my config.xml. Does this look right?
<config>
<modules>
<VPS_Paypal>
<version>0.1.0</version>
</VPS_Paypal>
</modules>
<global>
<models>
<paypal>
<rewrite>
<express_checkout>
<class>VPS_Paypal_Model_Express_Checkout</class>
</express_checkout>
</rewrite>
</paypal>
</models>
</global>
</config>
I haven't tested this, but based on the class name I would think that adding this to the section of your config would work:
<paypal>
<rewrite>
<express_checkout>Your_Model_Class_Here</express_checkout>
</rewrite>
</paypal>
Your custom class should extend Mage_Paypal_Model_Express_Checkout and only override the method you want to change.

Magento config XML for adding a controller action to a core admin controller

I'm trying to add a custom action to a core controller by extending it in a local module. Below I have the class definition which resides in magento1_3_2_2/app/code/local/MyCompany/MyModule/controllers/Catalog/ProductController.php
class MyCompany_MyModule_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
public function massAttributeSetAction(){
...
}
}
Here is my config file at
magento1_3_2_2/app/code/local/MyCompany/MyModule/etc/config.xml:
...
<global>
<rewrite>
<mycompany_mymodule_catalog_product>
<from><![CDATA[#^/catalog_product/massAttributeSet/#]]></from>
<to>/mymodule/catalog_product/massAttributeSet/</to>
</mycompany_mymodule_catalog_product>
</rewrite>
<admin>
<routers>
<MyCompany_MyModule>
<use>admin</use>
<args>
<module>MyCompany_MyModule</module>
<frontName>MyModule</frontName>
</args>
</MyCompany_MyModule>
</routers>
</admin>
</global>
...
However, https://example.com/index.php/admin/catalog_product/massAttributeSet/ simply yields a admin 404 page. I know that the module is active - other code is executing fine. I feel it's simply a problem with my xml syntax. Am I going about this the write way? I'm hesitant because I'm not actually rewriting a controller method... I'm adding one entirely. However it does make sense in that, the original admin url won't respond to that action name and it will need to be redirected.
I'm using Magento 1.3.2.2
Thanks for any guidance.
I don't have access to my Magento installs at the moment, but two things pop out
First, your write rule
[#^/catalog_product/massAttributeSet/]
Is saying "match any URL that starts with /catalog_product" and your question indicates you want to match a URL that begins with /admin/catalog_product.
Second, if you're using 1.3+ consider skipping the URL rewrite method and trying a "real" controller override instead.

Resources