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.
<?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);
<?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"> <a 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($_product, true, '-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: ?> <p 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"}}
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.
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.
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 )
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.