I'm very new to Magento and I'm trying to add a new tab to the customer view of Magento backend.
I have made a new extension/module for it. Here are some extracts of my etc/config.xml:
<global>
<blocks>
<showidea>
<class>Whatever_Extendcustomer_Block</class>
</showidea>
</blocks>
<!-- ... -->
</global>
<adminhtml>
<layout>
<updates>
<showidea>
<file>whatever_extendcustomer.xml</file>
</showidea>
</updates>
</layout>
</adminhtml>
And here the contents of the whatever_extendcustomer.xml file:
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>extendcustomer_showidea</name>
<block>extendcustomer/adminhtml_customer_showidea</block>
</action>
</reference>
</adminhtml_customer_edit>
Of course this block is existing and it extends the Mage_Adminhtml_Block_Template and implements Mage_Adminhtml_Block_Widget_Tab_Interface.
When I go to details of a customer I get now the error: Wrong tab configuration.
In Magento's error log stands:
exception 'Mage_Core_Exception' with message 'Invalid Blocktype:
Mage_Extendcustomer_Block_Adminhtml_Customer_Showidea' in
/var/www/vhosts/whatever/htdocs/app/Mage.php:594
And I think this is the problem, because Mage_Extendcustomer is wrong. It should be Whatever_ ... but I don't know why it is prepending the Mage_ instead of my Whatever_ namespace.
I hope someone can give me the clue!
Thanks.
You should use showidea instead of extendcustomer in your layout file :
<adminhtml_customer_edit>
<reference name="customer_edit_tabs">
<action method="addTab">
<name>extendcustomer_showidea</name>
<block>showidea/adminhtml_customer_showidea</block>
</action>
</reference>
</adminhtml_customer_edit>
Because it's what you've defined in the blocks config :
<blocks>
<showidea>
<class>Whatever_Extendcustomer_Block</class>
</showidea>
</blocks>
Related
I'm creating a simple sample module in magento 1.9 and I am hoping to do display a custom block on the front end product page - through my module; however I have stumbled in trouble early on.
In my modules config.xml I have defined a front end layout update, below as the full config.xml file
<?xml version="1.0"?>
<config>
<modules>
<MP_SampleModule>
<version>0.0.1</version>
</MP_SampleModule>
</modules>
<frontend>
<layout>
<updates>
<MP_SampleModule>
<file>samplemodule.xml</file>
</MP_SampleModule>
</updates>
</layout>
</frontend>
</config>
I have confirmed the module is loading.
For the layout file, I created samplemodule.xml :
\app\design\frontend\rwd\default\layout\samplemodule.xml
rwd is my active theme.
the samplemodule.xml contents are as follows:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<action method="setTitle">
<rel>DID THIS WORK??</rel>
</action>
</reference>
</default>
</layout>
However it seems Magento is not picking up this file at all. I have tried placing invalid xml in the samplemodule.xml in the hope Magento would throw an error confirming it is at least being loaded, but as no error is thrown I'm lead to believe it is simply being ignored.
I've read countless other similar questions on SO and on other sites but i've hit a brick wall so any insight into the issue would be welcomed and anything leading to a solution would be applauded.
Thanks
After a few days of not making any progress with this, I decided to try again. In the end I changed the contents of my files to the following which seems to have done the trick:
\app\code\community\MP\SampleModule\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<MP_SampleModule>
<version>0.0.1</version>
</MP_SampleModule>
</modules>
<frontend>
<layout>
<updates>
<MP_SampleModule module="MP_SampleModule">
<file>mp_samplemodule.xml</file>
</MP_SampleModule>
</updates>
</layout>
</frontend>
</config>
\app\design\frontend\base\default\layout\mp_samplemodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="before_body_end">
<block type="core/template"
name="test"
template="mp/samplemodule/test.phtml"/>
</reference>
</default>
</layout>
This now correctly outputs contents of test.phtml (\app\design\frontend\base\default\template\mp\samplemodule\test.phtml) near the end of the page.
Thanks for all the insights provided which was helpful in finding the solution.
First make sure you are putting it in your theme folder. Second the updates reference the Module Name not its namespace so it would be
<frontend>
<layout>
<updates>
<Sample_Module>
<file>samplemodule.xml</file>
</Sample_Module>
</updates>
</layout>
</frontend>
Then try adding this: <layout version="0.1.0"> instead of layout. Then add this:
<default>
<reference name="head">
<action method="setTitle"><rel>DID THIS WORK??</re></action>
</reference>
</default>
this will set the title of every page.
Other things to check: is the module being loaded?
I need to call an alternate js/prototype1_6_0_3.js file into my admin only, and keep the original js/prototype.js for the user/customer front-end. I had to qickly upgrade the original js/prototype.js file to 1.7.0.1 b/c of an issue that popped up when IE10 did one of its auto-updates.
Currently my extension causes the admin to be mostly blank and very broken.
can someone point out what I'm doing wrong.
thanks.enter code here
Here is what I'm trying to do:
app\design\adminhtml\default\default\layout\adminprototypeversion.xml
<?xml version="1.0"?>
<layout>
<adminhtml>
<reference name="head">
<action method="removeItem"><type>js</type><name>prototype/prototype.js</name></action>
<action method="addJs"><script>prototype/prototype1_6_0_3.js</script></action>
</reference>
</adminhtml>
</layout>
app\code\local\Alphacard\Adminprototypeversion\etc\config.xml
<config>
<modules>
<Alphacard_Adminprototypeversion>
<version>0.1.0</version>
</Alphacard_Adminprototypeversion>
</modules>
<adminhtml>
<layout>
<updates>
<Adminprototypeversion>
<file>adminprototypeversion.xml</file>
</Adminprototypeversion>
</updates>
</layout>
</adminhtml>
</config>
app\etc\modules\Alphacard_Adminprototypeversion.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Alphacard_Adminprototypeversion>
<active>true</active>`enter code here`
<codePool>local</codePool>
</Alphacard_Adminprototypeversion>
</modules>
</config>
In your app\design\adminhtml\default\default\layout\adminprototypeversion.xml
You should be able to just rename the <adminhtml> node to <default>
Magento already knows it's for "adminhtml" because of the config.xml layout update in your module being declared within the "adminhtml" area.
I want to insert a canonical meta tag in some sites which will be generated by an extension. So I inserted following code in the layout.xml of the extension:
<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href><url helper="core/url/getCurrentUrl"/></href>
</action>
</reference>
But I always just get "Array" instead of the url. What am I doing wrong?
If I will get it work, do I get just the www.mystore.com/productxy.html or the complete url with www.mystore.com/productxy.html?page=3.
Because I only need the first one, without the parameters.
Your code was almost right. Though you can only use the helper attribute in layout xml on the tags directly under the <action> tag. Luckily, you mistakenly added the extra <url> tag, so this should work:
<reference name="head">
<action method="addLinkRel">
<rel>canonical</rel>
<href helper="core/url/getCurrentUrl"/>
</action>
</reference>
Mage_Core_Helper_Url::getCurrentUrl() returns the REQUEST_URI from your $_SERVER variable. That variable includes the query, so unfortunately it's not as usable as you probably thought it would be.
I'm pretty sure you can't do that. You're getting an Array because it's interpreting the <url helper="core/url/getCurrentUrl"/> XML node into an Array. This action processes the function addLinkRel instead and not the <url /> helper at all (never).
The better (and much more fun) way of doing this is by creating a module where you can define a new block type that renders <link rel='canonical' href='{$currentUrl}' />.
Here's how I would do it, and it would take about 4 files:
app/code/community/Electricjesus/Canonical/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Canonical>
<version>0.1.0</version>
</Electricjesus_Canonical>
</modules>
<global>
<blocks>
<canonical>
<class>Electricjesus_Canonical_Block</class>
</canonical>
</blocks>
</global>
</config>
app/code/community/Electricjesus/Canonical/Block/Link.php
<?php
class Electricjesus_Canonical_Block_Link extends Mage_Core_Block_Template {
}
app/design/frontend/base/default/template/canonical/link.phtml
<?php $currentUrl = Mage::helper('core/url')->getCurrentUrl(); ?>
<link rel="canonical" href="<?php echo $currentUrl ?>" />
app/etc/modules/Electricjesus_Canonical.xml
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Canonical>
<active>true</active>
<codePool>community</codePool>
<version>0.1.0</version>
</Electricjesus_Canonical>
</modules>
</config>
So, the way to do it now here is (in your local.xml):
<reference name="head">
<block type="canonical/link" name="canonical_link" template="canonical/link.phtml" />
</reference>
So this is basically just a rough draft I cooked up in a few minutes, I've used the same solution for another kind of problem (but similar scope). So, give it a spin if you want.
i created a new block in my own module of Customer, here's the config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Nauba_Customer>
<version>1.6.2.0.3</version>
</Nauba_Customer>
</modules>
<global>
<resources>
<nauba_customer_setup>
<setup>
<module>Nauba_Customer</module>
</setup>
</nauba_customer_setup>
</resources>
<blocks>
<nauba_customer>
<class>Nauba_Customer_Block</class>
</nauba_customer>
<customer>
<rewrite>
<form_register>Nauba_Customer_Block_Form_Register</form_register>
</rewrite>
</customer>
</blocks>
<models>
<customer>
<rewrite>
<customer>Nauba_Customer_Model_Customer</customer>
</rewrite>
</customer>
</models>
</global>
<frontend>
<routers>
<customer>
<args>
<modules>
<Nauba_Customer before="Mage_Customer">Nauba_Customer</Nauba_Customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
now i'm trying to call it in the home page, so i've specified it in the page.xml layout:
<!-- this is only the home page section -->
<page_homepage translate="label">
<label>Homepage</label>
<reference name="root">
<!--reference name="head">
<action method="removeItem"><type>skin_css</type><name>css/styles.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/styles-ie.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/widgets.css</name></action>
<action method="removeItem"><type>skin_css</type><name>css/print.css</name></action>
</reference-->
<block type="page/html" name="category_links" template="page/html/category_links.phtml" />
<block type="cms/block" name="homepage_slider_image_1" as="homepage_slider_image_1">
<action method="setBlockId"><block_id>homepage_slider_image_1</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_2" as="homepage_slider_image_2">
<action method="setBlockId"><block_id>homepage_slider_image_2</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_3" as="homepage_slider_image_3">
<action method="setBlockId"><block_id>homepage_slider_image_3</block_id></action>
</block>
<block type="cms/block" name="homepage_slider_image_4" as="homepage_slider_image_4">
<action method="setBlockId"><block_id>homepage_slider_image_4</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_1" as="homepage_event_banner_1">
<action method="setBlockId"><block_id>homepage_event_banner_1</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_2" as="homepage_event_banner_2">
<action method="setBlockId"><block_id>homepage_event_banner_2</block_id></action>
</block>
<block type="cms/block" name="homepage_event_banner_3" as="homepage_event_banner_3">
<action method="setBlockId"><block_id>homepage_event_banner_3</block_id></action>
</block>
<block type="nauba_customer/list_ordercrosssell" name="ordercrosssell" as="ordercrosssell" template="nauba_customer/list/ordercrosssell.phtml">
</block>
<action method="setTemplate"><template>page/home.phtml</template></action>
<!-- Mark root page block that template is applied -->
<action method="setIsHandle"><applied>1</applied></action>
<action method="setLayoutCode"><name>page_homepage</name></action>
</reference>
</page_homepage>
but it doesn't work when i call it in the home template with:
($this->getChildHtml('ordercrosssell'))
Also i've tried to create it by:
$this->getLayout()->createBlock('ordercrosssell')
but it raise this exception 'invalid block type'. any help?
The createBlock() method would take in the whole block alias name (nauba_customer/list_ordercrosssell), not just ordercrosssell. The reason that getChildHtml() can take in just ordercrosssell is because the child block's name is defined in the layout xml.
Not totally sure what may be wrong with your layout.xml, but you should probably drop the underscore in your aliases. So instead of nauba_customer just go with naubacustomer or ideally something slightly shorter than that for ease of use.
I'm not 100% sure whether it's a problem or not but in general it's better to follow existing convention as #Herve mentioned with underscores vs. slashes in class aliases, b/c things can get a little hairy.
In some cases (Magento 1.9), if we forgot to use construct function in block PHP file then put it and the issue will be fixed:
protected function _construct()
{
parent::_construct();
}
In some other cases (Magento 1.9), if we have wrong file permissions/ownership, we get the same exception. Fixing permission/ownership solved it. Hope it saves someone else a couple of hours ...
I have custom layout for category.
<CATEGORY_8>
<reference name="root">
<action method="setTemplate"><template>page/category_8.phtml</template></action>
</reference>
<reference name="left">
<block type="catalog/category_view" name="catalog.leftnav.within" before="-" template="catalog/layer/within.phtml "/>
</reference>
<reference name="category.products">
<action method="setTemplate"><template>catalog/category/8/view.phtml</template></action>
</reference>
<reference name="catalog.leftnav">
<action method="setTemplate"><template>catalog/layer/view_8.phtml</template></action>
</reference>
<reference name="product_list">
<action method="setTemplate"><template>catalog/product/list_8.phtml</template></action>
</reference>
</CATEGORY_8>
I want create new layout and I want apply this layout for category.
I created new layout
<page_new_new module="page" translate="label">
<label>Layout new</label>
<template>page/category_8.phtml</template>
<layout_handle>page_new_new</layout_handle>
</page_new_new>
How I can setup templates for this layout?
I don't want using "Custom Layout Update" field inside admin.
I want use only "Page Layout" field?
I would insert the layout xml block (your first code part with CATEGORY_8) into design/frontend/*/*/layout/page.xml (your actual frontend design folder, most possibly default/default) and create an extension with a simple config.xml, something like this:
<?xml version="1.0"?>
<config>
<global>
<page>
<layouts>
<page_new_new module="page" translate="label">
<label>Layout new</label>
<template>page/category_8.phtml</template>
<layout_handle>page_new_new</layout_handle>
</page_new_new>
</layouts>
</page>
</global>
</config>
To create an extension just create the folder structure in your app/code/local directory:
YourCompanyName/ModuleNameYouLike/etc
and put this [config.xml] in, you will also need an xml file in app/etc/modules directory:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<YourCompanyName_ModuleNameYouLike>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Page />
</depends>
</YourCompanyName_ModuleNameYouLike>
</modules>
</config>
After refreshing configuration and layout cache you will see Layout new for pages from the Page layout dropdown.