Showing Product on Custom Page Gives Error – Magento 1.9 Fix

magento-1.9module

i am showing product on custom page created via modules

app\design\frontend\base\default\layout\related.xml

 <?xml version="1.0"?>   
    <layout version="0.1.0">   
      <related_index_index>   
        <reference name="root">   
          <action method="setTemplate"><template>page/1column.phtml</template></action>   
        </reference>   
        <reference name="content">   
          <block type="catalog/product" name="related_index" template="related/index.phtml"/>   
        </reference>   
      </related_index_index>   
    </layout> 

app\design\frontend\base\default\template\related\index.phtml
i just copied list.phtml content here with few modification

no it gives error

Fatal error: Call to a member function getStoreLabel() on a non-object in app\design\frontend\themefolder\themefile\template\catalog\product\price.phtml on line 53

i got few answer but i do not want to modify core files please suggest way to fix it

Line no 53 of price.html

$_specialPriceStoreLabel = $this->getProductAttribute('special_price')->getStoreLabel();

Updated code for my \app\design\frontend\base\default\template\related\index.phtml

Here i am show all related products of product

$model = Mage::getModel('catalog/product');
$product_id = Mage::app()->getRequest()->getParam('product');
$product = $model->load($product_id);

// Get all related product ids of $product.
$allRelatedProductIds = $product->getRelatedProductIds();

    $_helper = $this->helper('catalog/output');
    $store = Mage::app()->getStore();
    $code  = $store->getCode();

?>
<?php if(!count($allRelatedProductIds)): ?>
<?php foreach ($allRelatedProductIds as $id): 
        $_product = $model->load($id);
        ?>
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_product->getName();?></a></h3>
 <?php echo $this->getPriceHtml($_product, true) ?>
 <?php endforeach ?>

Best Answer

Add bellow code in file app\design\frontend\base\default\layout\related.xml

<?xml version="1.0"?>   
<layout version="0.1.0">   
    <related_index_index>   
        <reference name="root">   
          <action method="setTemplate"><template>page/1column.phtml</template></action>   
        </reference>   
        <reference name="content">   
          <block type="catalog/product_list" name="related_index" template="related/index.phtml"/>   
        </reference>   
    </related_index_index>   
</layout>

OR

<?xml version="1.0"?>   
<layout version="0.1.0">   
    <related_index_index>   
        <reference name="root">   
          <action method="setTemplate"><template>page/1column.phtml</template></action>   
        </reference>   
        <reference name="content">   
          <block type="catalog/product_related" name="related_index" template="related/index.phtml"/>   
        </reference>   
    </related_index_index>   
</layout> 

Also add bellow code in file app\design\frontend\base\default\template\related\index.phtml

<?php
  $model = Mage::getModel('catalog/product');
  $product_id = Mage::app()->getRequest()->getParam('product');
  $product = $model->load($product_id);

  // Get all related product ids of $product.
    $allRelatedProductIds = $product->getRelatedProductIds();

    $_helper = $this->helper('catalog/output');
    $store = Mage::app()->getStore();
    $code  = $store->getCode();

?>
<?php if(count($allRelatedProductIds)): ?>
<?php foreach ($allRelatedProductIds as $id): ?>
    <?php $_product = Mage::getModel('catalog/product')->load($id);?>
    <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_product->getName();?></a></h3>
    <?php echo $this->getPriceHtml($_product, true) ?>
<?php endforeach ?>
<?php endif;?>
Related Topic