Magento: loading frontent layout - magento

I have a module in app/code/community/Foo/Bar/. Now, I wrote most of it, but I have a problem adding a into head on every page. My config.xml:
<?xml version="1.0"?>
<config>
<modules>
<FooBar_BrowserSearch>
<version>0.1.0</version>
</FooBar_BrowserSearch>
</modules>
<global>
<helpers>
<browsersearch>
<class>FooBar_BrowserSearch_Helper</class>
</browsersearch>
</helpers>
</global>
<frontend>
<layout>
<updates>
<mmbrowsersearch>
<file>browsersearch.xml</file>
</mmbrowsersearch>
</updates>
</layout>
</frontend>
<default>
<bs_general>
<bs_general_settings>
<bs_shortname>My Store Search</bs_shortname>
<bs_description>My default search plugin description</bs_description>
<bs_contact>admin#mysite.com</bs_contact>
</bs_general_settings>
</bs_general>
</default>
</config>
then, I've created /app/design/frontend/base/default/layout/browsersearch.xml, like so:
<layout version="0.1.0">
<browsersearch>
<reference name="head">
<action method="addLinkRel">
<rel>search</rel>
<href>myfile.xml</href>
</action>
</reference>
</browsersearch>
</layout>
but the

I've just changed <browsersearch> into <default>, and it works.

Related

how call custom module block in template file using layout configration file in magento

friends
i have created custom module ,in which i have crated blocks .i want use this block in template but this is not work.
This is my config file :-
<?xml version="1.0"?>
<config>
<modules>
<CustomModule_SocialLogin>
<version>1.0.0</version>
</CustomModule_SocialLogin>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<CustomModule_SocialLogin before="Mage_Customer">CustomModule_SocialLogin_Customer </CustomModule_SocialLogin>
</modules>
</args>
</customer>
<sociallogin>
<use>standard</use>
<args>
<module>CustomModule_SocialLogin</module>
<frontName>sociallogin</frontName>
</args>
</sociallogin>
</routers>
<layout>
<updates>
<CustomModule_SocialLogin module="CustomModule_SocialLogin">
<file>CustomModule/sociallogin.xml</file>
</CustomModule_SocialLogin>
</updates>
</layout>
</frontend>
<global>
<blocks>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Block</class>
</CustomModule_SocialLogin>
</blocks>
<models>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Model</class>
</CustomModule_SocialLogin>
</models>
<helpers>
<CustomModule_SocialLogin>
<class>CustomModule_SocialLogin_Helper</class>
</CustomModule_SocialLogin>
</helpers>
</global>
</config>
My block file -:
class CustomModule_SocialLogin_Block_Qa extends Mage_Core_Block_Template{
public function getText()
{
$name='test';
return $name;
}
}
custom module layout update file :-
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="custommodule_sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
</layout>
my template file :-
<?php
echo $this->getText()->toHtml();
//echo $this->getText();
?>
Please help me to solve this error .
You need to correct your module layout file. I have corrected the block type.
<layout version="0.1.0">
<default>
<reference name="content" translate="label">
<block type="sociallogin/qa" name="SocialLogin.qa" template="CustomModule/SocialLogin/questionans.phtml" />
</reference>
</default>
In template file :-
<?php
echo $this->getText();
?>

Show icon on product on each page

I'm using custom block to show my module logo over each product, now since catalog_product_view tag it shows the logo at product details page only, the problem is that I want to show the icon on each page on each product, whether it is home page, product list, detail, etc. how to achieve this using blocks
Here is the code
Module Configuration (app\etc\modules\NS_Mymodule.xml)
<config>
<modules>
<NS_Mymodule>
<active>true</active>
<codePool>community</codePool>
</NS_Mymodule>
</modules>
</config>
Configuration XML (app\code\community\NS\Mymodule\etc\config.xml)
<config>
<modules>
<NS_Mymodule>
<version>1.0.1</version>
</NS_Mymodule>
</modules>
<global>
<helpers>
<Mymodule>
<class>NS_Mymodule_Helper</class>
</Mymodule>
</helpers>
<blocks>
<mymodule>
<class>NS_Mymodule_Block</class>
</mymodule>
</blocks>
</global>
<frontend>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
</config>
Block Class ( app\code\community\NS\Mymodule\Block\Showicon.php )
class Ns_Mymodule_Block_Showicon extends Mage_Core_Block_Template
{
public function myfunction()
{
return "Hello tuts+ world";
}
}
Layout XML ( app\design\frontend\rwd\default\layout\mymodule.xml)
<layout version="1.0.1">
<catalog_product_view>
<reference name="product.info">
<block type="mymodule/showicon" as="ns_media" name="mymodule_showicon" template="mymodule/showicon.phtml" />
</reference>
</catalog_product_view>
</layout>
Template File (app\design\frontend\rwd\default\template\mymodule\showicon.phtml)
<h1>SHOW ICON HERE</h1>
and in the app\design\frontend\rwd\default\template\catalog\product\view.phtml
<?php echo $this->getChildHtml('ns_media') ?>
right after
<?php echo $this->getChildHtml('media') ?>

