change my account menu position in magento - php

I have created custom module which added link in Left navigation menu of My Account Page. Every things is handle By modules Layout.xml.
But My Module link is appeared at Last in position i.e after News letter Subscription. I want to add this after "My Order" Menu.
How can I do this. Please help me.
Thanks
Pravin

In the XML file you can set your block to come before or after another block.
In the layout XML file add the following attribute to the block:
before="name_of_block"
Or:
after="name_of_block"
So your line would look something like this:
<block type="some/type" before="some_other_block_name" template="some/path/to/template.phtml" />
If you want it to come before any other block (or after every other block) use the following:
before="-"
Or:
after="-"

Related

How do I access methods like $this->getChildHtml() in other directories/pages in Magento?

All I want to do is move a search box. This search box is currently displayed in the header, directly next to the logo, and is generated by the following code:
<?php echo $this->getChildHtml('topSearch') ?>
in /app/design/frontend/MYTHEME/default/template/page/html/header.phtml
I would like this search box inline with the navigation links, which are located in top.phtml which is located in another directory. But when I use the code
<?php echo $this->getChildHtml('topSearch') ?>
the search box does not appear. I understand that this is because the meaning of $this has changed, but what I don't understand is how to display the search box? What do I replace $this with?
I tried replacing it with Mage_Page_Block_Html_Header since that was the definition of $this in header.phtml, but to no avail. Can anybody point me in the right direction, or provide an explanation as to how I access methods once the definition of $this has changed?
You need to make layout update and include block topSearch into block containing top.phtml.
Look into app/design/frontend/.../layouts/...xml files, find how topSearch is declared and then find where the block using top.phtml template is declared. Then move topSearch block as a child of top block. I mean add layout xml update like this:
<default>
<reference name="catalog.topnav">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
</default>
Another solution is try next in your template:
echo $this->getLayout()->getBlock('top.search')->toHtml()
If it would not work then find in layouts topSearch block and try to use in code above name of block instead of alias.
You can read more about Magento view level here: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/designing-for-magento
Good luck!

Ajax in magento (load product view block)

