I'm trying to display products with same attribute in product view. I had my code in view.phtml and now i want to remove it and calling it using getChildHtml() function. my block definition :

<block type="catalog/product_view" name="product.info.samecollection" as="same_collection_products" template="catalog/product/list/samecollection.phtml">

my same_collection.phtml:

 <?php $_product = Mage::getModel('catalog/product')->load();
  $col = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('collection_titelive',array('like'=>$_product->getCollectionTitelive()))->load();
  <?php foreach($col as $same_col){
     $same_col = Mage::getModel('catalog/product')->load($same_col->getId()); 
  <a href="<?php echo $same_col->getProductUrl();?>"><img alt="<?php echo $same_col->getName();?>" src="<?php echo $same_col->getImageUrl();?>"  height="125" width="125"></a>
    <?php }?>

In my view.phtml, i have:

 <?php echo $this->getChildHtml('same_collection_products')?>

I would like to note that i tested the block with simple html and it was displayed and that first method of fetching products from product view also dispalyed the correct items.

I'm relatively new to magento so if you have any insights.

Thank you in advance.


Instead of the first line $_product = Mage::getModel('catalog/product')->load(); (that actually does nothing useful) try this:

$_product = Mage::registry('current_product');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.