0

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 ?>
  • Yes! Because you're saying its a type of catalog/product .. That function getStoreLabel() does not exist in the block class app/code/core/Mage/Catalog/Block/Product.php – André Ferraz Jun 15 '16 at 10:30
  • The error is thrown from the price template though, which is likely a child block. We have no reference from that answer that it's even calling the method against $this. We'd need to know whats on the lines ~53 of price.phtml. – Peter O'Callaghan Jun 15 '16 at 10:31
  • This is not enough information, if you are just loading a single product then why you are using list.phtml file code, you should use view.phtml and if you need to use list.phtml code then where are you creating collection of products? One more thing if you needed only one product then how are you loading that product? Please provide full information what are you trying to do else no one can help here – Saurabh Jun 15 '16 at 14:08
  • @Saurabh updated my question – mdeveloper Jun 16 '16 at 5:08
1

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;?>
  • hey but it show same price for all products now – mdeveloper Jun 16 '16 at 5:51
  • can you share \app\design\frontend\base\default\template\related\index.phtml file code – Abdul Jun 16 '16 at 5:59
  • already shared pls check – mdeveloper Jun 16 '16 at 6:00
  • Updated ans pls check now – Abdul Jun 16 '16 at 6:04
  • can you tell what exact you changed but it works – mdeveloper Jun 16 '16 at 6:32
1

Find simple solution and its work:

Open this file : app/design/frontend/[your_package]/[your_theme]/template/catalog/product/price.phtml

Find this code:

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

And replace it with below:

$specialPriceAttr = $this->getProductAttribute('special_price');
if (!is_null($specialPriceAttr)) {
$_specialPriceStoreLabel = $this->getProductAttribute('special_price')->getStoreLabel();
} else {
$_specialPriceStoreLabel = '';
}

Reference: http://www.justwebdevelopment.com/blog/call-to-a-member-function-getstorelabel-in-price-phtml/

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.