Magento : Overriding Config Controller? - magento

Can any one please tell me how to override config controller in magento. I have attatched my config code below :
<config>
<modules>
<Adodis_Themechooser>
<version>0.1.0</version>
</Adodis_Themechooser>
</modules>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Adodis_Themechooser>
<title>Themechooser Module</title>
<sort_order>10</sort_order>
</Adodis_Themechooser>
<system>
<children>
<config>
<children>
<themechooser>
<title>Themechooser</title>
</themechooser>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<adminhtml>
<rewrite>
<themechooser_config>
<from><![CDATA[#^/admin/system_config/#]]></from>
<to>/themechooser/config/</to>
</themechooser_config>
</rewrite>
</adminhtml>
<models>
<themechooser>
<class>Adodis_Themechooser_Model</class>
</themechooser>
</models>
<helpers>
<themechooser>
<class>Adodis_Themechooser_Helper</class>
</themechooser>
</helpers>
</global>
</config>

An override of the config controller means you will be dealing with all presses of the Save Config button, not just your own themechooser page. That method of override means that no other module could ever make a compatible override of their own, and the "from/to" syntax is outdated anyway. Also an override is not needed at all, you're only interested in the saving of one field and that can be found through a backend_model.
Your module probably has an etc/system.xml file,
<config>
<sections>
<themechooser>
<groups>
<themechooser>
<fields>
<example translate="label">
<label>This is a text field</label>
<frontend_type>text</frontend_type>
<backend_model>themechooser/config_example</backend_model>
<show_in_default>1</show_in_default>
</example>
</fields>
</themechooser>
</groups>
</themechooser>
</sections>
</config>
Note the backend_model. Now make the class that fits themechooser/config_example,
class Adodis_Themechooser_Model_Config_Example extends Mage_Core_Model_Config_Data {
protected function _afterSave() {
$value = $this->getValue();
// $value is the text in the text field
}
}
All that remains is to use $value to set the frontend theme. The field can be any type, it does not have to be text.

Related

Page not found in custom module in magento

Im getting a error of:
404 Error
Page not found.
Everything looks ok, i already cleared cache, logout and login again from the backend and also reset permissions, but still getting this error.
My code:
etc/modules:
Cloud_Freeshipping.xml
<?xml version="1.0"?>
<config>
<modules>
<Cloud_Freeshipping>
<active>true</active>
<codePool>community</codePool>
</Cloud_Freeshipping>
</modules>
</config>
app/code/community/Cloud/Freeshipping/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Cloud_Freeshipping>
<version>1.0.0</version>
</Cloud_Freeshipping>
</modules>
<global>
<helpers>
<cloud_freeshipping>
<class>Cloud_Freeshipping_Helper</class>
</cloud_freeshipping>
</helpers>
</global>
</config>
app/code/community/Cloud/Freeshipping/etc/adminhtml.xml
<?xml version="1.0"?>
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<cloud_freeshipping translate="title">
<title>FreeShipping Notification</title>
</cloud_freeshipping>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
app/code/community/Cloud/Freeshipping/etc/system.xml
<?xml version="1.0"?>
<config>
<tabs>
<cloud_freeshipping translate="label">
<label>Free Shipping Notification</label>
<sort_order>1</sort_order>
</cloud_freeshipping>
</tabs>
<sections>
<cloud_freeshipping translate="label">
<tab>cloud_freeshipping</tab>
<label>Configuration</label>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<basic_config translate="label">
<label>Basic Config</label>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<total_cart translate="label">
<label>Valor de Envio</label>
<frontend_type>text</frontend_type>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<comment>Selecione o total do valor para free shipping</comment>
</total_cart>
</fields>
</basic_config>
</groups>
</cloud_freeshipping>
</sections>
</config>
app/code/community/Cloud/Freeshipping/Helper/Data.php
class Cloud_Freeshipping_Helper_Data extends Mage_Core_Helper_Abstract
{
}
In file app/code/community/Cloud/Freeshipping/etc/adminhtml.xml, try to add <all> tag before <admin> like this:
<?xml version="1.0"?>
<config>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<cloud_freeshipping translate="title">
<title>FreeShipping Notification</title>
</cloud_freeshipping>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
Then logout and login to admin again.

Editing a module seems to have no effect

I am using a module which calculates the shipping method based on item weight. The module appears to install but if I make an edit to the main class, nothing seems to be reflected on the front end.
The main class extends the Mage_Shipping_Model_Carrier_Abstract see below:
<?php
class Laurensmedia_Advancedshipping_Model_Carrier_Advancedshipping
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'advancedshipping';
The config.xml file looks like this:
<?xml version="1.0"?>
<config>
<modules>
<Laurensmedia_Advancedshipping>
<version>0.1.0</version>
</Laurensmedia_Advancedshipping>
</modules>
<global>
<helpers>
<advancedshipping>
<class>Laurensmedia_Advancedshipping_Helper</class>
</advancedshipping>
</helpers>
<blocks>
<advancedshipping>
<class>Laurensmedia_Advancedshipping_Block</class>
</advancedshipping>
</blocks>
<models>
<advancedshipping>
<class>Laurensmedia_Advancedshipping_Model</class>
<resourceModel>advancedshipping_mysql4</resourceModel>
</advancedshipping>
<advancedshipping_mysql4>
<class>Laurensmedia_Advancedshipping_Model_Mysql4</class>
<entities>
<matrix>
<table>advancedshipping_matrix</table>
</matrix>
</entities>
</advancedshipping_mysql4>
<shipping>
<rewrite>
<shipping>Laurensmedia_Advancedshipping_Model_Shipping_Shipping</shipping>
</rewrite>
</shipping>
</models>
<resources>
<advancedshipping_setup>
<setup>
<module>Laurensmedia_Advancedshipping</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</advancedshipping_setup>
<advancedshipping_write>
<connection>
<use>core_write</use>
</connection>
</advancedshipping_write>
<advancedshipping_read>
<connection>
<use>core_read</use>
</connection>
</advancedshipping_read>
</resources>
</global>
<admin>
<routers>
<advancedshipping>
<use>admin</use>
<args>
<module>Laurensmedia_Advancedshipping</module>
<frontName>advancedshipping</frontName>
</args>
</advancedshipping>
</routers>
</admin>
<adminhtml>
<menu>
<advancedshipping module="advancedshipping">
<title>Advancedshipping</title>
<sort_order>100</sort_order>
<children>
<matrix module="advancedshipping">
<title>Manage Matrix</title>
<sort_order>0</sort_order>
<action>advancedshipping/adminhtml_matrix</action>
</matrix>
<import module="advancedshipping">
<title>Import from CSV</title>
<sort_order>1</sort_order>
<action>advancedshipping/adminhtml_matrix/import</action>
</import>
<settings>
<title>Manage Settings</title>
<sort_order>999</sort_order>
<action>adminhtml/system_config/edit/section/lm_advancedshipping</action>
</settings>
</children>
</advancedshipping>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<advancedshipping translate="title" module="advancedshipping">
<title>Advancedshipping</title>
<sort_order>1000</sort_order>
<children>
<matrix translate="title">
<title>Manage Matrix</title>
<sort_order>0</sort_order>
</matrix>
<import translate="title">
<title>Import from CSV</title>
<sort_order>1</sort_order>
</import>
<settings translate="title">
<title>Manage Settings</title>
<sort_order>999</sort_order>
</settings>
</children>
</advancedshipping>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<advancedshipping>
<file>advancedshipping.xml</file>
</advancedshipping>
</updates>
</layout>
</adminhtml>
<default>
<carriers>
<advancedshipping>
<active>1</active>
<model>advancedshipping/carrier_advancedshipping</model>
<name>Advanced Shipping</name>
<title>Laurensmedia</title>
<description>Laurensmedia Advanced Shipping description</description>
<sort_order>0</sort_order>
</advancedshipping>
</carriers>
</default>
</config>
I have tried the following:
Clearing the Magneto cache
Manually deleting the contents of /var/cache/
Copying all of the other modules to ../disabled/ (Effectively
disabling them)
None of the above seems to have worked. Can anyone offer any suggestions as to why when I edit the main class file nothing happens? Even if I deliberately break the file (i.e - delete half the code) I don't even see any errors.
I don't see a <rewrite> declared for Laurensmedia_Advancedshipping_Model_Carrier_Advancedshipping in the config.
That would explain why it's not being picked up, since it appears to want to rewrite a standard Magento class.
If it's not intended as a rewrite, how is that class being called?

How to add some content in menu item admin panel Magento

I have create some menu and his sub menu in admin panel(it displays me a blank page) so i want to add some input then this input I want to do some SQL query (Save text in db), and this text i want to display it in some sms page. I dont know how.
Menu admin panel
W/Testimony/controllers/Adminhtml/TestimonyController.php
class W_Testimony_Adminhtml_TestimonyController extends Mage_Adminhtml_Controller_Action{
protected function _initAction() {
$this->_title($this->__('Paramétrage'))
->_title($this->__('Témoignage'));
$this->loadLayout()
->_setActiveMenu('testimony/parametrage')
->_addBreadcrumb(Mage::helper('adminhtml')->__('testimony'), Mage::helper('adminhtml')->__('testimony'))
->_addBreadcrumb(Mage::helper('adminhtml')->__('Paramétrage'), Mage::helper('adminhtml')->__('Paramétrage'));
return $this;
}
public function indexAction() {
$this->_initAction()
->renderLayout();
}
}
W/Testimony/etc/adminhtml.xml
<config>
<menu>
<testimony translate="title" module="testimony">
<title>Témoignage</title>
<sort_order>100</sort_order>
<children>
<parametrage translate="title" module="testimony">
<title>Paramétrage</title>
<sort_order>1</sort_order>
<action>adminhtml/testimony/index</action>
</parametrage>
</children>
</testimony>
</menu>
W/Testimony/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<W_Testimony>
<version>0.0.1</version>
</W_Testimony>
</modules>
<adminhtml>
<layout>
<updates>
<testimony>
<file>testimony.xml</file> <!-- I dont know what is this file ?-->
</testimony>
</updates>
</layout>
<acl>
<resources>
<admin>
<children>
<testimony>
<title>testimony Menu Item</title>
<children>
<parametrage translate="title" module="testimony">
<title>param Menu Item</title>
</parametrage>
</children>
</testimony>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<models>
<w_testimony>
<class>W_Testimony_Model</class>
</w_testimony>
</models>
<helpers>
<testimony>
<class>W_Testimony_Helper</class>
</testimony>
</helpers>
<blocks>
<w_testimony>
<class>W_Testimony_Block</class>
</w_testimony>
<w_testimony_adminhtml>
<class>W_Testimony_Block_Adminhtml</class>
</w_testimony_adminhtml>
</blocks>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<w_testimony after="Mage_Adminhtml">W_Testimony_Adminhtml</w_testimony>
</modules>
</args>
</adminhtml>
</routers>
</admin>
W/Testimony/Helper/Data.php
class W_Testimony_Helper_Data extends Mage_Core_Helper_Abstract{
}
W/Testimony/Model/Testimony.php
class W_Testimony_Model_Testimony extends Mage_Core_Model_Abstract{
public function _construct() {
$this->_isPkAutoIncrement = false;
$this->_init('w_testimony/testimony');
}
}
You can follow this instruction and create page in admin.
Create Module

Magento - How to create new admin page

I'm using Magento 1.9.0.1 and i've created a new extension in which i've added a new tab in the admin panel take a look at the picture.
Here is what i have in my files.
In: /app/code/community/VivasIndustries/SmsNotification/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<VivasIndustries_SmsNotification>
<version>0.1.0</version>
</VivasIndustries_SmsNotification>
</modules>
<global>
<models>
<smsnotification>
<class>VivasIndustries_SmsNotification_Model</class>
</smsnotification>
</models>
<events>
<sales_order_save_after>
<observers>
<vivasindustries_smsnotification>
<class>smsnotification/observer</class>
<method>orderSaved</method>
</vivasindustries_smsnotification>
</observers>
</sales_order_save_after>
</events>
<helpers>
<smsnotification>
<class>VivasIndustries_SmsNotification_Helper</class>
</smsnotification>
<adminhtml>
<rewrite>
<data>VivasIndustries_SmsNotification_Helper_Adminhtml_Data</data>
</rewrite>
</adminhtml>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/etc/adminhtml.xml:
<?xml version="1.0"?>
<config>
<menu>
<vivassms translate="title" module="smsnotification">
<title>SMS Center</title>
<sort_order>110</sort_order>
<children>
<sendsms translate="title" module="smsnotification">
<title>Send SMS</title>
<action>adminhtml/magesms_sendsms</action>
<sort_order>1</sort_order>
</sendsms>
<settings>
<title>Settings</title>
<action>adminhtml/system_config/edit/section/vivas/</action>
<sort_order>10</sort_order>
</settings>
<about translate="title" module="smsnotification">
<title>About</title>
<action>adminhtml/smsnotification_about</action>
<sort_order>11</sort_order>
</about>
</children>
</vivassms>
</menu>
<acl>
<resources>
<admin>
<children>
<vivassms>
<title>SMS</title>
<children>
<sendsms translate="title" module="smsnotification">
<title>Send SMS</title>
</sendsms>
<settings>
<title>Settings</title>
<children>
<smsprofile translate="title" module="smsnotification">
<title>Edit user account</title>
</smsprofile>
</children>
</settings>
<about translate="title" module="smsnotification">
<title>About</title>
</about>
</children>
</vivassms>
<system>
<children>
<config>
<children>
<vivassms translate="title" module="smsnotification">
<title>Vivas SMS</title>
</vivassms>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
I've added these three children tabs to the created new tab SMS Center but when i click on the About tab i got error 404 ON MY FRONTEND. This is awkward. Why i got redirected to the frontend ?
Can you please help me out to create a simple new custom page in the admin panel where i want to add a simple text?
Thanks in advance!
Seems like Magento recognizes your module is telling it "Check me for admin" controllers, but that Magento doesn't find any. The best way to figure out what Magento thinks your controller file should be named (as well as which folder it should be located in) is to add some temporary debugging to _validateControllerClassName
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
var_dump($controllerFileName); //add this line
return false;
}
This will dump out every file Magento checks for a controller. Look for the line with your module name in it, and compare paths between where your file is located and where Magento thinks it should be located.

Custom Magento Extension Enable and Disable not working

I am simply trying to build an extension that if it is enabled it will override the original cart/shipping.phtml file with my own template file..
When I click on Enable it does not enable the extension. I know the extension actually works b/c if I manually change my layout block theme it works. However, I don't want to do that. Can you please have a look at my code and let me know what I am doing wrong? I am assuming it has something to do with my block file not being right. P.S. if you see what is wrong and how to fix it could you also tell me how to set a CSS file for the extension as well if it is enabled?
Here are all of my files :)
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Module_Name><version>1.0.0</version></Module_Name>
</modules>
<global>
<blocks>
<modulename>
<class>Module_Name_Block</class>
</modulename>
</blocks>
<helpers>
<modulename>
<class>Module_Name_Helper</class>
</modulename>
</helpers>
</global>
<modulename>
<settings>
<enable>1</enable>
</settings>
</modulename>
<frontend>
<layout>
<updates>
<modulename>
<file><!-- shipping.xml --></file>
</modulename>
</updates>
</layout>
<routers>
<modulename>
<use>standard</use>
<args>
<module>Module_Name</module>
<frontName>modulename</frontName>
</args>
</modulename>
</routers>
</frontend>
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<modulename>
<title>Shipping Extension</title>
</modulename>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
etc/system.xml
<?xml version="1.0"?>
<config>
<tabs>
<module translate="label">
<label>Custom Extensions</label>
<sort_order>100</sort_order>
</module>
</tabs>
<sections>
<modulename translate="label">
<label>Shipping</label>
<tab>module</tab>
<frontend_type>text</frontend_type>
<sort_order>1000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<settings translate="label">
<label>Settings</label>
<frontend_type>text</frontend_type>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enable translate="label">
<label>Enable</label>
<comment>
<![CDATA[Enable or Disable this extension.]]>
</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable>
</fields>
</settings>
</groups>
</modulename >
</sections>
</config>
Helper/Data.php
<?php
class Module_Name_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Block/Cart/Shipping.php
<?php
class Module_Name_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Shipping
{
protected function _beforeToHtml()
{
if(Mage::getStoreConfig('modulename/settings/enable'))
$this->setTemplate('module/name/shipping.phtml');
return $this;
}
}
For checking boolean config data it's more appropriate to use Mage::getStoreConfigFlag() [link]. In this case, there's a hook to do just this purely in layout XML without the need to do a block class rewrite.
Configure a custom layout update file for your module, and in that file simply do the following:
<?xml version="1.0"?>
<layout>
<checkout_cart_index>
<action method="setTemplate" block="checkout.cart.shipping" ifconfig="dropdownshipping/settings/enable">
<template>beckin/dropdownshipping/drop_down_shipping.phtml</template>
</action>
<action method="addCss" block="head" ifconfig="dropdownshipping/settings/enable">
<template>css/beckin/dropdownshipping.css</template>
</action>
</checkout_cart_index>
</layout>
As long as your module is also configured with <depends /> on the Mage_Checkout this layout XML update will be merged in after the core instruction, thus overriding the core template.
The only reason to take the approach which you have taken is to thoroughly force that the template will be set to your module's template just prior to rendering - thereby overriding any potential conflicting layout XML instruction - assuming that there is no cache hit, a behavior which is ... debatable.

Resources