Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 6
Special Price Page
 
olmomp
Jr. Member
 
Total Posts:  8
Joined:  2008-05-16
Bremen, Germany
 

Hey, I think I figured out a much nicer way, without copy and pasting or modifying core config files.

Show all products that have a special price, using your regular catalog/product/list.phtml template

1) Create a file /app/code/local/Mage/Catalog/Block/Product/Special.php with the following code:

class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List 
{
    
/**
     * Retrieve loaded category collection
     *
     * @return Mage_Eav_Model_Entity_Collection_Abstract
     */
    
protected function _getProductCollection()
    
{     
        $todayDate 
date('m/d/y');
        
$tomorrow mktime(000date('m'), date('d')+1date('y'));
        
$tomorrowDate date('m/d/y'$tomorrow);

        
$collection Mage::getResourceModel('catalogsearch/advanced_collection')
            ->
addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->
addMinimalPrice()
            ->
addStoreFilter();
        
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);

        
$collection->addAttributeToFilter('special_from_date', array('date' => true'to' => $todayDate))
                    ->
addAttributeToFilter('special_to_date', array('or'=> array(
                        
=> array('date' => true'from' => $tomorrowDate),
                        
=> array('is' => new Zend_Db_Expr('null')))
                        ), 
'left');
   
          return 
$collection;
    
}

}

2) Create a CMS page calling the list.phtml with our newly created block:

{{block type="catalog/product_special" template="catalog/product/list.phtml"}}

3) Nope, that’s it already. If I missed something please let me know, haven’t done extensive testing yet! :)

So what did we wo? We created a new class that extends our general list view block. It does everything just like app/code/core/Mage/Catalog/Block/Product/List.php , just the product collection is a different one (thanks to devin above for the code). The List.php is also the file you want to look at in case you’d like to change more details in your list view. Just overwrite the methods you’d like to change, and remember you can always call the parent one with parent::parentMethod()

For the SEO problem (same product, different URL) check out this blog entry.

 
Magento Community Magento Community
Magento Community
Magento Community
 
olgri
Jr. Member
 
Total Posts:  19
Joined:  2008-12-22
 

@ okie

