Edit 4/4/12
I STILL HAVE ONE QUESTION:
I solved my issue but it adds my option at the top of the list. How can I sort it to my my option to the bottom of the list?
Please see answer for contents of my working config.xml file...
I'm looking for in depth help here because I've been at this for quite a while now and seem to be getting nowhere.
Background
I was looking to make a printable RMA form for our customers to make it easier on them to Return/Exchange items.
I did this with the help of this extension: http://www.magentocommerce.com/magento-connect/admin-order-printing-extension.html
(Please download this to see the directory structure if needed)
It adds a button to the order and then I went in and edited the form/form layout so that it was an RMA (or has RMA content).
Everything is working great, however, we have to go into each order and press the button in order for it to print.
We really need a Mass Action in order to make it more efficient and useful.
Problem
I've tried to different ways to get this to work but I really need help on this. Most recently I've tried to follow this tutorial (http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/) using the second method of events but I can't seem to get this to work.
Can someone please explain in more depth (this last method I've tried) so that I can get it working with this module???
I've added this in the config.xml(according to the tutorial)
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<orderprint_core_block_abstract_prepare_layout_before>
<class>orderprint/observer</class>
<method>addRmaAction</method>
</orderprint_core_block_abstract_prepare_layout_before>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
And in Nastnet/OrderPrint/Model/Observer.php I've added this (according to the tutorial)
<?php class Nastnet_OrderPrint_Model_Observer {
public function addRmaAction($observer) {
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
&& $block->getRequest()->getControllerName() == 'sales_order')
{
$block->addItem('pdfrma_order', array(
'label' => 'Print RMA',
'url' => Mage::app()->getStore()->getUrl('nastnet/controller/action'),
));
}
} }
(Sorry for the messy code above - the only way I could get it highlighted)
EDIT 1 (4/2/12)
This is my module's config.xml file. I've had to go with the rewrite/override method as of right now (deleting my attempts at using events). If you see anything, including the exact structure of what it would need to be please let me know...
Minus the <config> tags:
<modules>
<Nastnet_OrderPrint>
<version>0.1.3</version>
</Nastnet_OrderPrint>
</modules>
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>Nastnet_OrderPrint_Block_Sales_Order_Grid</sales_order_grid> <!-- WORKIING METHOD -->
<sales_order_view>Nastnet_OrderPrint_Block_Sales_Order_View</sales_order_view>
</rewrite>
</adminhtml>
</blocks>
<rewrite>
<Nastnet_OrderPrint_OrderController>
<from><![CDATA[#/\w+/sales_order/print/#]]></from>
<to>/orderprint/order/print/</to>
</Nastnet_OrderPrint_OrderController>
</rewrite>
<models>
<Nastnet_OrderPrint>
<class>Nastnet_OrderPrint_Model</class>
</Nastnet_OrderPrint>
</models>
<pdf>
<order>
<default>Nastnet_OrderPrint/order_pdf_items_order_default</default>
<grouped>Nastnet_OrderPrint/order_pdf_items_order_grouped</grouped>
</order>
</pdf>
</global>
<admin>
<routers>
<Nastnet_OrderPrint>
<use>admin</use>
<args>
<module>Nastnet_OrderPrint</module>
<!-- This is used when "catching" the rewrite above -->
<frontName>orderprint</frontName>
</args>
</Nastnet_OrderPrint>
</routers>
I've figured out the correct handles and everything in order for this to work (with the help of this article: http://mydons.com/simple-example-using-magento-event-observer/)
In the config.xml file, I had to make new <adminhtml> handles after the <config> handles. This got me to the right "depth". Here is the entire config.xml file minus the <config> handles (cause it won't paste correctly):
<modules>
<Nastnet_OrderPrint>
<version>0.1.3</version>
</Nastnet_OrderPrint>
</modules>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<Nastnet_OrderPrint_Model_Observer>
<type>singleton</type>
<class>Nastnet_OrderPrint_Model_Observer</class>
<method>addRmaAction</method>
</Nastnet_OrderPrint_Model_Observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_view>Nastnet_OrderPrint_Block_Sales_Order_View</sales_order_view>
</rewrite>
</adminhtml>
</blocks>
<rewrite>
<Nastnet_OrderPrint_OrderController>
<from><![CDATA[#/\w+/sales_order/print/#]]></from>
<to>/orderprint/order/print/</to>
</Nastnet_OrderPrint_OrderController>
</rewrite>
<models>
<Nastnet_OrderPrint>
<class>Nastnet_OrderPrint_Model</class>
</Nastnet_OrderPrint>
</models>
<pdf>
<order>
<default>Nastnet_OrderPrint/order_pdf_items_order_default</default>
<grouped>Nastnet_OrderPrint/order_pdf_items_order_grouped</grouped>
</order>
</pdf>
</global>
<admin>
<routers>
<Nastnet_OrderPrint>
<use>admin</use>
<args>
<module>Nastnet_OrderPrint</module>
<!-- This is used when "catching" the rewrite above -->
<frontName>orderprint</frontName>
</args>
</Nastnet_OrderPrint>
</routers>
</admin>
This is the part that I needed and it is finally correct here:
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<Nastnet_OrderPrint_Model_Observer>
<type>singleton</type>
<class>Nastnet_OrderPrint_Model_Observer</class>
<method>addRmaAction</method>
</Nastnet_OrderPrint_Model_Observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
It points to my observer file (based on the correct event) here: app/code/local/Nastnet/OrderPrint/Model/Observer.php. This obviously then holds my addRmaAction.
I STILL HAVE ONE QUESTION:
This puts my option at the top of the list. How can I sort it to my my option to the bottom of the list?
Contents of Observer.php
<?php
class Nastnet_OrderPrint_Model_Observer
{
public function addRmaAction($observer)
{
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
&& $block->getRequest()->getControllerName() == 'sales_order')
{
$block->addItem('rmamassprint', array(
'label' => 'Print Return/Exchange',
'url' => Mage::app()->getStore()->getUrl('orderprint/order/pdfRma'),
));
}
}
}
For starters did you confirm whether or not your observer is being called? Just by adding a Mage::log("Observer called");
and watching the system.log file..
Here is the working tutorial for adding mass action to Sales > Order Grid:
http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/
Try the 2nd approach(using event-observer method) which seems to be more upgrade proof way.
Thanks
Related
at the moment i'm trying to commit a little change to Magento's Paypal Express Extension. I'm trying to get rid of the review page because it's unnecessary.
How it's done is alreasy described here:
Magento: easy way to remove "paypal/express/review" step
But it won't work when you enable agreements.
And here's the problem:
app/code/core/Mage/Paypal/Controller/Express/Abstract.php
line 314 to 316 must be uncommented
if (array_diff($requiredAgreements, $postedAgreements)) {
Mage::throwException(Mage::helper('paypal')->__('Please agree to all the terms and conditions before placing the order.'));
}
app/code/community/Sandfox/RemovePaypalExpressReviewStep/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Sandfox_RemovePaypalExpressReviewStep>
<version>0.1.0</version>
</Sandfox_RemovePaypalExpressReviewStep>
</modules>
<global>
<models>
<sandfox_removepaypalexpressreviewstep>
<class>Sandfox_RemovePaypalExpressReviewStep_Model</class>
</sandfox_removepaypalexpressreviewstep>
<paypal>
<rewrite>
<config>Sandfox_RemovePaypalExpressReviewStep_Model_Config</config>
</rewrite>
</paypal>
</models>
<events>
<controller_action_predispatch_paypal_express_review>
<observers>
<sandfox_removepaypalexpressreviewstep>
<type>singleton</type>
<class>sandfox_removepaypalexpressreviewstep/observer</class>
<method>controllerActionPredispatchPaypalExpressReview</method>
</sandfox_removepaypalexpressreviewstep>
</observers>
</controller_action_predispatch_paypal_express_review>
</events>
</global>
<frontend>
<routers>
<paypal>
<args>
<modules>
<Sandfox_RemovePaypalExpressReviewStep before="Mage_Paypal">Sandfox_RemovePaypalExpressReviewStep</Sandfox_RemovePaypalExpressReviewStep>
</modules>
</args>
</paypal>
</routers>
</frontend>
</config>
Now i tried to rewrite the controller (is it really a controller? Why it's not in controllers but has it's own Controller directory?)
app/code/community/Sandfox/RemovePaypalExpressReviewStep/Controller/Express/Abstract.php
<?php
include_once("Mage/Paypal/Controller/Express/Abstract.php");
class Sandfox_RemovePaypalExpressReviewStep_Controller_Express_Abstract extends Mage_Paypal_Controller_Express_Abstract
{
public function placeOrderAction()
{
try {
.
.
.
// if (array_diff($requiredAgreements, $postedAgreements)) {
// Mage::throwException(Mage::helper('paypal')->__('Please agree to all the terms and conditions before placing the order.'));
// }
}
.
.
.
}
At the moment the rewrite doesn't work. Can someone give me a hint?
tec:
Magento 1.9.2
PHP 5.5
MYSQL 5.6.19
In your config.xml, remove the space after module's name
<Sandfox_RemovePaypalExpressReviewStep before="Mage_Paypal">Sandfox_RemovePaypalExpressReviewStep </Sandfox_RemovePaypalExpressReviewStep>
should be changed to
<Sandfox_RemovePaypalExpressReviewStep before="Mage_Paypal">Sandfox_RemovePaypalExpressReviewStep</Sandfox_RemovePaypalExpressReviewStep>
You can't extends an Abstract class. U need to copy into local/Mage...
I am trying to override Mage_Sales_Model_Resource_Order_Collection
My custom module's config:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Abc_Salesextend>
<version>0.1.0</version>
</Abc_Salesextend>
</modules>
<global>
<blocks>
<salesextend>
<class>Abc_Salesextend_Block</class>
</salesextend>
<adminhtml>
<rewrite>
<sales_order_grid>Abc_Salesextend_Block_Sales_Order_Grid</sales_order_grid>
</rewrite>
</adminhtml>
</blocks>
<models>
<salesextend>
<class>Abc_Salesextend_Model</class>
<resourceModel>salesextend_resource</resourceModel>
</salesextend>
<salesextend_resource>
<class>Abc_Salesextend_Model_Resource</class>
</salesextend_resource>
<!-- HERE is i am trying to override-->
<sales_resource>
<rewrite>
<order_collection>Abc_Salesextend_Model_Resource_Order_Collection</order_collection>
</rewrite>
</sales_resource>
</models>
</global>
</config>
It's not giving me any kind of error even if I place the wrong custom class name. So it's not finding my custom class.
Please help
I am not quite sure why the rewrite fails. The rewrite definition looks good. The error can only be related to the wrong class used for rewriting, a cache problem (config.xml cache) or to your module not being active.
I guess you want to just manipulate the collection so instead of a rewrite you should use some event/observer technique.
/**
*
* Sales order grid collection
* #param unknown_type $observer
*/
public function salesOrderGridCollectionLoadBefore($observer){
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$select->DO_WHATEVER_YOU_WANT...
}
and this method is triggered by:
<events>
<sales_order_grid_collection_load_before>
<observers>
<cartware_modify_grid_adminhtml_collection>
<model>your_module/observer_block</model>
<method>salesOrderGridCollectionLoadBefore</method>
</cartware_modify_grid_adminhtml_collection>
</observers>
</sales_order_grid_collection_load_before>
</events>
</adminhtml>
Good luck!
<sales>
<rewrite>
<resource_order_collection>Abc_Salesextend_Model_YOURFILENAME</resource_order_collection>
</rewrite>
</sales>
just replace with you file name in YOURFILENAME,,,it works...
i try to overridde
app\code\core\Mage\Customer\Model\Resource\Customer.php
with this xml:
<models>
<customer_resource>
<rewrite>
<customer>My_Company_Model_Resource_Customer</customer>
</rewrite>
</customer_resource>
</models>
but i get
Mage registry key "_resource_singleton/customer/customer" already exists
and with
<customer>
<rewrite>
<customer_resource>My_Company_Model_Resource_Customer</customer_resource>
</rewrite>
</customer>
or
<models>
<customer>
<rewrite>
<resource_customer>My_Company_Model_Resource_Customer</resource_customer>
</rewrite>
</customer>
</models>
nothing happens
You should be able to accomplish it with the code you had. If it is not being overwritten try some of the basics like making sure you've cleared your cache. If that still doesn't work, you might be fighting with another module that is already overriding it. In that case you'd need to figure out the next steps in figuring out which one wins: merge logic, rewrite/extend the other one, etc.
<models>
<customer_resource>
<rewrite>
<customer>My_Company_Model_Resource_Customer</customer>
</rewrite>
</customer_resource>
</models>
I did it (in 1.7.0.2) with the following xml:
<?xml version="1.0" encoding="UTF-8" ?>
<config>
<modules>
<Final_Dummy>
<version>0.0.1</version>
</Final_Dummy>
</modules>
<frontend>
<routers>
<dummy>
<use>standard</use>
<args>
<module>Final_Dummy</module>
<frontName>dummy</frontName>
</args>
</dummy>
</routers>
</frontend>
<global>
<helpers>
<dummy>
<class>Final_Dummy_Helper</class>
</dummy>
</helpers>
<models>
<dummy>
<class>Final_Dummy_Model</class>
<resourceModel>dummy_resource</resourceModel>
</dummy>
<dummy_rsource>
<class>Final_Dummy_Model_Resource</class>
<deprecatedNode>dummy_mysql4</deprecatedNode>
</dummy_rsource>
<customer_resource>
<rewrite>
<customer>Final_Dummy_Model_Resource_Customer</customer>
</rewrite>
</customer_resource>
</models>
</global>
</config>
and in order to make sure that it really works I created the following class:
<?php
class Final_Dummy_Model_Resource_Customer extends Mage_Customer_Model_Resource_Customer{
public function amIHere(){
return 'Yes sir';
}
}
?>
and called the resource in my module's controller like this
<?php
class Final_Dummy_IndexController extends Mage_Core_Controller_Front_Action{
public function indexAction(){
$res=Mage::getResourceModel('customer/customer');
die($res->amIHere());
}
}
?>
and the result was:
Yes sir
I hope these code help you in some way. remember to clear the cache and I do recommend that in development phase, disable Magento compiler.
I would like to set the default number of displayed rows in the admin to higher than 20.
I was following along at http://inchoo.net/ecommerce/magento/magento-admin-grid-how-to-change-number-of-rows/, but I'm trying to make a module to do the task. Magento version is 1.4.2.0.
The error I am getting is Mage registry key "_singleton/grid/observer" already exists.
I have in app/code/local/Company/Custom/etc/config.xml:
<config>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<grid_observer>
<class>grid/observer</class>
<method>applyLimitToGrid</method>
</grid_observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
</config>
and in app/code/local/Company/Custom/Model/Observer.php:
class Company_Custom_Grid_Model_Observer
{
public function applyLimitToGrid(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if (($block instanceof Mage_Adminhtml_Block_Widget_Grid) && !($block instanceof Mage_Adminhtml_Block_Dashboard_Grid)) {
$block->setDefaultLimit(200);
}
}
}
app/etc/modules/Company_Custom.xml:
<config>
<modules>
<Company_Custom>
<codePool>local</codePool>
<active>true</active>
</Company_Custom>
</modules>
</config>
class Company_Custom_Grid_Model_Observer
should be
class Company_Custom_Model_Observer
You don't have module models class declaration:
<global>
<models>
<modulename>
<class>Namespace_ModuleName_Model</class>
</modulename>
</models>
</global>
The biggest change was in Company/Custom/etc/config.xml, where I put the <events> section inside a <global> block instead of <adminhtml>.
Also inside that file, and fixing the error message was <class>Company_Custom_Model_Observer</class> (where I had grid/observer before...)
As titled.
But still, users can login to the frontend, and administrator could create user account only in backend.
Another possibility would be overloading the customer/account/create action and just redirect the user to the home page when this action is invoked.
In a first time, just do what was proposed by Ben V. It will remove the possibility to view the registration page.
Then, create a new module in which you will overload the AccountController.php.
1- Create a new folder in app/code/local/ named Mycompany
2- Create a new folder in app/code/local/Mycompany/ named Registrationremove
3- Create app/code/local/Mycompany/Registrationremove/etc/
4- Create app/code/local/Mycompany/Registrationremove/etc/config.xml
Copy and Paste in config.xml :
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Registrationremove>
<version>0.1.0</version>
</Mycompany_Registrationremove>
</modules>
<global>
<rewrite>
<mycompany_registrationremove_customer_account_create>
<from><![CDATA[#^/customer/account/create/$#]]></from>
<to>/registrationremove/customer_account/create</to>
</mycompany_registrationremove_customer_account_create>
<mycompany_registrationremove_customer_account_createPost>
<from><![CDATA[#^/customer/account/createPost/$#]]></from>
<to>/registrationremove/customer_account/createPost</to>
</mycompany_registrationremove_customer_account_createPost>
</rewrite>
</global>
<frontend>
<routers>
<registrationremove>
<use>standard</use>
<args>
<module>Mycompany_Registrationremove</module>
<frontName>registrationremove</frontName>
</args>
</registrationremove>
</routers>
</frontend>
</config>
5- Create app/code/local/Mycompany/Registrationremove/controllers
6- Create app/etc/modules/Mycompany_Registrationremove.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Registrationremove>
<active>true</active>
<codePool>local</codePool>
</Mycompany_Registrationremove>
</modules>
</config>
7- Create app/code/local/Mycompany/Registrationremove/controllers/Customer/AccountController.php
Copy and Paste in AccountController.php:
require_once 'Mage/Customer/controllers/AccountController.php';
class Mycompany_Registrationremove_Customer_AccountController extends Mage_Customer_AccountController
{
public function createAction()
{
$this->_redirect('*/*');
}
public function createPostAction()
{
$this->_redirect('*/*');
}
}
8- Create app/code/local/Mycompany/Registrationremove/Helper/Data.php
Copy and paste in Data.php:
class Mycompany_Registrationremove_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Now, when someone tries to access to customer/account/create/ it should be redirected to the home page.
Hope that helped :)
Hugues.
You could modify the login screen to remove the "Create New Account" button. This way existing users can still log in but they have no way to create new accounts.
The file to modify is /app/design/frontend/default/default/template/customer/form/login.phtml. Around line 41 you'll see <div class="col-1 new-users">. Comment out that entire div to hide the New User section of the login page.
Edit:
There is no way to just disable new user registration like you are asking. I did a little more searching, and all I found were several people with the same idea as mine. In addition to my original suggestion, I would
a) remove the <customer_account_create> section of /app/design/frontend/default/default/layout/custom.xml, and
b) remove the registration-related lines from /app/design/frontend/default/default/template/checkout/onepage/login.phtml.
Ok. I got it worked. Refer to Hugues Solution, there are two amendments:
add app\etc\modules\Mycompany_All.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Registrationremove>
<active>true</active>
<codePool>local</codePool>
</Mycompany_Registrationremove>
</modules>
</config>
modify the file: app/code/local/Mycompany/Registrationremove/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Registrationremove>
<version>0.1.0</version>
</Mycompany_Registrationremove>
</modules>
<global>
<rewrite>
<mycompany_registrationremove_customer_account_create>
<from><![CDATA[#^/customer/account/create/$#]]></from>
<to>/registrationremove/customer_account/create</to>
</mycompany_registrationremove_customer_account_create>
<mycompany_registrationremove_customer_account_createPost>
<from><![CDATA[#^/customer/account/createPost/$#]]></from>
<to>/registrationremove/customer_account/createPost</to>
</mycompany_registrationremove_customer_account_createPost>
</rewrite>
</global>
<frontend>
<routers>
<mycompany_registrationremove>
<use>standard</use>
<args>
<module>Mycompany_Registrationremove</module>
<frontName>registrationremove</frontName>
</args>
</mycompany_registrationremove>
</routers>
</frontend>
</config>
In the above example structure, the controller class name should be changed
from
class Mycompany_Registrationremove_AccountController extends Mage_Customer_AccountController
to
class Mycompany_Registrationremove_Customer_AccountController extends Mage_Customer_AccountController
Does this method works for ver. 1.4.1.1?
Finally I decided to skip all the complicated steps and also modify the register.phtml in \app\design\frontend\base\default\template\customer\form, apart from the files that BenV said.
I deleted the form and changed the title to "User registration disabled" :)
I couldn't get any of the solutions posted here to work, and found I had to use the following syntax in the config.xml (specifically frontend routers syntax):
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Registrationremove>
<version>0.1.0</version>
</Mycompany_Registrationremove>
</modules>
<global>
<rewrite>
<mycompany_registrationremove_customer_account_create>
<from><![CDATA[#^/customer/account/create/$#]]></from>
<to>/registrationremove/customer_account/create</to>
</mycompany_registrationremove_customer_account_create>
<mycompany_registrationremove_customer_account_createPost>
<from><![CDATA[#^/customer/account/createPost/$#]]></from>
<to>/registrationremove/customer_account/createPost</to>
</mycompany_registrationremove_customer_account_createPost>
</rewrite>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<Mycompany_Registrationremove before="Mage_Customer">Mycompany_Registrationremove_Customer</Mycompany_Registrationremove>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
There's more info on this method here - http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_overload_a_controller
One could always change the customer router to point to a module without controllers, e.g.
<frontend>
<routers>
<customer>
<args>
<module>MyModule_NullRouting</module>
</args>
</customer>
</routers>
</frontend>
As an extension to liquidity's answer, a couple more changes I'd make to improve this. Firstly the regex doesn't match the url if it does not have a trailing slash eg. customer/account/create. To correct, the "from" nodes should read <![CDATA[#^/customer/account/create(/.*)?$#]]> and <![CDATA[#^/customer/account/createPost(/.*)?$#]]>.
Secondly, I've included an observer that listens for the customer_registration_is_allowed event (this gets called in persistent/customer/form/login.phtml when using the RWD theme from the $this->helper('customer')->isRegistrationAllowed() function):
<events>
<customer_registration_is_allowed>
<observers>
<your_module_set_is_active>
<class>Your_Module_Model_Observers_Customer</class>
<method>disableCustomerRegistration</method>
</your_module_set_is_active>
</observers>
</customer_registration_is_allowed>
</events>
Then in the observer:
class Your_Module_Model_Observers_Customer
{
/**
* Force disable customer registration
*
* #param Varien_Event_Observer $observer Observer
* #return void
*/
public function disableCustomerRegistration($observer)
{
$result = $observer->getResult();
if ($result->getIsAllowed() === true) {
$result->setIsAllowed(false);
}
}
}
This sets allowing registration to false and prevents the registration form showing without any template modifications.
Hope this is helpful!