magento ajax not working on frontend

I created a block path is : local\Attribute\Layout\Controllers\ProductController code is
class Attribute_Layout_ProductController extends Mage_Core_Controller_Front_Action
{
public function ajaxDataAction()
{
echo 'ajax controller';
}
}
And in etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Attribute_Layout>
<version>0.0.1</version>
</Attribute_Layout>
</modules>
<global>
<blocks>
<attribute_layout>
<class>Attribute_Layout_Block</class>
</attribute_layout>
</blocks>
</global>
<frontend>
<routers>
<layout>
<use>standard</use>
<args>
<module>Attribute_Layout</module>
<frontName>layout</frontName>
</args>
</layout>
</routers>
<layout>
<updates>
<attribute_layout module="Attribute_Layout">
<file>attribute_layout.xml</file>
</attribute_layout>
</updates>
</layout>
</frontend>
</config>
And design\frontend\default\shirt_cust\layout\attribute_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="1.0">
<default>
<attribute_layout_product_ajaxData>
<block type="layout/product" name="root" output="toHtml" template="attribute_layout/product.phtml" />
</attribute_layout_product_ajaxData>
</default>
</layout>
And ajax template in design\frontend\default\shirt_cust\template\product.phtml
$.ajax({
url:'<?php echo $this->getUrl('layout/product/ajaxData') ?>',
type:'post',
data: {id:31},
success:function(result) {
$('#res_html').html(result);
}
});
My ajax url in local localhost/shirt/layout/product/ajaxData is working fine
but not working in my server. path is: 162.144.13.7/o/tailorcustmize/layout/product/ajaxData
Getting 404 error
I tried anything but didn't find any solution please help me to solve this problem
What is the problem in this code please suggest anything. My server is linux.
etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Attribute_Layout>
<version>0.0.1</version>
</Attribute_Layout>
</modules>
<frontend>
<routers>
<layout>
<use>standard</use>
<args>
<module>Attribute_Layout</module>
<frontName>layout</frontName>
</args>
</layout>
</routers>
<layout>
<updates>
<layout>
<file>attribute_layout.xml</file>
</layout>
</updates>
</layout>
</frontend>
<global>
<blocks>
<layout>
<class>Attribute_Layout_Block</class>
</layout>
</blocks>
</global>
</config>
And design\frontend\default\shirt_cust\layout\attribute_layout.xml
<?xml version="1.0"?>
<layout version="0.0.1">
<layout_product_ajaxData>
<block type="layout/product" name="root" output="toHtml" template="attribute_layout/product.phtml" />
</layout_product_ajaxData>
</layout>

error 404 in user's my account magento

I am creating a module for creating new tab in User's myaccount. I have successfully added a tab named "My Special Products".
Problem is that when i click on that tab it's redirect to 404 error page. I am not able to getting the problem.
My layout xml(customtabs.xml) code is:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account>
<!-- Mage_Review -->
<reference name="customer_account_navigation" before="-" >
<action method="addLink" translate="label" module="customer">
<name>newtab</name>
<url>customer/newtab/</url>
<label>My Special Products</label>
</action>
</reference>
</customer_account>
<customer_account translate="label">
<label>Customer My Special Products</label>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customer_account>
</layout>
My template page is at template\customer\newtab\newtab.phtml
My config.xml for module "Customtabs" is :
<?xml version="1.0"?>
<config>
<modules>
<Fishpig_Customtabs>
<version>0.1.0</version>
</Fishpig_Customtabs>
</modules>
<global>
<blocks>
<customtabs>
<class>Fishpig_Customtabs_Block</class>
</customtabs>
</blocks>
<models>
<customtabs>
<class>Fishpig_Customtabs_Model</class>
</customtabs>
</models>
<helpers>
<customtabs>
<class>Fishpig_Customtabs_Helper</class>
</customtabs>
</helpers>
</global>
<frontend>
<layout>
<updates>
<customtabs>
<file>Customtabs.xml</file>
</customtabs>
</updates>
</layout>
</frontend>
<adminhtml>
<layout>
<updates>
<customtabs>
<file>customtabs.xml</file>
</customtabs>
</updates>
</layout>
<events>
<catalog_product_save_after>
<observers>
<fishpig_save_product_data>
<type>singleton</type>
<class>customtabs/observer</class>
<method>saveProductTabData</method>
</fishpig_save_product_data>
</observers>
</catalog_product_save_after>
</events>
</adminhtml>
</config>
Any one can help me where is the problem.
You set url for this tab as <url>customer/newtab/</url>
so, you should have controller of newtab somewhere,
First you need to add <routers> part in your module's config.xml, put this in <frontend>.
<routers>
<customtabs>
<use>standard</use>
<args>
<module>Fishpig_Customtabs</module>
<frontName>customtabs</frontName>
</args>
</customtabs>
</routers>
change <url>customer/newtab/</url> to <url>customtabs/newtab</url> in customtabs.xml file.
also put,
<customtabs_newtab_index>
<update handle="customer_account"/>
<reference name="my.account.wrapper">
<block type="customer/newtab_newtab" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml"/>
</reference>
</customtabs_newtab_index>
create a controller at code/local/Fishpig/Customtabs/controllers/NewtabController.php
in that your code should be
class Fishpig_Customtabs_NewtabController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
if(!Mage::getSingleton('customer/session')->isLoggedIn())
{
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
return false;
}
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->getLayout()->getBlock('head')->setTitle($this->__('My Special Products'));
$this->renderLayout();
}
}
Add a block file as app/code/local/Fishpig/Customtabs/Block/Customtabs.php
and put there code,
class Fishpig_Customtabs_Block_Customtabs extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function getCustomtabs()
{
if (!$this->hasData('customtabs')) {
$this->setData('customtabs', Mage::registry('customtabs'));
}
return $this->getData('customtabs');
}
}
and change your block type in your customtabs.xml file
<block type="customtabs/customtabs" name="customer_newtab_newtab" template="customer/newtab/newtab.phtml" />

