rearrange product blocks - magento

I have 3 questions that my normal Googling efforts haven't answered. I'm a in-house front end web developer that has been trying to learn Magento for the past two weeks. I'm also new to posting on Stack Overflow, so let me know if these would be better posted as separate questions or something.
1. Layouts - Making it so every single page uses the same layout
So most of my pages are using my 2columns-left layout, but not all of them. I have some set in my local.xml, and some I just hard coded in the .phtml pages directly. I would have thought the following code would make ALL pages use the same layout:
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
<action method="setIsHandle">
<applied>1</applied>
</action>
</reference>
There are a lot of pages I don't normally see when I work on the site that are stuck with the default Magento layouts, like the /cookies-enabled page, or the review pages. What's the best practice for unifying all pages if you want the same layout on the entire site, rather than having a block like this in local.xml for every single page?
2. Contact Us Form - Clicking the submit button doesn't work
I am editing the contact us page under CMS>Pages, and I think I am possibly missing the file that my form action is pointing to. The form shows up, but it doesn't submit.
Here is what I have on our Contact Us CMS page:
{{block type='core/template' name='contactForm' form_action="/contacts/index/post/" template='contacts/form.phtml'}}
Here's the error I get after clicking the submit button:
Not Found
The requested URL /contacts/index/post/ was not found on this server.
I've gone through the configuration settings and I think those are right, but maybe there is something else I have to do there.
3. Product Reviews - Getting an "Overall" rating to display
I have the review div that utilizes form.phtml showing up on my product pages after you login and add a review, but the ratings aren't being shown. I am apparently not satisfying the conditions of an if statement that controls if the ratings should be displayed. Below is the if statement that it is getting caught on I believe:
<?php if( $this->getRatings() && $this->getRatings()->getSize()): ?>
I'm not sure how to satisfy these conditions.
4. Rearranging Blocks - Using local.xml to rearrange where blocks are going
Before I start developing bad habits, I want to make sure I'm using best practices from the get go. I've typically just gone into the template files and manually move where stuff was appearing in the phtml, but I've heard it's best to make those changes in the XML. One particular issue I can't seem to figure out is a seemingly simple one: How do I make the "Proceed to Checkout" button move to the bottom of the cart?
I'm trying to unset it then re-set it after the other blocks. I haven't even been able to get the unsetChild part to work. Here is my code from local.xml:
<reference name="content">
<action method="unsetChild">
<name>checkout.cart.top_methods</name>
</action>
</reference>
I think the reason this isn't working is because in checkout.xml it's the child of a child. Here's the general flow of the checkout.xml:
<checkout_cart_index>
<reference name="content">
<block name="checkout.cart">
**<block name="checkout.cart.top_methods">**
Any ideas? Thanks so much, and sorry about the length of this post!

1°) Edit all your layout xml to change the layout of the root reference to 2columns-leftf.phtml template
You can also go through an observer. Observe the controller_action_layout_generate_blocks_after event and in your method do :
public function myEventHandling($event) {
$event->getAction()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
}
2°) module Contacts controller index action postAction() so it should be /contacts/index/post/ so it should work. Except if you made your CMS page replacing /contacts/ normal behaviour (module contacts controller index action indexAction() ) it will search under your cms page instead of in the contacts module. If your CMS page have contacts as url, try changing it.
3°) Could you be more precise ? I don't really understand what you need. The form or the existing ratings are not showing up ?
4°) UnsetChild or remove instruction are global, you have to set it with a different name after a replace. But you can edit your layout file in your template directory (not the ones on the base/default/layout directory) to move the block in the proper location, and in the phtml file, try to move the
echo $this->getChildHtml('myblock')
in the proper location.

Related

Edit the catalog page for specific category

