Skip to content

Commit

Permalink
Magento featured products extension
Browse files Browse the repository at this point in the history
  • Loading branch information
organicinternet committed Jul 12, 2008
1 parent a492453 commit 07b2ba1
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README
@@ -0,0 +1,25 @@
Featured Products Extension For Magento
---------------------------------------

Inspired by this Magento wiki article: http://github.com/organicinternet/featured-products-magento/tree/master

This extension allows products to be flagged as 'featured' along with a numerical order in which they should be featured, lowest first. The sidebar block shows all products from the currently visible category with a 'Featured Product Order' > 0, lowest number first. If the category 'Is Anchor' then featured products will be selected, still ordered numerically, from the current category and all its children.

The latest release version of this extension should be installed from Magento Connect. If you would like to contribute or get the bleeding edge version, it is available on GitHub - http://github.com/organicinternet/featured-products-magento/tree/master

Users
-----

Once installed, a new attribute - oi_featured_product_order will appear for all your products. Setting this to 0 or leaving blank will prevent a product being featured. Any other numerical value will feature the product.

As with all things Magento if you wish to modify the behaviour or layout of this extension, override the phtml by copying into your own theme, or override the block using rewrites rather than modifying the original.

Developers
----------

If you wish to install this extension in your local magento installation and still version control with git, symlink the following files and directories:

app_code_community_OrganicInternet_FeaturedProducts -> app/code/community/OrganicInternet/FeaturedProducts
app_design_frontend_default_default_layout_organicinternet_featuredproducts.xml -> app/design/frontend/default/default/layout/organicinternet_featuredproducts.xml
app_design_frontend_default_default_template_organicinternet_featuredproducts -> app/design/frontend/default/default/template/organicinternet_featuredproducts
app_etc_modules_OrganicInternet_FeaturedProducts.xml -> app/etc/modules/OrganicInternet_FeaturedProducts.xml
@@ -0,0 +1,38 @@
<?php

class OrganicInternet_FeaturedProducts_Block_Featured_Products extends Mage_Catalog_Block_Product_Abstract
{
protected $_itemCollection;
protected function _prepareData()
{
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);

$collection->addAttributeToFilter('oi_featured_product_order', array('gt' => 0));
$collection->addCategoryFilter(Mage::getSingleton('catalog/layer')->getCurrentCategory());

$collection->load();
$this->_itemCollection = $collection;
return $this;
}

protected function _beforeToHtml()
{
$this->_prepareData();
return parent::_beforeToHtml();
}

public function getItems() {
return $this->_itemCollection;
}

public function getTopFeaturedItem() {
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getModel('catalog/layer')->prepareProductCollection($collection);

$collection->addAttributeToFilter('oi_featured_product_order', array('gt' => 0));
$collection->setPageSize(1);
$collection->load();
return $collection->getIterator()->current();
}
}
@@ -0,0 +1,5 @@
<?php

class OrganicInternet_FeaturedProducts_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup {

}
50 changes: 50 additions & 0 deletions app_code_community_OrganicInternet_FeaturedProducts/etc/config.xml
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<config>
<modules>
<OrganicInternet_FeaturedProducts>
<version>0.0.1</version>
</OrganicInternet_FeaturedProducts>
</modules>
<global>
<blocks>
<organicinternet_featuredproducts>
<class>OrganicInternet_FeaturedProducts_Block</class>
</organicinternet_featuredproducts>
</blocks>
<resources>
<organicinternet_featuredproducts_setup>
<setup>
<module>OrganicInternet_FeaturedProducts</module>
<class>OrganicInternet_FeaturedProducts_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</organicinternet_featuredproducts_setup>
<organicinternet_featuredproducts_write>
<use>core_write</use>
</organicinternet_featuredproducts_write>
<organicinternet_featuredproducts_read>
<use>core_read</use>
</organicinternet_featuredproducts_read>
</resources>
</global>
<frontend>
<translate>
<modules>
<OrganicInternet_FeaturedProducts>
<files>
<default>OrganicInternet_FeaturedProducts.csv</default>
</files>
</OrganicInternet_FeaturedProducts>
</modules>
</translate>
<layout>
<updates>
<organicinternet_featuredproducts>
<file>organicinternet_featuredproducts.xml</file>
</organicinternet_featuredproducts>
</updates>
</layout>
</frontend>
</config>
@@ -0,0 +1,16 @@
<?php

