1. Home
  2. Prices
  3. Guided Tour
  4. New Shop
  5. Shop Review
  6. Ecommerce Marketing
  7. Ecommerce TV
  8. Magento Developers
  9. Portfolio
  10. Blog
  11. Contact
Home > Magento Tutorials > Special Offers In Magento

Special Offers In Magento

Posted on: 28th May 2010 By: Robert Kent Leave a comment No Comments

Today I will teach you how to create a really simple yet quite functional Special Offers section on your Magento Website.

Picture the scene:

  • Randomly displays your top 3 products
  • Shows the retail price and the special offer price
  • clicks through to the product
  • can place anywhere on your website

A special offer section is really quite useful, it gives you the option to add a section to the website where the shop owner has the ability to change whats being displayed really easily. If you place it in a prominent position you will find that this really simple tool will help boost your sales through catching the visitors eye.

To start off with grab yourself a pen and pencil and some stick-back plastic….just kidding but what you do need to do is create a new category to store your special offers. Navigate to manage categories and add a new subcategory called “Special Offers” – if you wanted to you can make this disabled – so that it doesn’t show up in your navigation bar.

Secondly you add the products that you want to be displayed to this category. The easiest way to do this is to click on the category products tab when you have your category selected and simply tick the products you want to add.

Thirdly take note of the category ID – we’ll need this later.

Next you need to work out where you want to add this feature. Normally I have added it to the following places and it has worked quite well:

  • header.phtml
  • footer.phtml
  • 1-column.phtml
  • 2-columns-left.phtml

Basically you need to add it to your template file – to be included into your overall design so that it is visible on every page. If we take header.phtml as the example we can add our code to it and the special offers section will appear on every page.

So here’s the code…

<div>
<a href="/special-offers.html" title="Special Offers"><img src="/images/special-offers.gif" alt="Special Offers" /></a>
<?php
$result = array();
$category = new Mage_Catalog_Model_Category();
$category->load(17); // this is your special offers category id!
$collection = $category->getProductCollection();
foreach ($collection as $product) {
$result[] = $product->getId();
}
shuffle($result); // this shuffles the array causing the randomisation!
?>

<?php
if(!$result){ // this is optional - its if you have no items in your category
?>
<!--    <img src="/images/nopromo.gif" alt="No Active Promotions" />-->
<?php
} else {
$i=0;
foreach ($result as $_product_id){
$i++;
if($i<=5){
$_product = new Mage_Catalog_Model_Product();
$_product->load($_product_id);
?>
<div>
<p><a href="<?php echo $_product->getProductUrl() ?>"><?php echo $_product->getName(); ?></a></p>
<a href="<?php echo $_product->getProductUrl() ?>">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image')->resize(50,50) ?>" alt="<?php echo $_product->getName(); ?>" />
</a>
<p>Was:<?php echo "&pound;".number_format(round($_product->getPrice(), 2), 2); ?></p>
<p>NOW:<?php echo "&pound;".number_format(round($_product->getFinalPrice(), 2), 2); ?></p>
</div>
<?php
}
}
}
?>

</div>

The above code should be copy/pastable into one of your template files – just remember to style it all up! And good luck!

Thanks for checking out our Magento Blog at ecommerce website design.

  • Twitter
  • AIM
  • WordPress
  • LinkedIn
  • Facebook
  • StumbleUpon
  • Technorati Favorites
  • Delicious
  • Ping
  • Digg
  • Bebo
  • Reddit
  • MySpace
  • NewsVine
  • Google Bookmarks
  • Sphinn
  • Propeller

Post A Comment