I am using Magento 1.8.1 and I am working on SEO. I need to put micro-data (schema code) for some category on that page only. I don't understand how to put the data for specific page because if I put any data in template page, it will update on all categories.
For example: I need to put data only for this page.
As I understand it, you want to add some code to only appear on a specific category view. You can add Javascript to the description field in the General Information tab of the category:
You can also add a template to before_body_end block of the page:
You can add additional layout directives here. This layout update:
<reference name="before_body_end">
<block type="core/template" name="seocode" template="seocode/seocode.phtml" />
</reference>
means render out your custom block (seocode) and template file (seocode.phtml) in the before_body_end block. The before_body_end block can be found in the page templates; i.e. page/1column.phtml or page/2columns-left.phtml.

Magento: Products List - Changing back to Grid Mode

I'm trying to figure out a way to set the Grid Mode/List Mode back to default, which in this case is Grid Mode. I want someone to be able to use List Mode if they like, but only on that page. Once they go to another page, I want that page to be reverted back to Grid Mode no matter what.
The reason I need this is due to Infinite Scroll seizing to function properly when someone stays on List Mode going from one page to another. This has been the only option to fix it.
I think you just need to reference the product_list_toolbar, because the function you want, disableParamsMemorizing() is a member of Mage_Catalog_Block_Product_List_Toolbar.
So your local xml update would look something like:
<catalog_category_layered>
<reference name="product_list_toolbar">
<action method="disableParamsMemorizing"></action>
<action method="setData"><key>_current_grid_mode</key><value>list</value></action>
</reference>
</catalog_category_layered>
Edit: Found another SO question that seemed like it could be similar: Set "List / Grid" default view mode in catalog.xml for category view

CMS page add block magento

I have in CMS->page "home page" file. In content i am writing line like this:
{{block type="myfolder/newfile" template="myfolder/newfile.phtml"}}
I want to render in content file newfile.phtml. What i am doing wrong ?
My new file is under: app\design\frontend\default\themeas\template\myfolder\newfile.phtml
You need to give your block a name. That's how Magento will reference the block. Also, your block type must be valid in order for the block to render. For default blocks try using type="core/template"
Your new code should look like this:
{{block type="core/template" name="my.block.name" template="myfolder/newfile.phtml"}}
Another note about the type attribute, its not actually a directory/file structure, rather, it's a URI that is mapped with the Magento autoloader. "Core" relates back to the Mage_Core_Block_Core class (under the app/code/core/Mage/Core directory) and then the info after the slash relates to the folders inside of that directory. So type="core/template" resolves to this class Mage_Core_Block_Core_Template which is located at app/code/core/Mage/Core/Block/Template.php. All the type attribute is doing is telling Magento which methods you need to load inside of your block.
A couple other block types you can try are:
For Product Lists: catalog/product_list
For Text Lists (blocks that automatically render out child blocks): core/text_list
For Category Blocks: catalog/category_view
There are plenty more, a good way to find new ones is to look at a block that does a similar action to what you are trying to do, and find where it is defined in the XML.
If you want to pass variables to the block, you can do something like:
{{block type="core/template" name="my.block.name" myvariable="5" template="myfolder/newfile.phtml"}}
Since Magento 1.9.2.2, or equvivalent patch you also need to grant permissions to the new block. You do this in the backend:
System | permissions | blocks
I.e if you wish to show:
{{block type="catalog/product_bestseller" name="krillo.bestseller" template="catalog/product/bestseller.phtml"}}
Add your block name "catalog/product_bestseller" and set the status to "allowed"
I'd like to offer an alternative:
The above answers work fine, however it's my personal preference to not insert blocks in the content of a CMS page as clients can (and have) deleted this crucial line when trying to edit text and content using the WYSIWYG.
You could add the following in the the Layout > Layout update XML section of a CMS page:
<reference name="content">
<block after="-" type="your/block_type" name="block.name" template="your/block/template/file.phtml"/>
<action method="insert" ifconfig="your/block_type">
<block>block.name</block>
</action>
</reference>
This way, clients are less likely to edit this tab!
Hope this helps anyone else with this issue!