$installer = $this;
$installer->addAttribute('catalog_product', 'oi_featured_product_order', array(
'type' => 'int',
'backend_type' => 'int',
'label' => 'Featured Product Order',
'global' => true,
'default' => null,
'frontend_class' => 'validate-digits',
'visible' => false,
'required' => false,
'user_defined' => false,
));


@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<layout version="0.0.1">
<catalog_category_default>
<reference name="left">
<block type="organicinternet_featuredproducts/featured_products" name="oi_featuredproducts" as="oi_featuredproducts" template="organicinternet_featuredproducts/featured_products_sidebar.phtml" before="catalog.leftnav"/>
</reference>
<reference name="content">
<block type="organicinternet_featuredproducts/featured_products" name="oi_topfeaturedproduct" as="oi_topfeaturedproduct" template="organicinternet_featuredproducts/top_featured_product.phtml" before="category.products"/>
</reference>
</catalog_category_default>
<catalog_category_layered>
<reference name="left">
<block type="organicinternet_featuredproducts/featured_products" name="oi_featuredproducts" as="oi_featuredproducts" template="organicinternet_featuredproducts/featured_products_sidebar.phtml" before="catalog.leftnav"/>
</reference>
<reference name="content">
<block type="organicinternet_featuredproducts/featured_products" name="oi_topfeaturedproduct" as="oi_topfeaturedproduct" template="organicinternet_featuredproducts/top_featured_product.phtml" before="category.products"/>
</reference>
</catalog_category_layered>
</layout>
@@ -0,0 +1,30 @@
<?php if($this->getItems()->getSize()): ?>
<div class="box base-mini mini-featured-products">
<div class="head">
<h4><?php echo $this->__('Featured Products') ?></h4>
</div>
<div class="content">
<ol>
<?php foreach($this->getItems() as $_item): ?>
<li<?php if($_item->isSuper() || !$_item->isSaleable()): ?> class="super-products"<?php endif; ?>>
<div class="product-images">
<a href="<?php echo $_item->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" width="50" height="50" /></a>
</div>
<div class="product-details">
<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a>
<?php echo $this->helper('catalog/product')->getPriceHtml($_item) ?>
<?php if($_item->isSuper()): ?>
<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a><br/>
<?php else: ?>
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
<?php endif; ?>
<?php endif; ?>
</div>
</li>
<?php endforeach ?>
</ol>
</div>
</div>
<?php endif ?>
@@ -0,0 +1,23 @@
<?php if ($_item = $this->getTopFeaturedItem()): ?>
<div class="product-info-box">
<div class="product-essential">
<div class="top-featured-product">
<div class="product-images">
<a href="<?php echo $_item->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'image')->resize(200,200) ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" width="200" height="200" /></a>
</div>
<div class="product-details">
<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->htmlEscape($_item->getName()) ?></a>
<?php echo $this->helper('catalog/product')->getPriceHtml($_item) ?>
<?php if($_item->isSuper()): ?>
<a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->__('View Details') ?></a><br/>
<?php else: ?>
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_item) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button><br />
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php endif ?>
12 changes: 12 additions & 0 deletions app_etc_modules_OrganicInternet_FeaturedProducts.xml
@@ -0,0 +1,12 @@
<config>
<modules>
<OrganicInternet_FeaturedProducts>
<active>true</active>
<codePool>community</codePool>
<depends>
<Mage_Catalog />
</depends>
<version>0.0.1</version>
</OrganicInternet_FeaturedProducts>
</modules>
</config>

0 comments on commit 07b2ba1

Please sign in to comment.