Magento Forum

   
Quick question on the catalog layout…
 
beowax
Sr. Member
 
Total Posts:  94
Joined:  2007-12-17
Lille, France
 

Hi,

I’m trying to move the Related product block from the right to the product info block. Here is what is in Magento (catalog.xml) :

<reference name="content">
   <
block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
      <
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
      <
block type="core/text_list" name="alert.urls" as="alert_urls" />
      <
block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/>
      <
block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
   </
block>
</
reference>
<
reference name="right">
   <
block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>
</
reference>

So i tried to move the related block : These lines are working, but are not what i want :

<reference name="content">
   
[b]<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>[/b]
   
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
      <
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
      <
block type="core/text_list" name="alert.urls" as="alert_urls" />
      <
block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/>
      <
block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
   </
block>
</
reference>

Or

<reference name="content">
   <
block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
      <
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
      <
block type="core/text_list" name="alert.urls" as="alert_urls" />
      <
block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/>
      <
block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
   </
block>
   
[b]<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>[/b]
</reference>

Here is what i want, but the block doesn’t show :

<reference name="content">
   <
block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
      <
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
      <
block type="core/text_list" name="alert.urls" as="alert_urls" />
      
[b]<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>[/b]
      
<block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/>
      <
block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
   </
block>
</
reference>

Does anybody has an idea on how to put this in the product info block ?

Regards,
Antoine

PS: Sorry for the [ b ][ /b ], i tried to put in evidence the chages that were made.... wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
beowax
Sr. Member
 
Total Posts:  94
Joined:  2007-12-17
Lille, France
 

Does anybody knows how to move the related block to the information block ? I’stuck with this and i have a new block to add here…

Regards,
A.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wiseguy Digital
Member
 
Avatar
Total Posts:  61
Joined:  2007-09-17
Bristol, UK
 

Just a thought - not 100% sure as I’m still getting my head around the system. Have you tried removing the after="-" as I’m guessing that is a presentational attribute?

 
Magento Community Magento Community
Magento Community
Magento Community
 
beowax
Sr. Member
 
Total Posts:  94
Joined:  2007-12-17
Lille, France
 

Yes, but it doesn’t changes anything…

Do i have to add a addChildrenHTML function or something like that in the phtml file ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
youngpixel
Jr. Member
 
Total Posts:  10
Joined:  2008-06-17
Global Citizen
 

Hi !
I was stuck with this issues till now, and couldn’t find a way out, tried the same things you did, but came up with a solution. Maybe it’s not the most elegant one, but it solved my issues. Anyway, till now I don’t have a clue how to do it other way.

So that’s what I did. I moved the last three closing </div> from price.phtml, and move to related.phtml. At first the problem was that if there are no related products, the closing divs are missing and messing up the design, so what I did is included just before the end of div in related.phtml, and added an else, so that in case there are no related products it will add up the closing divs anyway.

Here is my code:

catalog.xml

<catalog_product_view>
        <!-- 
Mage_Catalog -->
        <
reference name="root">
            <
action method="setTemplate"><template>page/2columns-rosie.phtml</template></action>
        </
reference
        <
reference name="head">
            <
action method="addJs"><script>varien/product.js</script></action>
        </
reference>
        <
reference name="content">
            <
block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
                <
block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>
                <
block type="core/text_list" name="alert.urls" as="alert_urls" />
                <
block type="catalog/product_list_upsell" name="product.info.upsell" as="upsell_products" template="catalog/product/list/upsell.phtml"/>
                <
block type="catalog/product_view_additional" name="product.info.additional" as="product_additional_data" />
            </
block>
            <
block type="catalog/product_list_related" name="catalog.product.related" template="catalog/product/list/related.phtml"/>
        </
reference>
    </
catalog_product_view>

view.phtml (note the missing divs at the end of view.phtml)

<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<?php $_product=$this->getProduct() ?>
<div class="product-info-box">
    <
div class="product-essential">

        <
div class="product-img-box">
            
