magento product - magento

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

Related

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"/>

Extending Magento's topLinks to Include Nested/Dropdown Child Menu's

We've extended the Magento class Mage_Page_Block_Template_Links using the method outlined by Sonassi here.
Editing the _construct function to include our custom template:-
protected function _construct()
{
$this->setTemplate('page/template/links_nested.phtml');
}
Editing the function addLink to include $childMenu variable and allow this to be used in XML layout:-
public function addLink($label, $url = '', $title = '', $prepare = false, $urlParams = array(), $position = null, $liParams = null, $aParams = null, $beforeText = '', $afterText = '', $childMenu = false)
{
if (is_null($label) || false === $label) {
return $this;
}
$link = new Varien_Object(array(
'label' => $label,
'url' => ($prepare ? $this->getUrl($url, (is_array($urlParams) ? $urlParams : array())) : $url),
'title' => $title,
'li_params' => $this->_prepareParams($liParams),
'a_params' => $this->_prepareParams($aParams),
'before_text' => $beforeText,
'after_text' => $afterText,
'child_menu' => ($childMenu ? $this->getLayout()->getBlock($childMenu) : '')
));
$this->_links[$this->_getNewPosition($position)] = $link;
if (intval($position) > 0) {
ksort($this->_links);
}
return $this;
}
Then we wish to include <childMenu> parameter in local.xml for an item in topLinks:-
<reference name="top.links">
<action method="addLink" translate="label title before_text">
<label>Account</label>
<url />
<title>Account</title>
<prepare />
<urlParams />
<position>10</position>
<liParams>id="account-dropdown"</liParams>
<aParams />
<before_text />
<after_text />
<childMenu>account-submenu</childMenu>
</action>
</reference>
And then construct the childMenu as account-submenu:-
<reference name="top.links">
<block type="page/template_links" name="submenu" as="submenu">
<action method="setName">
<name>account-submenu</name>
</action>
<action method="addLink" translate="label title before_text">
<label>Contact Us</label>
<url />
<title>Contact Us</title>
<prepare />
<urlParams />
<position>110</position>
<liParams />
<before_text />
<after_text />
</action>
</block>
</reference>
Then we've made a few modifications to the template file to render childMenu if declared:-
<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links nav"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $count=>$_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()||$count): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?> link-<?php echo $count ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>>
<?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?>
<?php var_dump($_link->getChildMenu()); ?>
<?php echo ($_link->getChildMenu()) ? $_link->getChildMenu()->toHtml() : ''; ?>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Everything is working as expected apart from the fact that childMenu doesn't render anything at all in the front end, so the 'My Account' top link contains no submenu.
Is there something incorrect with the call for childMenu in the template file ?
<?php echo ($_link->getChildMenu()) ? $_link->getChildMenu()->toHtml() : ''; ?>
In the layout XML, you should define your submenu block (<block> node) before adding it to the top links (<action method="addLink"> within <reference name="top.links">). As Magento treats the nodes as they come, he won't know that the block exists otherwise
To anybody having any issues with this - I thought I'd post my solution.
I don't think it's too wise to copy the core Page/Block/Template/Links.php file from app/code/core to app/code/local and making the adjustments to that file (what happens if this Links.php file is updated in a future Magento update, you'd need to ensure your override complies with the new updated file from the core).
Anyways, the issue here is definitely that the instructions are missing a step - everything makes sense right to the point where they reference (out of nowhere) the block "mymainmenu.links" - this block doesn't exist anywhere, hence it won't work. And if you keep adding your links to the "top.links" block, Magento will just keep using the default block to display your links. So the obvious answer here is to create a new block.
In your layout file add the following block (I'm using local.xml) app/design/frontend/(package)/(theme)/layout.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header"> <!-- You could also use root here to give it a larger scale access -->
<block type="templatelinks/page_template_links" name="mymainmenu.links" as="mymainmenuLinks">
<action method="setName">
<name>mymainmenu-links</name>
</action>
<action method="addLink" translate="label title">
....
</action>
</block>
</reference>
</default>
</layout>
Setting the block type to (custom module name)/(block location) instantiates our custom module and and processes our actions through that.
You'll also have to remember to display your newly created (in this instance mymainmenuLinks) block in our template(s) - In most cases it'll be your app/design/frontend/(package)/(theme)/template/page/html/header.phtml file
Locate
<?php echo $this->getChildHtml('topLinks') ?>
And replace with your new block name
<?php echo $this->getChildHtml('mymainmenuLinks') ?>

Magento: How can I show the category description in the left sidebar?

I want to display the category description in my left sidebar instead of the main column.
I added this to my catalog.xml:
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/>
</reference>
<reference name="left">
<block type="catalog/navigation" name="catalog.catdes" after="catalog.leftnav" template="catalog/navigation/description.phtml"/>
</reference>
And I created this file: catalog/navigation/description.phtml
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
?>
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<div class="category-description">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
There is no result at all. What could I be doing wrong?
The following solved this issue for me.
echo Mage::getModel('catalog/layer')->getCurrentCategory()->getDescription();
Have you just tried to echo $_description since you set it equal in the if statement?
If that doesn't work then just try to load it:
$cat = Mage::getModel('catalog/category')->load($_category->getId());
$description = $cat->getDescription();
<?php if($category = Mage::registry('current_category')): ?>
<div class="category-description std">
<?php echo $category->getDescription(); ?>
</div>
<?php endif; ?>
Anywhere in custom phtml file :
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentCategory = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category information
echo $currentCategory->getDescription();
?>

Call a block in another template

I just create a module name referral. Now I want to place the referral block to another module template file name success.phtml. Can it be done?
referral.xml(in referral module)
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_success>
<reference name="checkout.success">
<block type="referral/referral" name="referralCallLink"><action method="referralCallLink"></action></block>
</reference>
</checkout_onepage_success>
<!--block type="referral/referral" name="referralAddSession"><action method="referralAddSession"></action></block-->
</layout>
success.phtml
<?php if($hasBoughtMCash): ?>
<div> Your
<?php echo implode(', ',$hasBoughtMCash); ?>
purchase is successful.
</div>
<?php endif; ?>
<h2>Share in Facebook and Earn for Free MCash!</h2>
<?php echo $this->getChildHtml(); ?>
Referral.php(block)
public function referralCallLink() //success page
{
...
$collection7 = Mage::getModel('referral/referrallink')->getCollection();
$collection7->addFieldToFilter('customer_id', array('eq' => $cust_id));
$collection7->addFieldToFilter('grouped', array('eq' => $grouped));
foreach($collection7 as $data3)
{
$product = $data3->getData('product');
$link = $data3->getData('link');
$imageurl = $data3->getData('url');
//facebook
$title=urlencode('Shop, Save and Get Rewarded at MRuncit.com');
$url=urlencode($link);
$summary=urlencode('I just bought '.$product.' from MRuncit.com and earned some MReward Points!');
$image=urlencode($imageurl);
?>
<p>
<a href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" target="_blank">
<img src="<?php echo $imageurl;?>" width="30">
I just bought <?php echo $product; ?> from MRuncit.com and earned some MReward Points!
</a>
</p>
<?php
}
}
Results
You should create the block as child of the success block in your layout XML:
<layout_handle_of_the_success_page>
<reference name="name_of_the_success_block_in_layout">
<block type="your/referral_block" />
</reference>
</layout_handle_of_the_success_page>
Then you can insert the following line in success.phtml:
<?php echo $this->getChildHtml('referral'); ?>
There are some names in the example XML that you have to replace with your own:
layout_handle_of_the_success_page - you will find it in the layout XML of the corresponding module. It should be in the form module_controller_action --> checkout_onepage_success
name_of_the_success_block_in_layout - also from the layout XML, look for the block with the success.phtml template and its name attribute --> checkout.success
your/referral_block - that's the class alias of the block that you want to insert in the form module/class --> referral/referral

I want add custom column for sidebar all page in 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

Resources