I’m having trouble in moving the mini cart from sidebar to header. I’ve tried all the tutorials available in the internet but it doesn’t work.
I also tried adding this in the header block of layout\page.xml
<block type="checkout/cart_sidebar" name="cart_sidebar" as="topcart" template="checkout/cart/sidebar.phtml"
And then in my page\html\header.phtml, I use the code below to call the cart but nothing happened.
<?php echo $this->getChildHtml('topcart'); ?>
The solution above works in magento 1.6, but not in version 1.7
First you need to create or update your local.xml file IF you do not have a local.xml file you can create one in
app->frontend->[Package Name]->[Theme Name]->layout->local.xml
Once this is created you can copy exactly what I have in this post into that file for a start of how to use one.
DO ALL UPDATES THROUGH A LOCAL.XML file not through catalog.xml or checkout.xml !! This will make upgrades significantly easier later down the road. Additionally, you will be able to quickly see all changes you have made to your site in one file.
The below example will add it to the header reference name which will be available on all pages as indicated by the tag and will only be available in the header.phtml file. Duplicate base/default/checkout/cart/sidebar.phtml and rebane that file as topcart.phtml and place it into your theme at [Your Package]/[Your Theme]/template/checkout/cart/topcart.phtml by doing this you are cloning the sidebar functionality and adding it to the header. Then you can make any edits through the topcart.phtml file without affecting base functionality.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="header">
<block type="checkout/cart_sidebar" name="topcart_mini" as="topcart" template="checkout/cart/topcart.phtml" />
</reference>
</default>
</layout>
Then call it in header.phtml with
<?php echo $this->getChildHtml('topcart'); ?>
This is the proper way to modify Magento, this makes upgrades quite simple. Additionally, it does not edit any core files.
Insteat of copying block xml, you should reference it like
<reference name="block-name">
</reference>
Related
I've built a custom shopping cart for my Magento site that sends and API call to Shopify to handle payment.
The problem is I need the template file to load on every page in magento. I thought after_body_start would be a good place to put the template, but I cannot get it to load!
My template lives in \app\design\frontend\rwd\crystal\template\mgw\mwCart.phtml
and contains php, html and javascript. It was running just fine when I placed the code directly into the header.phtml
Here's the xml in \app\design\frontend\rwd\crystal\layout\local.xml which should load the template
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="after_body_start">
<block type="core/template" name="mwCart" template="mgw/mwCart.phtml" output="toHtml" before="-" />
</reference>
</default>
</layout>
I'm new to Magento and have read through the tutorials. I also checked out and tried any suggestions I could find.
I've seen this Magento - Add Some HTML on All Pages of my Theme After_Body_Start but did not solve my issue.
How can I get my template to load on every page?
Thank you.
You're close here... It the location of your local.xml file that is the problem. Place the existing file in the following location:
app/design/frontend/rwd/default/layout/local.xml
..and it should solve the problem. If you have an existing subtheme, e.g. rwd/mytheme, the file would go here:
app/design/frontend/rwd/mytheme/layout/local.xml
If you still aren't getting the desired results, check the configuration in Magento Admin->Configuration->Design->Themes and make sure that you are indeed using the rwd theme. If all else fails, the base/default location would be the last thing to try:
app/design/frontend/base/default/layout/local.xml
I'm trying to remove "recently viewed" from the home page, but I don't know where the block is called. I tried to delete reports.xml but the block stayed there. Then I tried to delete all the code in home_product_viewed.phtml and it worked, but I don't want to delete the code. I only want to delete the call to that file but I don't know where that file is called.
Goto magento backend.
Select the CMS page for homepage.
In the Design section add the below code in the Layout Update XML field
<reference name="right">
<action method="unsetChild"><alias>right.reports.product.viewed</alias></action>
</reference>
To remove it from only the home page, I would do this. Go to your /app/design/frontend/packagename/themename/layout/local.xml
and edit it like this:
<layout>
<cms_index_index>
<remove name="right.reports.product.viewed" />
</cms_index_index>
</layout>
To verify your packagname and themename, go in to admin - System - Configuration - Design.
There may already be other code inside of the layout tag which you should leave there!
This worked for me -> Using left below not right.reports.product.viewed.
Custom Layout Update
<reference name="right">
<action method="unsetChild"><alias>left.reports.product.viewed</alias></action>
</reference>
I'm pretty new to Magento, and have been following the base theme so far along, but I am having problems with catalog pagination.
At the moment I'm having problems getting the "page/html_pager" block to display.
So, my catalog.xml has this for both anchor and non-anchor categories:
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager" />
</block>
</block>
</block>
</reference>
My toolbar.phtml has the corresponding code:
<?php echo $this->getPagerHtml() ?>
and my default/template/page/html/pager.phtml just contains some test code along the lines of:
<h1>Test</h1>
At first I thought it might be because there weren't multiple pages, so I added some products and set the both the grid and the list views to show a maximum of 1 per page, and the item count reflects this:
Showing 1 of 11 items
Doing a var_dump on the $this->getPagerHtml() returns an empty string, and using the template path hints indicates it doesn't even seem to load the block - yet it loads it's parent block.
Copying the code directly from the base design package doesn't work, yet switching to that package it does.
So, what am I missing? Or doing wrong? I've run out of ideas as to what it could be.
thanks
Solved:
Adding<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
After the product_list_toolbar block appeared to fix this issue.
Magento's documentation is a little thin on the ground with this so I'm unsure as to why
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
requires it's name set again with an action tag, but it does.
If anyone can explain this, I'd love to understand it.
Any chance that it's being overridden by a different .xml file in layout?
You could always remove all the .xml files in the layout directory and bring them back in one by one and see if the pagination toolbar disappears, whilst making sure cache is turned off.
After that, rename the template directory catalog to ~catalog and let it pick up the base catalog directory and see if it's actually the .phtml files causing the problem.
I am creating a custom module where i added a button in product view page(default file).I have inserted the button code in the following file
app\design\frontend\base\default\template\catalog\product\view.phtml
and the button gets displayed & works well.But everytime Magento is updated , the above file gets replaced and so my code is discarded.Is there any way to modify or extend or inject the template coding from within my custom module?Should i need to override the core blocks or somehting?
Give your module a layout file:
...
<frontend>
<layout>
<updates>
<YOUR_MODULE>
<file>YOURMODULE.xml</file>
</YOUR_MODULE>
</updates>
</layout>
</frontend>
...
In the base theme's layout/YOURMODULE.xml file:
<layout version="1.0">
<catalog_product_view>
<reference name="product.info">
<action method="setTemplate"><name>YOURMODULE/product/view.phtml</name></action>
</reference>
</catalog_product_view>
</layout>
Copy the modified view.phtml to a new directory, template/YOURMODULE/product/
When packaging your module remember to include all these files but don't overwrite template/catalog/product/view.phtml.
Anyone downloading your module might want to make their own changes to that template so you should also include instructions on which file has been changed and where to find it. Since view.phtml is often changed by both themers and other modules it would be a much better idea to alter one of the child templates instead - which one depends on where your button will be.
As a bonus there is a block called extrahint just after the prices of type core/text_list - it doesn't have a template so you might normally miss it when using template path hints. You can safely add as many templates as you like to it without altering any existing ones:
<layout version="1.0">
<catalog_product_view>
<reference name="product.info.extrahint">
<block type="core/template" name="YOUR.CUSTOM.BLOCK" template="YOUR/CUSTOM/TEMPLATE.phtml" />
</reference>
</catalog_product_view>
</layout>
That only helps if just after the price is useful for you. Other blocks that can be safely appended are the options and containers areas, but they only show for products with options.
The problem is that you are installing it in app/design/frontend/base/default.
You need to create a copy of this directory in another directory, such as app/design/frontend/default/yoursite.
Read this for more info on how to do it specifically
You can't build your custom extension to be dependent on default views it shows bad planning. you should either clone this template or extend it and have ways to enable and disable your functionality. The must have thing is "designers guide" if your module implements templates or has ways to modify other templates.
I asked this question yesterday Static block on home page in Magento, which answered my question about hooking a cms/block to an existing block (content, in that example).
But now I would like to know how to create my own block.
I have this in my .phtml template:
<?php echo $this->getChildHtml('home_flash') ?>
And this in my cms.xml file
<reference name="home_flash">
<block type="cms/block" name="home-page-flash" before="content">
<action method="setBlockId"><block_id>home-page-flash</block_id></action>
</block>
</reference>
But this is not working.
I have also tried to create my own block type, (by copying the breadcrumbs declaration) in the page.xml file:
<block type="page/html_home_block" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
That file exists but isn't being rendered.
However when I reference the block like this:
<block type="page/html_breadcrumbs" name="home_block" as="home_block" template="page/template/home_block.phtml"/>
It renders my home block template, but the original cms/block is not attached to it.
Hope all the different cases show what is happening and highlight the gap in my knowledge well enough for someone to answer, do I have to "register" my new "home_block" type somewhere?
There are many different blocks available that you can use without creating your own. In this case I think core/text_list would be suitable because it doesn't require a template and can have as many child blocks within it as you need.
<?xml version="1.0"?>
<layout version="0.1.0"><!-- All layout files start with this -->
<cms_index_index><!-- Index directive is the same as "home" page -->
<reference name="root"><!-- For more blocks that can be referenced see "default" directive -->
<block type="core/text_list" name="home_flash">
<block type="cms/block" name="home-page-flash">
<action method="setBlockId"><block_id>home-page-flash</block_id></action>
</block>
</block>
</reference>
</cms_index_index>
<!-- More directives might go here -->
</layout>
Other useful block types worth knowing are core/text and core/template which correspond to Mage_Core_Block_Text and Mage_Core_Block_Template respectively. They get used the most.
Your home made block type of page/html_home_block didn't have any PHP class with a matching name, and if you were genuinely creating your own you wouldn't be able to use the page prefix since Magento already does.
To create a block you only need a <block> tag in the layout file.
To create a block type you need to write a PHP class, give it a namespace and declare it as part of a module.
To add to an existing block is the time when you use a <reference> tag.
There are many fine articles at Magento Knowledge Base including some on Theming & Design.