How to change the page layout in Magento?

I want to change my category page layout to 2columns-left.phtml. The default is a 3 column layout. I only want to set the category page layout to 2columns-left.phtml. The rest should keep the default page layout (3 columns). How can I do this?
You can do this for categories individually under the Design tab. You can do this for all categories by adding a local.xml to your custom theme's layout folder which contains the following:
<?xml version="1.0"?>
<layout>
<my_category_root_template>
<reference name="root">
<tpl>page/2columns-left.phtml</tpl>
</reference>
<my_category_root_template>
<catalog_category_layered>
<update handle="my_category_root_template" />
</catalog_category_layered>
<catalog_category_layered_nochildren>
<update handle="my_category_root_template" />
</catalog_category_layered_nochildren>
<catalog_category_default>
<update handle="my_category_root_template" />
</catalog_category_default>
<!-- EDIT: forgot about search results page -->
<catalogsearch_advanced_result>
<update handle="my_category_root_template" />
</catalogsearch_advanced_result>
<layout>
For further info, Magebase has a great Layout XML primer, and Alan Storm wrote the book on it.
I don't have much experience with magneto but i think it may work.
Go to admin->Catalog->Categories->Manage Categories
Then go to ->Custom Design
You will find Page Layout option there change that to whatever you like.
First to set up the categories: in the admin panel, select the Catalog menu. Then on the left, select the category that you wish to edit. On the right, the Custom Design tab contains the Page Layout property. If you want all categories to have the same layout, set the root category's Page Layout accordingly, and then the child categories' "Use Parent Category Settings" property to True.
The layout for all other pages will be determined by the CMS->Pages page. Click the page to modify, then on the left, select Design, and then on the right, the Layout property.
If you are wondering how to make sure that all subsequently created pages in the CMS admin area by default use a particular layout, so that you don't have to change it each time you create a new content page, I am not certain, as mine seems to default to 1column, even though the XML seems to configure the page to use 3-column (I'm referring to what is in /app/design/frontend///layout/page.xml).. I may misunderstand how that is linked to this, though, perhaps someone else can comment. My understanding is that the CMS pages have their layout settings and custom layout information stored in the database. Therefore, perhaps there is another setting in the database that choose the default when creating a new CMS page.

Magento - render phtml template file from layout update xml

I'm putting together my first Magento theme. Wee.
This site will have a large number of static pages, and I'm trying to determine the best method of getting that content into the system in an easily maintainable way. Ideally, this process can be managed by a team member with limited experience in magento (this is a key point).
Aside from these two main methods of including static "page" content:
1 - save page-content as a CMS static block, to be added to a
category page
2 - save page-content as a CMS page
it seems I should be able to just render a phtml template file (with page-content as real markup) from a combination of layout update xml directives (in a cms page / category page), or as a widget type of include.
Assuming my file structure looks like this:
/my_theme
/default
/varient
/template
/cms
/template
/category1
/category2
- page_content.phtml
I've tried planting this file into a cms page via a number of variations on:
<reference name="content">
<block type="core/template" name="content.current" as="content.current" output="toHtml" template="cms/template/category1/category2/page_content.phtml"
</reference>
in the layout update xml.
Alternatively, I've tried to render this file via content directives like:
{{block type="core/template" name="content.current" template="cms/template/category1/category2/page_content.phtml"}}
With (obviously) no luck so far.
Granted - there maybe reasons not to deal with static content in this way, but it may still be a viable alternative to the two steps already mentioned (image and link pathing, for example).
At any rate - I believe some combination of update xml or content directives should be workable, but I'm still getting my head around Magento layout and haven't figured out the correct method.
Any advice or explanations would be grand.
Cheers -
b[]x
For any future overflowers looking to figure this out:
{{block type='core/template' template='cms/template/category1/category2/page_content.phtml'}}
works for sure. Just tried it this morning without the name attribute and viola.

Resources