Question

I'm would like to call a products custom attributes in my own .phtml file, but having some issues with it. Any help is greatly appreciated.

I have the following code in my template/catalog/product/view.phtml file:

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('customstuff/deliveries_returns.phtml')->toHtml(); ?>

Which calls my own custom .phtml file in template/customstuff/deliveries_returns.phtml

In that .phtml file I have this code:

Delivery Times:</strong> <?php echo $_product->getshipping_times() ?></p>Delivery Costs: <?php echo $_product->getdelivery_costs() ?></p>

I have set up custom attributes already with the attribute codes shipping_times and delivery_costs

On the front-end of my website i get the following error message: Production time: Fatal error: Call to a member function getshipping_times() on a non-object in /home/cuffandc/public_html/app/design/frontend/mytheme/default/template/customstuff/deliveries_returns.phtml on line 11

Any help is greatly appreciated!

Was it helpful?

Solution

In deliveries_return.phtml not find object proper object of Product.

You can try

<?php  
      echo $this->getLayout()->createBlock('catalog/product_view')->setTemplate('customstuff/deliveries_returns.phtml')->toHtml(); 
?>

and Add this code in deliveries_returns.phtml

<?php $_product = $this->getProduct(); ?>
 Delivery Times:</strong> <?php echo $_product->getshipping_times() ?></p>Delivery Costs: <?php echo $_product->getdelivery_costs() ?></p>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top