<?php echo $this->getChildHtml('media'?>
        
</div>

        <
div class="product-shop">
            <
h3 class="product-name"><?php echo $this->htmlEscape($_product->getName()) ?></h3>
            
<?php echo nl2br($_product->getDescription()) ?>
            
            
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
            <
fieldset>
            <
input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
            <
input type="hidden" name="related_product" id="related-products-field" value="" />
            </
fieldset>

                
<?php echo $this->getChildHtml('alert_urls'?>

                <?php 
echo $this->getChildHtml('product_type_data'?>

            
</form>
            
            <
script type="text/javascript">
                var 
productAddToCartForm = new VarienForm('product_addtocart_form');
                
productAddToCartForm.submit = function() {
                    
if(this.validator.validate()) {
                        this
.form.submit();
                    
}
                }
.bind(productAddToCartForm);
            
</script>
            
            
            
<div class="mail_friend">
                
<?php if ($this->canEmailToFriend()): ?>
                    
<a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>" class="email_btn"><?php echo $this->__('Email to a Friend'?></a>
                
<?php endif; ?>
            
</div>

.... continue >

 
Magento Community Magento Community
Magento Community
Magento Community
 
youngpixel
Jr. Member
 
Total Posts:  10
Joined:  2008-06-17
Global Citizen
 

continue 2 --->

and here is the related.phtml file

<?php if($this->getItems()->getSize()): ?>
<div class="box base-mini mini-related-items">
    <
div class="head">
        <
h4><?php echo $this->__('May We Also Recommend'?></h4>
    </
div>
    <
div class="content">
        
        
<?php foreach($this->getItems() as $_item): ?>
        
<div class="related_container">
            <
div class="product-img">
                <
a href="<?php echo $_item->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(60,77) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" width="60" height="77" /></a>
            </
div>
            <
div class="product-dtls">
                    <
a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a>
                    
<?php echo $this->helper('catalog/product')->getPriceHtml($_item?>
                    <?php 
if($_item->isSuper()): ?>
                    <?php 
else: ?>
                        <?php 
if ($this->helper('wishlist')->isAllow()) : ?>
                        
<a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist'?></a>
                        
<?php endif; ?>
                    <?php 
endif; ?>
            
</div>
            <
br class="clear"/><br />
        </
div>
       
        
<?php endforeach ?>
    
</div>
</
div>
</
div>
    </
div>
</
div>
<
p style="clear:both;"></p>
<
script type="text/javascript">
<!--
$$(
'.related-checkbox').each(function(elem){
    Event
.observe(elem'click'addRelatedToProduct)
});

var 
relatedProductsCheckFlag false;
function 
selectAllRelated(txt){
    
if (relatedProductsCheckFlag == false{
        
$$('.related-checkbox').each(function(elem){
            elem
.checked true;
        
});
        
relatedProductsCheckFlag true;
        
txt.innerHTML="<?php echo $this->__('unselect all') ?>";
    
else {
        
$$('.related-checkbox').each(function(elem){
            elem
.checked false;
        
});
        
relatedProductsCheckFlag false;
        
txt.innerHTML="<?php echo $this->__('select all') ?>";
    
}
    addRelatedToProduct
();
}

function addRelatedToProduct(){
    
var checkboxes = $$('.related-checkbox');
    var 
values [];
    for(var 
i=0;i<checkboxes.length;i++){
        
if(checkboxes[i].checkedvalues.push(checkboxes[i].value);
    
}
    
if($('related-products-field')){
        
$('related-products-field').value values.join(',');
    
}
}
//-->
</script>
<?php 
else: ?>
    
</div>
        </
div>
    </
div>
    <
p style="clear:both;"></p>
<?php endif ?>

Hope it solves ur problem too!

 
Magento Community Magento Community
Magento Community
Magento Community
 
morticya33
Jr. Member
 
Total Posts:  6
Joined:  2009-01-03
 

I think I got the answer (just in case no one else did)! smile

Instead of doing this in catalog.xml:

<block type="catalog/product_list_related" name="catalog.product.related" after="-" template="catalog/product/list/related.phtml"/>

Change it to this:

<block type="catalog/product_list_related" name="catalog.product.related" as="related_products" template="catalog/product/list/related.phtml"/>

then in app/design/frontend/default/(YOUR THEME)/template/catalog/product/view.phtml stick this code out wherever you want the related products to display:

<?php echo $this->getChildHtml('related_products'?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
nasha
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2009-04-15
 

thanks @ morticya33

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top