What I want to achieve:
Clicking on a product link/image (at least in certain areas) to open a pop-up with the full product information (basically all the contents of the product view page).
What I did/tried so far:
created all the stuff outside the ajax php code (the module, links, templates, rewrites)
created the ajax controller (which can be accessed with a link similar to: http://test.com/index.php/ajaxproductview/ajax/index/id/2 ).
to follow various tutorials ( like this or this ) - that helped me get this far. But I don't want to load my custom block, I want the default product view block(s).
tried to add some code in the indexAction(). It gets there, but the code fails. I don't get any errors/notices/reports, just what it seems like an infinite loop that kills my processor.
$body = $this
->getLayout()
->createBlock('product.info') // taken from catalog.xml
->toHtml();
$this->getResponse()->setBody($body);
All the other pages work fine, and it's a fresh magento with only magneto and my module installed and activated.
My AJAX function simply gets this HTML response, puts it into a div, and opens a pop-up.
My question(s) is(are) - how can I set the product id, so the block knows what product to load, and how can I load this block correctly. I also tried something similar to this:
Thank you.
PS: I also tried this:
$layout = $this->getLayout();
$update = $layout->getUpdate();
$update->load('catalog_product_view');
$layout->generateXml();
$layout->generateBlocks();
$output = $layout->getOutput(); // $output is an empty string
The Product controller uses a helper to set the active product. You should be able to do the same in your controller!
Try this before you do your layouting:
$productId = (int) $this->getRequest()->getParam('id');
Mage::helper('catalog/product')->initProduct($productId, $this);
Another thing to be aware of:
If you add a block like the product.info block. It needs additional child blocks if it calls them in its template file.
It would be easiest to use a custom layout xml file. You can then add a specific layout for your action handle (your action handle consists of your routers node in your module's etc/config.xml file under <frontend><routers>, e.g. <Yourmodule> node, make sure to lowercase it! And then with underscores add the controller name and action name, in your case index_index) like this:
<yourmodule_index_index>
<remove name="right"/>
<remove name="left"/>
<block type="catalog/product_view" name="root" output="toHtml" template="catalog/product/view.phtml">
<!-- Add all the child blocks you need -->
</block>
</yourmodule_index_index>
This makes the view.phtml the root block which renders itself using its toHtml method.
Therefore, in your controller action, all you need is my two lines above and then:
$this->loadLayout();
$this->renderLayout();

Magento Contact form in phtml file of custom created widget

I'm developing a widget for Magento, in this widget i need to load the magento contact form. I've tried several options, but none of them seem to work.
the widget is located in
app/
code/
local/
CompanyName/
WidgetName/
and the phtml files are located in
app/
design/
frontend/
default/
default/
template/
templatename/
templatefile1.pthml
templatefile2.pthml
templatefile3.phtml
to load the magento contact form i've added this in templatefile3.phtml
<?php echo $this->getChildHtml('contactForm') ?>
but it's not showing up, even after adding xml to 2 files, i've added this line into app/design/frontend/base/default/layout/catalog.xml, right below <reference name="content">
<block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"/>
and also added this code to app/design/frontend/base/default/layout/default.xml (this file didn't even exist)
<default>
<cms_page>
<reference name="content">
<block type="core/template" name="contactForm" as="contactForm" template="contacts/form.phtml">
<action method='setBlockId'><block_id>contactForm</block_id></action>
</block>
</reference>
</cms_page>
I have the idea i'm not putting the xml in the right files, but i have no idea witch files to use otherwise, and can't find any other tips than these two on the internet.
Can someone help me out?
You can add the contact form to any CMS page using CMS tags like this inside the CMS content box:
{{block type="core/template" name="contactForm" template="contacts/form.phtml"}}
You could create a new page, and then inssert that snippet to show the contact form on this new page.
you could also make a copy of form.phtml and modify it for your needs, and update the tag code to use the new template.
Please use the following function to display inside templates.
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Magento_Contact::form.phtml")->toHtml(); ?>
You can't just create a default.xml - to let Magento know that that a layout xml file exists you'd have to go through and create a module and specify the layout file's location. that is a very long winded way round of trying to achieve what you need.
Also I believe the handle <cms_page> is not supported. Referencing a block in a CMS page is best done by placing your xml in the layout update section under the 'design' tab for that CMS page.
So it's fairly straight forward to put the contact form into a CMS page - again use the layout update facility. Simply enter the following xml...
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
Note you don't need a layout handle - Magento already knows of course the specific CMS page you are inserting content into because this is a layout update for that page. So in the above you are just referencing the structural block you want to add to (in this case content) and telling Magento to add the contactForm block along with its associated template location.
I've worked on a site using this method before. you will likely find that once you have called the contactform into your CMS page, and despite appearing successfully in a browser, the form doesn't actually post. In fact the form will only send if used from the intended page yoursite.com/contacts
Simple fix. Create the file app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/form.phtml and duplicate the required content from the default form.phtml into it.
Change the script at the bottom of the form.phtml file from:
<script type="text/javascript">
var contactForm = new VarienForm('contactForm', true);
</script>
To:
<script type="text/javascript">
elem = $("contactForm");
elem.writeAttribute('action', '/contacts/index/post');
</script>
And your CMS page contact form will now post as required.
Just as an addition (you may or may not find this useful).
I had a need for the contact form on my CMS page to be different from the standard form which appears on contacts. This is really simple too using the method above.
Duplicate the file app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/form.phtml and rename as something like app/design/frontend/YOUR-PACKAGE/YOUR-THEME/template/contacts/customForm.phtml - then make your required amends like different fields etc...
now in the layout update for the CMS page you want it to appear in simply add the following xml:
<reference name="content">
<block type="core/template" name="customContactForm" template="contacts/customForm.phtml"/>
</reference>
And that's it.
Note how the block name has changed - the block name can literally be anything - Magento doesn't care what you call it but I would obviously recommend something logical!

Magento catalog - Duplicate category using static block

In the web-shop i'm creating we want the customers to see the category new as they are landing in the shop.
Our configuration in the whole catalog is an layout of 4 items next to each other, like below:
four items in one row
*sorry i am not yet allowed to post pictures :(
I've made an static block in Magento using the following code:
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" category_id="7" template="catalog/product/list.phtml"}}
But when i call this block at the place I wan't it to display, it does not use the correct layout:
3 items in one row, two rows
*sorry i am not yet allowed to post pictures :(
It only put's 3 items next to each otter. I've already tried tweaking the css but that's not the problem. The page code shows that it is put in another row:
<ul class="products-grid first odd"> (the first row)
<ul class="products-grid last even"> (the second row)
My guess is that when i call the block it sets the display to 3 items a row, but i can't figure out where that configuration is located.
Way 1:
for you to use modificated template catalog/product/list.phtml
Create new template from this one and call it list-home.phtml and where you have grid mode view you must have something like this:
<?php $_columnCount = $this->getColumnCount(); ?>
replace this with
<?php $_columnCount = 4; ?>
Way 2: Add this block via layout or custom layout in admin area and add to it params like:
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
Sorry - second way would not work via static block - you can add this w/o static block directly in Layout Update XML in CMS home page, also I don't understand for what you using static block for this if you can add this code for block directly in CMS Page content too

Change position of currency selector in Magento

Currently, the currency selector is at the top, here’s my development site:
http://nordschleife.metaforix.net/118/118/index.php/kyocera.html
However, I would like to switch the currency selector to just under “Price” heading of the table.
I tried
echo $this->getCurrency();
but there’s nothing. I guess I need some method like getCurrencyHtml(), but it seems that there’s no such a method.
Or must I edit layout files, and how should I go about doing this?
I can show you a way to do this, but in order to understand what's going on, you'll need to have at least a basic grasp of how Magento's layout files work. For that you should read the designer's guide here and a basic explanation of how it all works here.
Now there are several way of handling this, but I think the easiest way is to simply use the existing currency block. Seeing as you'll be putting it in that tiny cell I assume you wont be needing the "Select your Currency" headline. So we'll need a new template.
A block in Magento consists of two files, a block class that does all the work of generating dynamic content and a template file which uses the block class' methods along with some html to create the final result. The heavy lifting of getting the currency options is already done by the block class so if we can use that paired with a new template file we'll be set.
The existing declaration in the layout files and specifically directory.xml is
<block type="directory/currency" name="currency" before="catalog.leftnav" template="directory/currency.phtml"/>
So the template file is app\design\frontend[interface][theme]\template\directory\currency.phtml
Copy that to currency2.phtml and in there remove the heading.
Now to create a new block named "currency2" consisting of the old block class and the new template file we write
<block type="directory/currency" name="currency2" as="currency2" template="directory/currency2.phtml"/>
We'll be using that in /template/catalog/product/list.phtml so open catalog.xml and put the new block declaration under
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
in the appropriate section (I assume catalog_category_default).
Finally open /template/catalog/product/list.phtml and add
<?php echo $this->getChildHtml('currency2'); ?>
where you want the block to appear.

Categories