I can't manage to show on a page, on the left side the categories.
I selected for the page under Design - layout to 3 columns,
Right side shows fine, but nothing on left side.
New to magento so I'm not sure in which file in the template I have to look for.
Its a custom template installed so I got so far to:
app/design/frontend/default/f001/template/
but not sure now if to look under catalog or page folders
Go to layout Xml folder..
Blockquote /app/design/frontend/default/default/layout/catalog.xml
Open this Xml file and paste this code.
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" />
</reference>
further open this file ..
/app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml
paste this code:
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current">'.$cat->getName()."\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li>'.$cat->getName()."</li>\n";
}
}
?>
Go to Layout folder
i.e.
app/design/frontend/default/f001/layout/
open any xml file e.g. catalog.xml and under tags
<default>
</default>
paste in this code
<reference name="left">
<block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
like this
<default>
<reference name="left">
<block type="catalog/navigation" name="left_categories_nav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
</default>
But make sure to comment this block on line number 79.
<!-- <reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->
To move the categories from the right sidebar to the left sidebar you'll need to do this:
(1) Open app/design/frontend/default/f001/layout/ and find a file called local.xml - If it does not exist, create it.
Paste the following inside and save.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<!-- Left Categories Begin-->
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" before="-" template="catalog/navigation/left.phtml"/>
</reference>
<!-- Left Categories End-->
</default>
</layout>
(2) Open app/design/frontend/default/f001/layout/catalog.xml
Inside "Category default layout", look for something like this and comment this line out (like so)-
<!-- <reference name="right">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference> -->
That will prevent the categories from displaying on both sidebars, assuming you're using a 3 column.
The reference name, as you might have guessed, refers to each sidebar. You'll need to make sure that the reference name for "left" contains the left categories, and make sure the right does not (controlled in layout, not template files).
Add this in left static block
<p>Left side bar {{block type="core/template" template="catalog/navigation/left.phtml"}}</p>
add left.phtml in yourtemplatename/template/catalog/navigation/left.phtml
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current">'.$cat->getName()."\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>\n";
}
echo "</ul>\n</li>\n";
} else {
echo '<li>'.$cat->getName()."</li>\n";
}
}
?>
Related
I just created a cms block from magento admin panel and now I want to get it into the phtml I tried this way:
<?php
$currentview = Mage::app()->getStore()->getCode();
if($currentview = 'default'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1')->toHtml();
}
else if($currentview = 'it'){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
}
?>
I am getting cms block but if statement not working how can I make it working ?
If you have created CMS block named ostore_footerb1-it from admin panel.
Then following will be code to call them in .phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml();
?>
Another way to do this is :
In the layout (app/design/frontend/your_theme/layout/default.xml):
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="cms_ostore_footerb1-it" as="cms_newest_product">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
In your phtml template:
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
To get static block in phtml file
echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
Try this:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('ostore_footerb1-it')->toHtml(); ?>
Or this:
add this piece to the layout:
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="ostore_footerb1-it" as="ostore_footerb1-it">
<action method="setBlockId"><block_id>ostore_footerb1-it</block_id></action>
</block>
</reference>
</cms_page>
</default>
and call in phtml
<?php echo $this->getChildHtml('ostore_footerb1-it'); ?>
I need to add the category banner below the Breadcrumbs.
I have tried by adding new reference
<?php echo $this->getChildHtml('category_banner') ?>
in the 2columns-left.phtml
and in local.xml
<catalog_category_view>
<reference name="category_banner">
<block type="core/template" name="topbanner" template="catalog/category/category-image.phtml" before="-"></block>
</reference>
</catalog_category_view>
<catalog_category_default translate="label">
<reference name="category_banner">
<block type="core/template" name="banner" template="catalog/category/category-image.phtml"></block>
</reference>
</catalog_category_default>
But output is not coming.
Added new line inside the all layout i.e 2columns-left.phtml etc.
<?php echo $this->getChildHtml('category_banner') ?>
added below line inside your xml
<catalog_category_view>
<reference name="root">
<block type="core/template" name="category_banner" template="catalog/category/category-image.phtml" before="-"></block>
</reference>
</catalog_category_view>
I have a requirement that the logout url must be visible only in My Account bottom for every section of it like on "Account Information","Address Book", "My Orders" similar for all.
How to do this?
Where should I write
action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
in My customer.xml file.
You can remove the block 'customer_logged_in' in customer.xml and then you can add/make a block in customer.xml like this.
<reference name="content">
<block type="page/html_wrapper" name="my.account.wrapper" translate="label">
<label>My Account Wrapper</label>
<action method="setElementClass"><value>my-account</value></action>
<block type="core/template" name="logout_link" template="customer/logout_link.phtml"/>
</block>
</reference>
And the content of the logout_link.phtml would be something like,
<?php
$loggedIn = $this->helper("customer")->isLoggedIn();
if($loggedIn == 1){
echo "<a href=\"".Mage::getBaseUrl()."customer/account/logout/\" >LOGOUT</a>";
}else{
echo "<a href=\"".Mage::getBaseUrl()."customer/account/\" >LOGIN</a>";
}?>
....
It's better to use these URL's:
Mage::helper('customer')->getLogoutUrl()
Mage::helper('customer')->getLoginUrl()
It uses the customer helper instead of a hard coded URL.
I'm a bit of a Magento noob. I have the following code in the Page Layout section of my home page:
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>8</category_id></action>
</block>
</reference>
How do I change what attribute the products in this block are ordered by?
The order of a product list is generally controlled by the toolbar block Mage_Catalog_Block_Product_List_Toolbar. But if you want to be able to influence the way the product collection is ordered from the layout, you can do the following:
Rewrite the block Mage_Catalog_Block_Product_List and add a function to it:
public function setOrder($attribute, $direction)
{
$collection = $this->_getProductCollection();
$collection->clear()->setOrder($attribute, $direction);
$this->_productCollection = $collection;
}
in the layout update add an action node, e.g.
<reference name="content">
<block type="catalog/product_list" name="featured" template="catalog/product/list.phtml">
<action method="setCategoryId"><category_id>8</category_id></action>
<action method="setOrder"><attribute>name</attribute><direction>desc</direction></action>
</block>
I have maden custom product type (hotel). It has custom options tab in the backend.
I have added some custom options in the certain product(hotel). I have added html to view.phtml of my custom theme to output custom options.
<?php if ($this->hasOptions()):?> <?php echo $this->getChildHtml('container1','', true, true) ?> <?php endif;?>
Also I have added block to my layout.
<block type="core/template_facade" name="product.info.container1" as="container1">
<action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
<action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
<action method="append"><block>product.info.options.wrapper</block></action>
<action method="append"><block>product.info.options.wrapper.bottom</block></action>
</block>
<block type="core/template_facade" name="product.info.container2" as="container2">
<action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
<action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
<action method="append"><block>product.info.options.wrapper</block></action>
<action method="append"><block>product.info.options.wrapper.bottom</block></action>
</block>
<action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if> <key>alias_in_layout</key><key>options_container</key></action>
<action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
But <?php echo $this->getChildHtml('container1','', true, true) ?> return empty.
How can I show options block?
I have solved this issue and created function in helper to render custom options. Code goes below:
public function getHotelCustomOptionsHtml(Mage_Catalog_Model_Product $product)
{
$blockOption = Mage::app()->getLayout()->createBlock("Mage_Catalog_Block_Product_View_Options");
$blockOption->addOptionRenderer("default","catalog/product_view_options_type_default","catalog/product/view/options/type/default.phtml");
$blockOption->addOptionRenderer("text","catalog/product_view_options_type_text","inchoo_catalog/product/view/options/type/text.phtml");
$blockOption->addOptionRenderer("file","catalog/product_view_options_type_file","catalog/product/view/options/type/file.phtml");
$blockOption->addOptionRenderer("select","catalog/product_view_options_type_select","catalog/product/view/options/type/select.phtml");
$blockOption->addOptionRenderer("date","catalog/product_view_options_type_date","catalog/product/view/options/type/date.phtml") ;
$blockOptionsHtml = null;
if($product->getTypeId() =="hotel")
{
$blockOption->setProduct($product);
if($product->getOptions())
{
foreach ($product->getOptions() as $o)
{
$blockOptionsHtml .= $blockOption->getOptionHtml($o);
};
}
}
return $blockOptionsHtml;
}