I want add custom column for sidebar all page in Magento - magento

I want add my custom sidebar next right column all page.
Please check this link: http://www.wildbuilder.com/images/Untitled-1-Recovered.png
(I explain using image.)
There are featured products in the mini sidebar.
I don't want include the mini sidebar into right column. next to right column :)
I already made featured-products.phtml at /catalog/product/ folder.
And I created cms block, featured_products and I put in this code
{{block type="catalog/product_list" category_id="4" template="catalog/product/featured-products.phtml"}}
And I added code at page.xml like this.
<block type="core/text_list" name="content" as="content" translate="label">
<label>Main Content Area</label>
<block type="cms/block" name="featured_products">
<action method="setBlockId"><block_id>featured_products</block_id></action>
</block>
</block>
Then I added code in 2columns-right.phtml at /template/page/ folde.
like this,
<div class="wrapper">
<?php echo $this->getChildHtml('global_notices') ?>
<div class="page">
<?php echo $this->getChildHtml('header') ?>
<div class="main-container col2-right-layout">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<div class="main">
<div class="col-main">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-right sidebar"><?php echo $this->getChildHtml('right') ?></div>
</div>
</div>
<?php echo $this->getChildHtml('before_body_end') ?>
</div>
<?php //my slidebar ?>
<div style="float:right;width:92px;vertical-align:top;background-color:#000;margin:-766px 110px 0 0;">
<?php echo $this->getChildHtml('featured_products') ?>
</div>
But my sidebar is not showing.
How Can I Do???
Please let me know.
Thank you.

Also, try the following in 2-columns-right.phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(featured_products)->toHtml() ?>

No no no. Never edit the 2col-right, left or any other ./page/ template file for a modification such as this. You should also not be making changes in page.xml
What you need to do is understand layout handles on Magento. As your change relates specifically to catalogue, you should edit
catalog.xml
Then within that file, you can utilise the layout handle - which means, it appears, by default, everywhere.
<default>
<reference name="right">
<block type="catalog/product_list" template="catalog/product/featured-products.phtml" name="featuredprods" before="-">
<action method="setCategoryId"><category_id>4</category_id></action>
</block>
</reference>
</default>
There is no need for a phtml modification, or a CMS block or an edit of page.xml

Related

Removing Magento blocks through xml or phtml

I am starting out in magento theme development and have coded my local.xml to removed 2 blocks below.
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<remove name="currency" /><!--removes currency selector-->
<remove name="store_language" /><!--removes store language -->
</reference>
</default>
</layout>
This works but the template header.phtml has the block wrapped in divs that are now not needed. See below:
<div class="header-language-background">
<div class="header-language-container">
<div class="store-language-container">
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('currency_switcher') ?>
<p class="welcome-msg"><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
</div>
</div>
My question is can I just remove the section from the template file instead of removing the block? Will this effect anything if the blocks are in the xml files but not being called up in any template phtml files?
Thanks :)
If the HTML you need to remove is referenced as a XML block then it is better to remove it from the XML using the <remove> node.
If the HTML to remove is not referenced as a XML block, removing it from the template directly is the only solution. Of course you should edit the template from your own theme and not the one from the base one.
if you remove befault store language then just comment out i header.phtml.
like this.
<?php echo $this->getChildHtml('store_language') ?>
Comment...
<?php **//**echo $this->getChildHtml('store_language') ?>

Magento - display product reviews on product view page

I am having difficulty placing the product reviews on the main product view at a specific location. I can load them in the content area, but not at the specific location I require (within some of the view mark-up).
I have a local.xml with the following in it:
<catalog_product_view>
<reference name="content">
<block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>
</reference>
<catalog_product_view>
The above loads the reviews after all other content - as might be expected, due to content not being a templated block.
I have tried defining the blocks outside of the content reference, and placing this at the relevant point:
<?php echo $this->getChildHtml('reviews') ?>
For clarity, here is where I need the block to appear in view.phtml:
<div class="product-collateral">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
<?php echo $this->getChildHtml('reviews') ?>
</div>
Unfortunately, this doesn't output anything at all. I'm fairly new to Magento, and I'm at a loss how to achieve the above.
You can try leaving the code as in your example and include and use the attribute before, or after.
This allows you to position a block in regards to another block within that reference.
Ex: <block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml" before="product.description"/>

How to Change the message position in magento?

