Magento Special price products page
Magento special price products page. We will be creating a new CMS page that will display all the Special or Sale products. We can make a product as a Special by filling it’s “Special From” and “Special To” price in “Prices” tab in Manage Products individual screen.
So let’s first create CMS Page, by going to CMS > Pages, which we will name it as “Specials”. In the Content tab of that Page, paste the below line of code:
{{block type="catalog/product_special" template="catalog/product/list.phtml" column_count="3" num_products="0"}} |
and save the page.
– Here we are saying Magento to display Product List template by looking at our new block type file, Catalog/Product/Block/Special.php. So let’s create this file, Special.php in local/Mage/Catalog/Product/Block/ directory. You will have to create this directory path if it’s not already there.
<?php | |
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List | |
{ | |
protected function _getProductCollection() | |
{ | |
if (is_null($this->_productCollection)) { | |
$categoryID = $this->getCategoryId(); | |
if($categoryID) | |
{ | |
$category = new Mage_Catalog_Model_Category(); | |
$category->load($categoryID); // this is category id | |
$collection = $category->getProductCollection(); | |
} else | |
{ | |
$collection = Mage::getResourceModel('catalog/product_collection'); | |
} | |
$todayDate = date('m/d/y'); | |
$tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y')); | |
$tomorrowDate = date('m/d/y', $tomorrow); | |
Mage::getModel('catalog/layer')->prepareProductCollection($collection); | |
$collection->addAttributeToSort('created_at', 'desc'); | |
$collection->addStoreFilter(); | |
$collection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate)) | |
->addAttributeToFilter('special_to_date', array('or'=> array( | |
0 => array('date' => true, 'from' => $tomorrowDate), | |
1 => array('is' => new Zend_Db_Expr('null'))) | |
), 'left'); | |
$numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0; | |
$collection->setPage(1, $numProducts)->load(); | |
$this->_productCollection = $collection; | |
} | |
return $this->_productCollection; | |
} | |
} |
25 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Tag Cloud
500 internal server error admin answers attribute bug category checkbox checkout cookie customer difference domain name EAV error event extension interview invoice jquery linux magento magento2 magento admin magento error magento interview questions magento orm mysql observer order pinterest product products questions redirect register remove script session simplexml to array state status study guide tax url wordpress
Hi there,
Thanks for the tutorial – I’m developing a Magento site however when I enter the code you’ve mentioned I receive an exception of “exception ‘Mage_Core_Exception’ with message ‘Invalid block type: Mage_Catalog_Block_Product_Special'” and the page dies halfway through loading. Do you have any suggestions please?
Many thanks, Chris
I hope you have created the file Special.php at “app/code/local/Mage/Catalog/Block/Product/” and pasted the content of the file I provided in the post. If the file is in place, then you should not get this error.
Hi Sir,
I want to hide all products which have special price(ie if product contain special price it should be hidden from listing page),
i have tried with layer.php as well as list.php but i haven’t find solution please help me out .
how should hide all the products which which have special prices as null
i have also tried to addAttributetofilter but haven’t find solution.
Please Reply as soon as possible.
Hi. In products list.phtml file, filter $_productCollection with special_price equal to null. Something like
Hi,
Thanks for this post.It really helps a lot.
Can you tell me how can i add left panel filters like on normal category page to this special product page.
Hi
What about if I am using Magento enterprise, dose the same code apply or i need to do some changes to the codes.
Yes it should apply, although I have not checked it. Check it in your local and if it works, then move it to production.
Just tried following you great tutorial, but i just get a blank CMS page when loading it 🙁
Placed the code in the 2 places mentioned
I think the problem is the folder structure
I had to create the folders “Mage” –> “Catalog” –> “Product” –> “Block” so I could place the Special.php
Shouldn’t the folder structure be there already? http://screencast.com/t/ZrDOE4I3
Hi Allan, the file/folder structure should be Mage -> Catalog -> Block -> Product -> Special.php
The folder structure will not there already, as we are doing it in local codepool.
Check all the steps are done correctly, it should work.
Changed the structure: http://screencast.com/t/r3Byd0hcF
CMS page looks like this: http://screencast.com/t/SwRR4VKt2DzO
Still no special products shows up 🙁
What I can suggest is:
Check if you have atleast 1 special product. Special From and To dates should be valid. Clear cache.
Nothing :-(… This is the special product: http://screencast.com/t/UgLbVMECJHi
Price is there, and dates are valid..
Anyways, thank your for your help
http://www.net-ost.dk/specials
Everything should be alright.. Path is correct, and product is enabled with specialprice for valid dates
http://www.net-ost.dk/specials
Changed the structure: http://screencast.com/t/r3Byd0hcF
CMS page looks like this: http://screencast.com/t/SwRR4VKt2DzO
Still no special products shows up 🙁
Hi Allan, I know this is very late reply but I just came across this page and checked your screenshots again to know why it was not working for you. The issue was, the double quotes were not in correct format. This usually happens if you copy-paste the code, and as double quotes are easily missed to get noticed.
Hope this will help someone with such kind of issue.
Hi,
how to limit the number of displayed products?
how to use buttons to sort the product?
Allan try turn off compilation.
Hi, thank you for this code, it is working great on Magento 1.7.0.2.
http://www.huckleberrysmenswear.co.uk/sale
My friend I used your code and it works fine but I have problems with the template, it shows in disorder the products… can we use layered navigation? 🙂 Thanks for your help
forgot to paste the page 🙂
http://www.trapolis.com/ofertas-especiales
I forgot to paste the page 🙂
http://www.trapolis.com/ofertas-especiales
Is it compulsary to create a page with name “Specials”. Can I call block code in other cms page?
Thank you for this code.. Worked well… Thanks a lot
it works for me. thanks for a great tutorial Kalpesh.
Many thanks Kalpesh .
Thank you for post, I have import this code , but CMS page blank, Please help me…