hmm it seems you’ve missed some steps out…
I get the following error when use your instructions :-(

class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List { /** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { $todayDate = date(’m/d/y’); $tomorrow = mktime(0, 0, 0, date(’m’), date(’d’)+1, date(’y’)); $tomorrowDate = date(’m/d/y’, $tomorrow); $collection = Mage::getResourceModel(’catalogsearch/advanced_collection’) ->addAttributeToSelect(Mage::getSingleton(’catalog/config’)->getProductAttributes()) ->addMinimalPrice() ->addStoreFilter(); Mage::getSingleton(’catalog/product_status’)->addVisibleFilterToCollection($collection); Mage::getSingleton(’catalog/product_visibility’)->addVisibleInSearchFilterToCollection($collection); $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’); return $collection; } }
Fatal error: Class ‘Mage_Catalog_Block_Product_Special’ not found in /home/dredgenz/public_html/app/code/core/Mage/Core/Model/Layout.php on line 462

Btw I use v. 1.3.2.3

 
Magento Community Magento Community
Magento Community
Magento Community
 
kkrieger
Member
 
Total Posts:  39
Joined:  2008-11-27
Saarbrücken
 

Try my solution:

I user new.php as basis.

/app/code/local/Mage/Catalog/Block/Product/Special.php

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * New products block
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_Abstract
{
    
protected $_productsCount null;

    const 
DEFAULT_PRODUCTS_COUNT 5;

    protected function 
_beforeToHtml()
    
{
        $todayDate  
Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        
        
$collection Mage::getResourceModel('catalog/product_collection');
        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
        
        
$collection $this->_addProductAttributesAndPrices($collection)
            ->
addStoreFilter()
            ->
addAttributeToFilter('special_from_date', array('date' => true'to' => $todayDate))
            ->
addAttributeToFilter('special_to_date', array('or'=> array(
                
=> array('date' => true'from' => $todayDate),
                
=> array('is' => new Zend_Db_Expr('null')))
            ), 
'left')
            ->
addAttributeToSort('special_from_date''desc')
            ->
setPageSize($this->getProductsCount())
            ->
setCurPage(1)
        ;
        
$this->setProductCollection($collection);

        return 
parent::_beforeToHtml();
    
}

    
public function setProductsCount($count)
    
{
        $this
->_productsCount $count;
        return 
$this;
    
}

    
public function getProductsCount()
    
{
        
if (null === $this->_productsCount{
            $this
->_productsCount self::DEFAULT_PRODUCTS_COUNT;
        
}
        
return $this->_productsCount;
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
kkrieger
Member
 
Total Posts:  39
Joined:  2008-11-27
Saarbrücken
 

Template: (Basis new.phtml)
/app/design/frontend/package/theme/template/catalog/product/special.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   default_default
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php 
if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<table class="products-grid" id="new-products-list-table">    
    
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php 
if ($i>2): continue; endif; ?>
            
<tr>
                <
td<?php if($i==0){echo ' class="first"';} ?>>
                    <
div class="line-x-divider"></div>
                    <
div class="product-col-1">
                        <
class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(80, 77) ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                    </
div>
                    <
div class="product-col-2">
                        <
h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
                        
<?php echo $this->getReviewsSummaryHtml($_product'short'?>                        
                        <?php 
echo $this->getPriceHtml($_producttrue'-new'?>                        
                        <?php 
if($_product->isSaleable()): ?>
                        
<button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
                        <
div class="clear"></div>
                        
<?php else: ?>
                        
<class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock'?></span></p>
                        <
div class="clear"></div>
                        
<?php endif; ?>
                        
<ul class="add-to-links">
                            
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                                
<li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>"><?php echo $this->__('Add to Wishlist'?></a></li>
                            
<?php endif; ?>
                            <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                
<li class="last"><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a></li>
                            
<?php endif; ?>
                        
</ul>
                    </
div>
                    <
br class="clear" />
                </
td>
            </
tr>
    
<?php $i++; endforeach; ?>        
</table>
<?php endif; ?>

In CMS-Page:
{{block type="catalog/product_special" template="catalog/product/special.phtml"}}

 
Magento Community Magento Community
Magento Community
Magento Community
 
olgri
Jr. Member
 
Total Posts:  19
Joined:  2008-12-22
 

@ kkrieger

Thank you for your posts! I don’t get the error anymore. However the products with special price are not displayed either…

i dunno why… I did everything exactly as you said but it’s just not working.. :-(

what magento version are you using?
did you do anything to app/etc/local.xml file? or maybe smth else?

 
Magento Community Magento Community
Magento Community
Magento Community
 
calik21
Jr. Member
 
Total Posts:  2
Joined:  2009-09-20
 

Hi,im new to this site and i also can’t view the product and their prices. Could someone help me with this? Thanks!

Regards,
calik21
Placement financier

 
Magento Community Magento Community
Magento Community
Magento Community
 
gizmocn
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2007-09-13
Xi'an, China
 

kkrieger, Thanks, it works in my hosting.

Just one thing, if you use Linux server, the first letter of “Special.php” must be captical.

 
Magento Community Magento Community
Magento Community
Magento Community
 
N88888
Jr. Member
 
Total Posts:  4
Joined:  2008-12-05
 

Hello,

I just wanted to put my 2 cents in on this one smile

What I did:
1) Created an attribute called “pricebreak” in Admin>Catalog>Attributes>Manage Attribute
b) set it up with drop down options of 10%, 20% 30% etc. (save)

2) Add the new Attribute to the Default Attribute set in Admin>Catalog>Attributes>Manage Attribute Sets inside the “Price” tab Section...or wherever you want it. (save)

3) Now go to Admin>Promotions>Catalog Price Rules and set up one rule for each option you created in step “1” (IE: “if: pricebreak: 10%: percent off original: 10) Do the same for 20%, 30% and the rest

Drawbacks I have found:
Each product needs to be edited or mass edited when the sale starts and ends. if you have a lot of products it might be a pain in the donkey. But it works for me and I thought I would share.

N8--->

 
Magento Community Magento Community
Magento Community
Magento Community
 
toinus
Jr. Member
 
Total Posts:  27
Joined:  2009-04-09
 
kkrieger - 11 September 2009 02:36 AM

Try my solution:

/app/code/local/Mage/Catalog/Block/Product/Special.php
<?php

I use your post to create a Special Price Module and works great in the setup you describe.
However, in my case I create the block using the XML in page_layout_update and this creates a display bug I can’t manage to fix.

The derivated code is :

<reference name="left">
<block type="catalog/product_special" template="catalog/product/special.phtml"></block>
</reference>

The module is correctly displayed in left column but is also duplicated at the end of the page, after magento’s footer.

I don’t know if this is linked specifically to your extension, but would love to fix this!

Regards,
Antoine

 
Magento Community Magento Community
Magento Community
Magento Community
 
Shven
Jr. Member
 
Total Posts:  12
Joined:  2008-10-25
 

Does kkrieger’s solution show all special priced products? (including catalogue price rules?)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Red Mouse Computers
Sr. Member
 
Total Posts:  123
Joined:  2009-10-04
 

thank you so much kkrieger. Your code worked for me. I’ve been trying to implement something like this on my website for a “Daily Deals” sidebar block on the homepage. Good man (Or woman smile )

 
Magento Community Magento Community
Magento Community
Magento Community
 
Red Mouse Computers
Sr. Member
 
Total Posts:  123
Joined:  2009-10-04
 

Here’s a SS of what i’ve done with it so far. Every 7 days i pic 7 products to be featured as Daily Deals and magento auto shows/removes the products based on the “Special Price From/To” dates.

Image Attachments
Clipboard01.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
alex2k
Jr. Member
 
Total Posts:  21
Joined:  2009-01-30
 

I use kkrieger code and it’s work
But the problem is display 3 products only, which I have more than 10 products with special price.

Any idea how to get all products with special price listed?
Also, how to make the look like homepage with grid?

Really appreciate for any help..

 
Magento Community Magento Community
Magento Community
Magento Community
 
Red Mouse Computers
Sr. Member
 
Total Posts:  123
Joined:  2009-10-04
 
alex2k - 18 January 2010 09:43 PM

I use kkrieger code and it’s work
But the problem is display 3 products only, which I have more than 10 products with special price.

Any idea how to get all products with special price listed?
Also, how to make the look like homepage with grid?

Really appreciate for any help..

here’s the code i have to only display 1 product. you can change it to display the number you want

<block type="catalog/product_special" name="daily.deals" template="catalog/product/special.phtml" before="-">
    <
action method="setProductsCount"><count>1</count></action>
    <
action method="addPriceBlockType">
      <
type>bundle</type>
      <
block>bundle/catalog_product_price</block>
      <
template>bundle/catalog/product/price.phtml</template>
    </
action>
</
block>

just change the “1” in the code to whatever number you want

 
Magento Community Magento Community
Magento Community
Magento Community
 
alex2k
Jr. Member
 
Total Posts:  21
Joined:  2009-01-30
 

Hi,

Where did you put this code?
Can you please more specific ?

Thank you....

Red Mouse Computers - 18 January 2010 09:47 PM

here’s the code i have to only display 1 product. you can change it to display the number you want

<block type="catalog/product_special" name="daily.deals" template="catalog/product/special.phtml" before="-">
    <
action method="setProductsCount"><count>1</count></action>
    <
action method="addPriceBlockType">
      <
type>bundle</type>
      <
block>bundle/catalog_product_price</block>
      <
template>bundle/catalog/product/price.phtml</template>
    </
action>
</
block>

just change the “1” in the code to whatever number you want
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 6