I need change the message(error/success) position in magento. By default magento message(error/success) show inside the wrapper or content. But I need to show the message in the top of the page. Can any one help me to fix this.
Thanks
There are a couple of ways to do this. Here is one which requires a little layout xml and a new template at a minimum…
Layout:
<layout>
<default>
<reference name="after_body_start">
<block type="core/template" name="top.messages" template="core/messages/top.phtml" before="-" />
</reference>
</default>
</layout>
Template: ( app/design/frontend/your_package/your_theme/template/core/messages/top.phtml )
<?php $_messageCollection = $this->getMessagesBlock()->getMessageCollection() ?>
<?php if ($_messageCollection->count()): ?>
<div>
<?php
echo $this->getMessagesBlock()->getGroupedHtml();
$_messageCollection->clear();
?>
</div>
<?php endif; ?>
You just have to move the block in your layout xml files. Unfortunately, I don't have Magento at hand to tell you what's the block name, and where it's defined.

magento product

I have posted this issue on the magneto Forums but haven't herd anything in two weeks so I'm going to post here and hopefully get a little more insight
"I have been going through the forums and working out how to change the view for one product, and I found a good post on the forums that let me change the view like I want but my page seems to be created from two seperate files. One called view.phtml in app/design/frontend/base/default/template/catalog/product and another called default.phtml in the same path just down two more directories view/type/. The Code I need to modify is in default.phtml but when i do that and set it to display that it stops displaying the other half of the page or the view.phtml part.
I am using ....
<reference name="product.info">
<action method="setTemplate">
<template>catalog/product/view/type/default1.phtml</template></action>
</reference>
...in the custom layout section of the product in the backend.
But this only shows the sizing section of the page and not the name/description/picture witch is output by view.phtml
So how do I get view.phtml to display the new default1.phtml
and if I try.....
<reference name="product.info">
<action method="setTemplate">
<template>catalog/product/view.phtml</template>
</action>
</reference>
it works but does not show default1.phtml in the size section.
All this because I need to show 2 different size charts one for males and one for females. You can see my issue by going to mysteryhousecostumes.net and navigating to a womans product and then a mans and you will see the mens products still link to the womens size chart.
How do I fix view.phtml so that it links to default1 instead of default? I realize I’ll need to make a duplicate view.phtml but I cant find the connection between the two files here is my view.phtml…
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?> </div>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div class="product-shop">
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<?php if ($this->canEmailToFriend()): ?>
<p class="email-friend"><?php echo $this->__('Email to a Friend') ?></p>
<?php endif; ?>
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php endif; ?>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
</div>
<div class="product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="clearer"></div>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
</form>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
</div>
<div class="product-collateral">
<?php foreach ($this->getChildGroup('detailed_info', 'getChildHtml') as $alias => $html):?>
<div class="box-collateral <?php echo "box-{$alias}"?>">
<?php if ($title = $this->getChildData($alias, 'title')):?>
<h2><?php echo $this->escapeHtml($title); ?></h2>
<?php endif;?>
<?php echo $html; ?>
</div>
<?php endforeach;?>
<?php echo $this->getChildHtml('upsell_products') ?>
<?php echo $this->getChildHtml('product_additional_data') ?>
</div>
Something that may help you find what blocks are used on what page is by enabling "debug mode". You can enable it by going to your admin panel and goto system->configuration then in the left nav switch the "Current Configuration Scope" from "Default Config" to "your-stores-name Web Store".
The page will auto refresh then towards the bottom of the left nav in the ADVANCED section click Developer then in the Debug section of the accordion you will see "Template Path Hints" and "Add Block Names to Hints" switch each of these select fields to "yes" then click the Save Config button at the top right of the page.
Once debug mode is active you will all your blocks will be outlined in red and labeled with template locations and block name references. Hope this helps in the future.
The reason it's not working is because view.phtml is kinda like the parent block for the product view page, therefore when you disable it it only shows the sizing section, and when you enable it you get the wrong sizing section.
What you need to do is within view.phtml tell it about the new sizing template.
This is done by first creating a block, then assigning it a template, and then calling it in your view.phtml file
The easiest way to do this is find out what the first sizing block is called, then look in the xml for it and copy it and change it's name to something unique and the template to you new file.
Then you go in to your view.phtml file and call the block by name to be displayed.
In your case I think it's the following lines that need to be changed:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
It should read:
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildHtml('your_new_block_name') ?>
<?php endif;?>
OK So I found the code including my size chart block
<?php echo $this->getChildHtml('product_type_data') ?>
When I comment it out I get the results i expect and my sizing charts disappear
In Catalog.xml I have found what I think the code is (theres a few catalog.xml files is there a way to be sure i have the right one?)
Anyway the code I found there is...
<PRODUCT_TYPE_simple translate="label" module="catalog">
<label>Catalog Product View (Simple)</label>
<reference name="product.info">
<block type="catalog/product_view_type_simple" name="product.info.simple"as="product_type_data" template="catalog/product/view/type/default.phtml">
<block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">
<label>Product Extra Info</label>
</block>
</block>
</reference>
</PRODUCT_TYPE_simple>
<PRODUCT_TYPE_configurable translate="label" module="catalog">
<label>Catalog Product View (Configurable)</label>
<reference name="product.info">
<block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data" template="catalog/product/view/type/default.phtml">
<block type="core/text_list" name="product.info.configurable.extra" as="product_type_data_extra" translate="label">
<label>Product Extra Info</label>
</block>
</block>
</reference>
<reference name="product.info.options.wrapper">
<block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml"/>
</reference>
</PRODUCT_TYPE_configurable>
To which I added
<PRODUCT_TYPE_simple translate="label" module="catalog">
<label>Catalog Product View (Simple)</label>
<reference name="product.info">
<block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data1" template="catalog/product/view/type/default1.phtml">
<block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">
<label>Product Extra Info</label>
</block>
</block>
</reference>
</PRODUCT_TYPE_simple>
and
<PRODUCT_TYPE_configurable translate="label" module="catalog">
<label>Catalog Product View (Configurable)</label>
<reference name="product.info">
<block type="catalog/product_view_type_configurable" name="product.info.configurable" as="product_type_data1" template="catalog/product/view/type/default1.phtml">
<block type="core/text_list" name="product.info.configurable.extra" as="product_type_data_extra" translate="label">
<label>Product Extra Info</label>
</block>
</block>
</reference>
<reference name="product.info.options.wrapper">
<block type="catalog/product_view_type_configurable" name="product.info.options.configurable" as="options_configurable" before="-" template="catalog/product/view/type/options/configurable.phtml"/>
</reference>
</PRODUCT_TYPE_configurable>
Then I changed the calling php to look like...
<?php echo $this->getChildHtml('product_type_data1') ?>
But I have missed something in translation

