to begin I want to thanks Andy for this usefull “featured product” module.
It works for me, but I have a little question :
I would like to use this module to display products of any categories on my home page, instead of displaying a product in a category page.
So I tried to modify the code of the function getFeaturedProduct() in the app/code/local/MyCompany/Catalog/Block/Product/Featured.php file.
But I didn’t found how to select every products of my catalog, instead of selecting products from a particular category.
Now i’m going to try to display a random item from all the items marked as featured, because I actually get the same item at every refresh.
I’ll post the code here if I find something.
Ok, I finally have a working function to display a random article from theire who are marked as featured on my home page. You have to follow this tutorial and just change the function getFeaturedProduct() from app/code/local/MyCompany/Catalog/Block/Product/Featured.php by this code :
I did as being said in the tutorial in wiki page. But it doesn’t show on any page. Is it working for any person? If so can anyone put this in the extension?
I did as being said in the tutorial in wiki page. But it doesn’t show on any page. Is it working for any person? If so can anyone put this in the extension?
I’ve just tried this and it doesn’t wokr to me. When I add the block on file “local.xml” all category pages are blank (without products).
Not to steal the significance of Andy’s thread, http://www.magentocommerce.com/boards/viewthread/4780/P0/, as it’s what got me started modding out my functions. And to get this to work you need to follow the same steps as far as getting this in place, so I won’t be redundant. Also I’m not the best of documenters.
Simply though looking at the way the Magento team handled New and Random, I simply thought, why don’t we do this with the Featured function. It would make it cleaner and utilize more of the core functions instead of using Zend DB to figure out how to build a query statement. So I don’t take much credit for this. It was already there, finding it was a chore though.
I did want it to be flexible though so that I can make it global or by category, change the order and the product number. And please note that it still is a bit custom for my needs and I’m pulling only the attributes I need.
This a snippet from my singlebycategory.phtml template that I utilize on the “Shop Now” block of my current project: http://www.netizenron.com/boomsite.php.
I successfully got this module working, however, I’m lacking a couple of things.
1. I have my featured product displayed on the same page as several other products on the category page, and the featured product is listed at the top of the page as a featured item (created from this module) then it’s also shown further down in the page with the rest of the product collection. How do I avoid repetition of the featured item?
2. I can only display the featured items name, SKU, description, and photo. I need to display all the options so a user can purchase the featured item without having to click into it’s detail page… how do I do this? Below is the code I have in featured.phtml
class MyCompany_Catalog_Block_Category_View extends Mage_Catalog_Block_Category_View { public function getFeaturedProductHtml() { return $this->getBlockHtml(’product_featured’); } } class MyCompany_Catalog_Block_Category_View extends Mage_Catalog_Block_Category_View { public function getFeaturedProductHtml() { return $this->getBlockHtml(’product_featured’); } }
Fatal error: Class ‘MyCompany_Catalog_Block_Category_View’ not found in /nfs/c02/h04/mnt/45486/domains/kehot.com.ar/html/app/code/core/Mage/Core/Model/Layout.php on line 445
I removed the <category_view> block in local xml and it displayed the products correctly. but i do not see the featured products. i followed the steps as in in WIKI but doesn’t help. let me know if there are any other issues.
cibernoid - 14 July 2008 03:37 AM
brianpat - 09 July 2008 07:35 AM
I did as being said in the tutorial in wiki page. But it doesn’t show on any page. Is it working for any person? If so can anyone put this in the extension?
I’ve just tried this and it doesn’t wokr to me. When I add the block on file “local.xml” all category pages are blank (without products).
I’ve had great success implementing a “Featured Products” block using the techniques described in Andy’s wiki article and Ron’s post earlier in this thread. I did stumble a couple of times though, so I thought I’d put together a step-by-step summary.
My aim was to have show a “Featured Products” block on the front page of my site, with the ability to restrict the products shown to a particular category, or show products from all categories. I wanted to have a random selection of my featured products displayed, and I wanted the structure and styling of the block to match the regular product grid display, minus the toolbars bottom and top. I didn’t want the featured products to appear above every product_list block, which is what Andy’s wiki article does.
2: Create the file app/code/local/MyCompany/Catalog/Block/Product/Featured.php. The code in this file is based on Ron’s, with two small differences: you need to add the argument ->addAttributeToSelect(’status’) to the getCollection() call, to avoid the out of stock bug. Also, I changed if($category) to if(isset($category)), as the former was causing an error when showing global featured products (no category_id attribute set). My amended version is below.
<?php class MyCompany_Catalog_Block_Product_Featured extends Mage_Catalog_Block_Product_Abstract { public function getProductFeatured(){
3: Write the code to mark up and display the result set. I wanted my featured products block to look like the standard product_list in grid mode, so I just copied app/design/frontend/default/default/template/catalog/product/list.phtml into featured.phtml in the same directory. I then replaced <?php $_productCollection=$this->getLoadedProductCollection() ?> with <?php $_productCollection = $this->getProductFeatured() ?>, and removed all the code pertaining to the toolbars and the list mode.
4: Add the product_featured block rewrite to local.xml, as per Andy’s wiki article, step 6. However, do not add the category_view rewrite, as this will interfere with the normal category view.
5: Finally, insert the line {{block type="catalog/product_featured" category_id="8" num_products="1" orderby="rand()" template="catalog/product/featured.phtml"}} in the CMS page where you want the block to appear. If you omit category_id, you will get featured products from all categories.
Hopefully this clarifies and brings together the excellent ideas from Andy and Ron.