Magento 1.6.2 - Problems overriding contacts controller

Ok so I've setup a new module to override the Contacts controller so that I can add a newsletter sign up option to it. My setup is as follows:
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_Contacts_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
error_log('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<mynamespace_ContactsPlus>
<version>0.1.0</version>
</mynamespace_ContactsPlus>
</modules>
<global>
<rewrite>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/index/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
</rewrite>
</global>
<frontend>
<routers>
<mynamespace_contactsplus>
<use>standard</use>
<args>
<module>mynamespace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</mynamespace_contactsplus>
</routers>
</frontend>
</config>
/app/etc/modules/MyNamespace_All.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNamespace_ContactsPlus>
</modules>
</config>
THe module appears in the admin modules list and it has produced the following error on my /contacts/ page:
Fatal error: Call to a member function setFormAction() on a non-object in /srv/www/foo.com/app/code/core/Mage/Contacts/controllers/IndexController.php on line 54
That's this line:
$this->getLayout()->getBlock('contactForm')->setFormAction( Mage::getUrl('*/*/post') );
I'm not sure where to go from here though, a guess is that it can't set the form action on whatever is being returned from Mage::getUrl('//post') but I'm clutching at straws tbh.
Any help of advice would be greatly appreciated!
Ok after much research, help and general frustration here is how I got it working:
First up, my module directory is set out as follows (note the caps on the directories):
/app/code/local/MyNamespace/ContactsPlus/etc/
config.xml
/app/code/local/MyNamespace/ContactsPlus/controllers/
IndexController.php
/app/code/local/MyNamespace/ContactsPlus/Helper/
Data.php
Now for the config files:
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<version>0.1.0</version>
</MyNameSpace_ContactsPlus>
</modules>
<frontend>
<routers>
<!-- Creates route to my module via /contactsplus/ - I used this for testing -->
<contactsplus>
<use>standard</use>
<args>
<module>MyNameSpace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</contactsplus>
<!-- Sets Mage_Contacts route to MyNameSpace_ContactsPlus -->
<contacts>
<args>
<modules>
<MyNameSpace_ContactsPlus before="Mage_Contacts">MyNameSpace_ContactsPlus</MyNameSpace_ContactsPlus>
</modules>
</args>
</contacts>
</routers>
<!-- Sets layout config file (essential for this to work) -->
<layout>
<updates>
<contactsplus>
<file>contactsplus.xml</file>
</contactsplus>
</updates>
</layout>
</frontend>
<global>
<!-- Sets a helper class for the module, when overriding contacts this is also essential. -->
<helpers>
<contactsplus>
<class>MyNameSpace_ContactsPlus_Helper</class>
</contactsplus>
</helpers>
</global>
</config>
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
//die('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/Helper/Data.php:
<?php
class MyNameSpace_ContactsPlus_Helper_Data extends Mage_Core_Helper_Abstract
{
}
/app/etc/modules/MyNamespace_ContactsPlus.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_ContactsPlus>
</modules>
</config>
/app/design/frontend/mythemepackage/mytheme/layout/contacts.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contacts_index_index translate="label">
<!-- had to comment this out in order to prevent a duplicate form issue, if anyone has a better method for this then I'd love to here it :)
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
-->
</contacts_index_index>
<!-- added this to rewrite contacts handle to the new modules handle -->
<contacts_index_index>
<update handle="contactsplus_index_index"/>
</contacts_index_index>
</layout>
/app/design/frontend/mythemepackage/mytheme/layout/contactsplus.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contactsplus_index_index translate="label">
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contactsplus/custom_form.phtml"/>
</reference>
</contactsplus_index_index>
</layout>
I also made a copy of /app/design/frontend/mythemepackage/mytheme/template/contacts/form.phtml and placed it in /app/design/frontend/mythemepackage/mytheme/template/contactsplus/ and then modified it to suit my requirements.
Resources I found particularly useful during this process were google, IRC #magento and
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table
http://alanstorm.com
Hope this helps someone else at some point.
Now it's onto adding a newsletter sign up option to my new form!

Resources