Custom blocks not being rendered

I have developed a collections module for a clients Magento site. Among other things, this module pulls in product details (media, description, attributes) on the category listing page. The issue I am running into is that my blocks are not rendering on the clients site (Magento EE 1.8), even though everything works locally (Magento CE 1.6).
Developer mode has been activated, but I see no errors on the page, and I know that Magento is seeing the module as it correctly shows up in the admin under System > Configuration > Advanced.
We set the base block class name in app/code/local/Mycompany/Collections/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Collections>
<version>0.1.0</version>
</Mycompany_Collections>
</modules>
<global>
<blocks>
<mycompany_collections>
<class>Mycompany_Collections_Block</class>
</mycompany_collections>
</blocks>
</global>
</config>
We insert our blocks to the layout in app/design/frontend/enterprise/mytheme/layout/local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_category_view>
<reference name="product_list">
<block type="mycompany_collections/collection" name="collection" template="collections/collection.phtml">
<block type="mycompany_collections/product" name="add-to-cart" template="collections/product/add-to-cart.phtml" />
<block type="mycompany_collections/product" name="description" template="catalog/product/view/description.phtml" />
<block type="mycompany_collections/product_attributes" name="attributes" template="catalog/product/view/attributes.phtml" />
<block type="mycompany_collections/product_media" name="media" template="catalog/product/view/media.phtml" />
</block>
</reference>
</catalog_category_view>
</layout>
The mycompany_collections/collection block extends Mage_Catalog_Block_Product_List and reloads the products to ensure we have fetched all the relevant data from the database.
class Mycompany_Collections_Block_Collection extends Mage_Catalog_Block_Product_List {
public function reloadProducts() {
// Fully reload each of the products in this category so that we have
// all the information required to display product details.
// TODO: find a more efficient way to grab all the info for all the
// products, as this would seem to add 1 (or more) additional
// query per product.
$reloaded = array();
foreach($this->getParentBlock()->getLoadedProductCollection() as $product){
$reloaded[] = Mage::getModel('catalog/product')->load($product->getId());
}
return $reloaded;
}
}
The mycompany_collections/product block extends Mage_Catalog_Block_Product_Abstract with custom methods to allow us to explicitly set the product on the block and return that product without pulling from the registry.
class Mycompany_Collections_Block_Product extends Mage_Catalog_Block_Product_Abstract {
private $_product = null;
public function _prepareLayout() {
// We don't need to do anything here.
}
// NOTE: Must be called before ->toHtml()
public function setProduct($product) {
$this->_product = $product;
return $this;
}
public function getProduct() {
return $this->_product;
}
}
Both the mycompany_collections/product_attributes and mycompany_collections/product_media blocks do the same get/set_product overrides for their equivalent abstract parent classes.
Inside our collection.phtml template, we call $this->reloadProducts() and iterate over the product list to display the product details and buy collection popups (these are js lightboxes that activate on click)
<?php
$_productCollection = $this->reloadProducts();
?>
<!-- Buy collection popup -->
<div id="buy-collection" class="no-display">
<h1>Buy Collection</h1>
<?php foreach($_productCollection as $_product): ?>
<div id="buy-collection-product-<?php echo $_product->getId(); ?>" class="product">
<div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div>
<?php /*
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(100); ?>" width="100" height="100" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
*/ ?>
<a href="<?php echo $_product->getProductUrl() ?>" ><?php echo $_product->getName(); ?></a>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart"><?php echo $this->getChild('add-to-cart')->setProduct($_product)->toHtml(); ?></div>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
<?php endif; ?>
<div class="details">
<div class="description">
<?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?>
</div>
<div class="attributes">
<?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- Product detail popups -->
<div id="product-details" class="no-display">
<?php foreach ($_productCollection as $_product): ?>
<div id="product-detail-<?php echo $_product->getId(); ?>" class="product">
<div class="media"><?php echo $this->getChild('media')->setProduct($_product)->toHtml(); ?></div>
<div class="description"><?php echo $this->getChild('description')->setProduct($_product)->toHtml(); ?></div>
<div class="attributes"><?php echo $this->getChild('attributes')->setProduct($_product)->toHtml(); ?></div>
</div>
<?php endforeach; ?>
</div>
To actually fire all this off, for any product category that we wish to display as collection we override the category.listing and product_list templates in the Custom Design tab of that category in the admin. These templates contain design changes, and product/list.phtml calls the collection block.
<reference name="product_list">
<action method="setTemplate">
<template>catalog/collections/product/list.phtml</template>
</action>
</reference>
<reference name="category.products">
<action method="setTemplate">
<template>catalog/collections/category/view.phtml</template>
</action>
</reference>
Inside product/list.phtml we call the collection block with a simple echo $this->getChildHtml('collection');. Nothing is returned on this line. No template, no PHP errors, nothing. As mentioned above, this all works beautifully in my local dev environment.
That's the overview of how things are setup. Here's what I have done to debug:
Using Alan Storm's Layoutviewer module, I have confirmed that my blocks are listed on ?showLayout=page, and the handle "catalog_category_view" is listed in ?showLayout=handles. However, when I print $this->getSortedChildren() in product/list.phtml the collection block is not listed.
If I replace the collection block in layout.xml with a super simple core/text block, it does render.
<?xml version="1.0"?>
<layout version="0.1.0">
<catalog_category_view>
<reference name="product_list">
<block type="core/text" name="collection"><action method="setText"><text>This is a test</text></action></block>
</reference>
</catalog_category_view>
</layout>
This led me to believe the problem was deeper in my own code, so I simplified and went totally basic… I removed the reloadProducts method from Mycompany_Collections_Block_Collection and reduced collections.phtml to a single line of text to see if something in the template or child blocks were causing an issue. Unfortunately this had no affect and I still got no output.
I'm really at a loss as to why this is not working. I first thought it may be a difference between the Enterprise and Community editions, but something as fundamental as the layout/block system is unlikely to differ between them. There clearly seems to be something missing, and I'm hoping someone may be able to point in the right direction.
Thanks!
Did you check Mycompany_Collections.xml available in /app/etc/modules section and codepool enabled?
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Collections>
<active>true</active>
<codePool>local</codePool>
</Mycompany_Collections>
</modules>
</config>

Resources