0

I had created a featured products block for my home page as per the tutorial here although with some changes to the featured.phtml file. It worked perfectly. Then I had to remove the block and put a plain message up in it's place for a period of time. So I could restore the block I simply cut the line

 <p>{{block type="core/template" name="product_featured" as="product_featured" template="catalog/product/featured.phtml"}}</p>

from the content area of the CMS Home Page and pasted it into a file to use again at a later date. Nothing else was changed (as far as I remember). Then the time came to restore the featured products block so I removed the text I had put up and pasted the line back in to the Home Page contents. Needless to say, it no longer works! Nothing appears on the home page and the right sidebar and footer disappear as well. In the interim we did remove all our products and replace them with new ones, and I flagged three new products as featured so they would show in the block, but I don't see how that could be the problem. I tried removing the <p></p> tags in case that was the problem but Magento keeps putting them back in, so I assume that is the same as before. Here is the changed featured.phtml

 <?php
 $totalPerPage = ($this->show_total) ? $this->show_total : 6;
 $visibility = array(
 Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
 Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
 );
 $storeId = Mage::app()->getStore()->getId();
 $_productCollection = Mage::getResourceModel('reports/product_collection')
 ->addAttributeToSelect('*')
 ->setStoreId($storeId)
 ->addStoreFilter($storeId)
 ->addAttributeToFilter('visibility', $visibility)
 ->addAttributeToFilter('featured', true)
 ->setOrder('created_at', 'desc')
 ->addAttributeToSelect('status')
 ->setPageSize($totalPerPage);

 Mage::getSingleton('catalog/product_status') -> addVisibleFilterToCollection($_productCollection);
 Mage::getSingleton('cataloginventory/stock') -> addInStockFilterToCollection($_productCollection);
 Mage::getSingleton('catalog/product_visibility') -> addVisibleInSearchFilterToCollection($_productCollection);
 ?>

 <h1>Featured products</h1><br><br><div>
 <?php $_collectionSize = $_productCollection->count() ?>
 <div id="featured-div">
 <?php foreach ($_productCollection as $_product): ?>
 <div class="featuredproduct">
 <p class="product-image" style="width:240px; margin-top:20px; padding:10px 20px;">
 <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
 <img class="featuredpic" src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->keepAspectRatio(TRUE)->resize(200,200); ?>" width= "200" height="200" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a></p>
 <h5><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h5><div>
 <?php echo $_product->getShortDescription() ?></div><div>
 <?php if ($_product->getSpecialPrice()>0):?>
 <span class="old featuredprice"><?php echo Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice()) ?></span>&nbsp;
 <span class="new featuredprice"><?php echo $this->helper('checkout')->formatPrice($_product->getSpecialPrice()) ?></span><?php else: ?>
 <span class="new featuredprice"><?php echo Mage::helper('core')->currency(Mage::helper('tax')->getPrice($_product, $_product->getFinalPrice()), true, false) ?></span>
 <?php endif; ?><?php if($_product->isSaleable()): ?>
 <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart featuredbutton"
 onclick="setLocation('<?php echo Mage::helper('checkout/cart')->getAddUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button><?php else: ?>
 <p><span><?php echo $this->__('Out of stock') ?></span></p>
 <?php endif; ?></div><div class="clear"></div></div>
 <div class="clear"></div>
 <?php endforeach ?>
 </div>
 <script type="text/javascript">decorateTable('product-list-table')</script></div>

Any help gratefully appreciated.

0

Have you added block in white list

  • Login to admin panel then go to System > Permissions > Blocks
  • Add the block - Enter catalog/product_list in the field
  • Set Allowed to Yes
  • Thanks for replying Patrick. Well, this has just thrown up a different but perhaps related issue. I go to System > Permissions > Blocks, nothing is listed, I click Add new block and all I get is a white page. I can navigate back from it but can't add any permissions as a result. – Alistair67 Feb 4 '16 at 12:46
0

Turns out SUPEE-6788 hadn't installed correctly and so the permissions weren't working properly. Didn't need to add the block as it is a core/template block type. Installed now and working fine.

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.