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.
Related
I have a widget grid type module, which i want to move into magento system config.
I have added the following into my system.xml:
<config>
<sections>
<customesetup>
<groups>
<serialnumbervalidator>
<label>Serial Numbers</label>
<sort_order>20</sort_order>
<expanded>1</expanded>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_class>complex</frontend_class>
<frontend_model>mymodule/adminhtml_serial</frontend_model>
</serialnumbervalidator>
</groups>
</customesetup>
</sections>
</config>
but apparently it shows nothing. as the Block extends Mage_Adminhtml_Block_Widget_Grid_Container .
If anyone can point me where to look for my answer this would be great (Did searches and did not find anything useful).
You have to modify your config.xml, to show this up in System Configuration section.
<adminhtml>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<YOUR_MODULE translate="title">
<title><![CDATA[MY TITLE]]></title>
<sort_order>2100</sort_order>
</YOUR_MODULE>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
[...]
</adminhtml>
And in your system.xml :
<config>
<tabs>
<YOUR_MODULE_tab translate="label" module="YOUR_MODULE">
<label>YOUR_MODULE</label>
<sort_order>150</sort_order>
<class>container_admin_img</class> /*optionnal*/
</YOUR_MODULE_tab>
</tabs>
<sections>
<customesetup>
<groups>
<serialnumbervalidator>
<label>Serial Numbers</label>
<sort_order>20</sort_order>
<expanded>1</expanded>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<frontend_class>complex</frontend_class>
<frontend_model>mymodule/adminhtml_serial</frontend_model>
</serialnumbervalidator>
</groups>
</customesetup>
</sections>
</config>
Hope this helps.
Take a look at Alan Storm's No Frills Magento Layout book, or on his website : http://alanstorm.com/category/magento
i'm using Magento 1.9.0.1 and right now i am working on a new extension and i want to add new module with tab in the admin panel.
Here is what i've done so far:
/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>
</global>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<vivas>
<title>Vivas - All</title>
</vivas>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</adminhtml>
</config>
Here is what i have in:
/app/code/community/VivasIndustries/SmsNotification/etc/system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<tabs>
<vivas translate="label" module="vivasindustries_smsnotification">
<label>Vivas Extensions</label>
<sort_order>100</sort_order>
</vivas>
</tabs>
<sections>
<vivas translate="label" module="vivasindustries_smsnotification">
<label>Extension Options</label>
<tab>vivas</tab>
<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>
<vivas_group translate="label" module="vivasindustries_smsnotification">
<label>My Extension Options</label>
<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>
<fields>
<vivas_input translate="label">
<label>My Input Field: </label>
<comment>My Comment</comment>
<frontend_type>text</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</vivas_input>
<vivas_select translate="label">
<label>My Dropdown: </label>
<comment>Source model provider Magento's default Yes/No values</comment>
<frontend_type>select</frontend_type>
<sort_order>90</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<source_model>adminhtml/system_config_source_yesno</source_model>
</vivas_select>
</fields>
</vivas_group>
</groups>
</vivas>
</sections>
</config>
Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/Helper/Data.php:
<?php
class VivasIndustries_SmsNotification_Helper_Data extends Mage_Core_Helper_Abstract
{
}
With this done i receive the following error when i open my admin panel:
Fatal error: Class 'Mage_Vivasindustries_Smsnotification_Helper_Data' not found in /home/superweb/public_html/store/app/Mage.php on line 547
When i change the name of the FOLDER SmsNotification to Smsnotification this error is gone, but there is any new tab in the System->Configuration...
So guys can you help me out to create a new tab in the Admin panel ?
Thanks in advance!
You forgot to define the helper alias for your module in config.xml. It should be in the same form as for the models:
<global>
<helpers>
<smsnotification>
<class>VivasIndustries_SmsNotification_Helper</class>
</smsnotification>
</helpers>
...
Also, you have to use the same alias in system.xml when specifying the module used for translation:
module="smsnotification"
To explain what has happened: Magento doesn't find a helper with the alias "vivasindustries_smsnotification", so it falls back to the Mage namespace and the given alias with capitalized letters as module (no, I have never seen a case where this would have been the desired behavior, but this is how it works). This results in Mage_Vivasindustries_Smsnotification_Helper_Data as helper class name which cannot be found.
As a general rule: If Magento tries to load classes from your module with "Mage_" prefix, your module configuration is either incomplete, has errors or is cached with an old version and the configuration cache must be cleared.
I have a module: app/code/local/Namespace/Resize/
so I've included a option to disable/enable an option through Magento admin.
System > Configuration > Namespace > Resize
but when I try to access to this option I always receives an NULL with Mage::getStoreConfig although the option is set to Yes.
Mage::getStoreConfig('resize/settings/enabled', Mage::app()->getStore()->getId());
or
Mage::getStoreConfig('resize/settings/enabled');
returns NULL
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Resize>
<version>0.0.1</version>
</Namespace_Resize>
</modules>
<global>
<helpers>
<resize>
<class>Namespace_Resize_Helper</class>
</resize>
</helpers>
<events>
<catalog_product_save_after>
<observers>
<resize>
<type>singleton</type>
<class>namespace_resize_model_observer</class>
<method>catalog_product_save_after</method>
</resize>
</observers>
</catalog_product_save_after>
</events>
</global>
</config>
system.xml
<?xml version="1.0" ?>
<config>
<tabs>
<resizing module="resize" translate="label">
<label>Resize</label>
<sort_order>100</sort_order>
</resizing>
</tabs>
<sections>
<resize module="resize" translate="label">
<label>Resize</label>
<sort_order>200</sort_order>
<show_in_default>0</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>1</show_in_store>
<tab>resizing</tab>
<groups>
<settings module="resize" translate="label">
<label>Settings</label>
<sort_order>10</sort_order>
<show_in_default>0</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enabled translate="Enable resize">
<label>Enabled</label>
<comment>Backend Resizing</comment>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<show_in_default>0</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>1</show_in_store>
</enabled>
</fields>
</settings>
</groups>
</resize>
</sections>
</config>
adminhtml.xml
<?xml version="1.0" ?>
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<resize>
<title>Resize Settings</title>
</resize>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
helper app/code/local/Namespace/Resize/Helper/Data
<?php
class Namespace_Resize_Helper_Data extends Mage_Core_Helper_Abstract {
}
Module is working fine
Cached is disabled
I'm sure the option is saved because I can see an entry in the database that is updated.
config id | scope | scope id | path | value
785 | stores | 1 | resize/settings/enabled | 1
Anyone can help me what's wrong?
thanks
Use PHP my admin and make sure you setting is saved on core_config_data table
Use this query
SELECT * FROM `core_config_data` where path like "%YOUR_CONFIG_FIELD_NAME%";
and make sure you will find your setting. If not then something is wrong on your module side.
Would you like to rename this tag name in your system.xml file
<tabs>
<resizing module="resize" translate="label">
<label>Resize</label>
<sort_order>100</sort_order>
</resizing>
</tabs>
Replace resizing with resize
and try again.
I am working on creating my very first community extension. It is a very simple one and is already working. I would like to learn how to add my extension to the admin area that will allow the customer to disable or enable it. What do I need to add to my module to be able to do this? Any help would be great!
Here is my code:
app/etc/modules/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Module_Name>
<!-- Whether our module is active: true or false -->
<active>true</active>
<!-- Which code pool to use: core, community or local -->
<codePool>community</codePool>
</Module_Name>
</modules>
</config>
etc/system.xml
<?xml version="1.0"?>
<config>
<sections>
<module translate="label" module="modulename">
<label>Your Module Name</label>
<tab>tab_id_where_you_want_to_add_your_section</tab>
<frontend_type>text</frontend_type>
<sort_order>980</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<modulename>
<label>Your Group Title</label>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<comment translate="label comment">
<label>Your Field Title</label>
<comment>Your Comment</comment>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</comment>
</fields>
</modulename>
</groups>
</your_module>
</sections>
</config>
etc/adminhtml.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<menu>
<modulename translate="title" module="shipping">
<title>Module</title>
<sort_order>15</sort_order>
<children>
<modulename translate="title" module="modulename">
<title>Drop Down Shipping</title>
<sort_order>1</sort_order>
<action>adminhtml/shipping/index</action>
</example>
</children>
</modulename>
</menu>
<layout>
<updates>
<modulename>
<file>shipping.xml</file>
</modulename>
</updates>
</layout>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<modulename translate="title" module="shipping">
<title>Your Module Name</title>
</modulename>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Module_Name>
<version>0.0.1</version>
</Module_Name>
</modules>
<frontend>
<layout>
<updates>
<modulename>
<file>shipping.xml</file>
</modulename>
</updates>
</layout>
</frontend>
<global>
<helpers>
<modulename>
<class>Module_Name_Helper</class>
</modulename>
</helpers>
</global>
</config>
My theme Layout XML File:
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_cart_index>
<reference name="head">
<action method="addCss"><stylesheet>css/module/shipping.css</stylesheet></action>
</reference>
<reference name="checkout.cart.shipping">
<action method="setTemplate"><template>module/shipping.phtml</template></action>
</reference>
</checkout_cart_index>
</layout>
Helper/Data.php
<?php
class Module_Name_Data extends Mage_Core_Helper_Abstract
{
}
It is not quite clear from your question if you want to add node to main admin menu (horizontal one with fly-out sub-menus) or sidebar menu of System\Configuration screen. Below are instructions how to add section, group and field to Magento configuration screen.
First you need the etc/system.xml file to your module:
<?xml version="1.0"?>
<config>
<sections>
<your_module translate="label" module="your_module_shortcode">
<label>Your Module Name</label>
<tab>tab_id_where_you_want_to_add_your_section</tab>
<frontend_type>text</frontend_type>
<sort_order>980</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<groups>
<your_group_name>
<label>Your Group Title</label>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<your_field_name translate="label comment">
<label>Your Field Title</label>
<comment>Your Comment</comment>
<frontend_type>text</frontend_type>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</your_field_name>
</fields>
</your_group_name>
</groups>
</your_module>
</sections>
</config>
And then add the following section to your etc/adminhtml.xml. It adds your newly created section to ACL so you will be able to control admin roles that can access it:
<config>
<acl>
<resources>
<admin>
<children>
<system>
<children>
<config>
<children>
<your_module translate="title" module="your_module_shortcode">
<title>Your Module Name</title>
</your_module>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
</config>
The enable and disable module feature is already exist in System >> Configuration >> ADVANCE >> Advance.
BTW if you want to add Menu in the System >> Configuration page, this article may help you http://alanstorm.com/custom_magento_system_configuration.
And if you got an error, check again whether everything is ok or not.
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.