Magento Create Daily Deal Page Programmatically

Today daily deal is most important part of eCommerce website so as magento also need so, Here are following steps with which we are able to create daily deal in our magento steps.

we divide or steps in 3 parts.

1. creating attribute.
2. codeing in view.phtml
3. updating style.css

The first attribute, should be called: “group_deal“. Set the “Catalog Input Type for Store Owner” as a “Yes/No” input type. Set the default value to “No” and make sure to set the “Apply To *” it to “All Product Types“. You can name the attribute whatever you want under the “Manage Label / Options” tab. We called ours “Group Deal” on both the Admin and Default Store Views.

We then set up a second attribute called “group_deal_number_for_deal”. We set the attribute type as a text field and made sure that we didn’t make it a required attribute. Once again set the “Apply To *” it to “All Product Types” and name it “Number Needed for Group Deal” for both the Admin and Default Store Views.

After both of the attributes are created, we need to go to Catalog -> Attributes -> Manage Attributes Sets-> and add these to whatever attribute set you want them to come upon. We added ours to the “Prices” tab to make things easy.

Applying attribute to Deal Product

Apply “Special Price” to whatever you’re going to offer the deal at. You are then going to set the length of the Group Buy deal using the “Special Price From Date” and “Special Price To Date” fields. Set the “Group Deal” to “Yes” and define “Number Needed for Group Deal” as the number needed for everyone to get the deal.

If you’re not currently managing stock inventory with Magento, you’ll need to switch to the “Inventory” tab and set the “Manage Stock” to “Yes” Set the “Qty *” to the number of “Deals” that you want to offer and “Stock Availability” to “In Stock“.

Editing View.phtml

Find the code below
[php]
<?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), ‘short_description’) ?>
[/php]

and under is place the code given below
[php]
<!–Daily Deal Code–>
<?php $currentCurrencySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol() ?>

<?php $isGroupDeal = $_product->getAttributeText(‘group_deal’) ?>

<?php $groupDealDateEnd = $_product->getSpecialToDate() ?>

<?php $mydate = date(‘M d Y h:i:s’, strtotime($groupDealDateEnd)) ?>

<?php $groupDealSpecialPrice = $_product->getSpecialPrice() ?>

<?php $groupPrice = $_product->getPrice() ?>

<?php $formattedPrice = number_format($groupPrice, 2) ?>

<?php //Geting Discount Amoutn ?>

<?php $groupDiscount = ($groupDealSpecialPrice / $groupPrice)?>

<?php $groupDiscount = $groupDiscount * 100 ?>

<?php $finalGroupDiscount = number_format($groupDiscount, 0)?>

<?php //Getting Savings Amount ?>

<?php $groupSavings = ($groupPrice – $groupDealSpecialPrice) ?>

<?php //Number Left to Get Deal ?>

<?php $groupInvAmt = (int)Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($_product)->getQty();?>

<?php $groupDealNumber =$_product->getGroupDealNumberForDeal ?>

<?php $groupDealLeft = $groupInvAmt – $groupDealNumber ?>

<?php if ( $isGroupDeal == "Yes" ) { ?>
<script type="text/javascript">// <![CDATA[
function Countdown(then) {

this.then = then;

function setElement(id, value) {
if (value.length < 2) {
value = "0" + value;
}

window.document.getElementById(id).innerHTML = value;
}

function countdown() {
now = new Date();
diff = new Date(this.then – now);

seconds_left = Math.floor(diff.valueOf() / 1000);

seconds = Math.floor(seconds_left / 1) % 60;
minutes = Math.floor(seconds_left / 60) % 60;
hours = Math.floor(seconds_left / 3600) % 24;
days = Math.floor(seconds_left / 86400) % 86400;

setElement(‘countdown-days’, days);
setElement(‘countdown-hours’, hours);
setElement(‘countdown-minutes’, minutes);
setElement(‘countdown-seconds’, seconds);

countdown.timer = setTimeout(countdown, 1000);
}

function start() {
this.timer = setTimeout(countdown, 1000);
}

start(then);
}

Countdown(new Date(""));
// ]]></script>
<div id="groupbuy">
<div id="groupbuy-hdr">
<div id="grp-buy-name">Daily Deal</div>
<div id="groupbuy-l2">
<div id="groupbuy-retai-value">Value

<span id="groupbuy-retail"><?php echo $currentCurrencySymbol.$formattedPrice ?></span>

</div>
<div id="groupbuy-discount">Discount

<span id="groupbuy-discount-percent"><?php echo $finalGroupDiscount ?>%</span>

</div>
</div>
<div id="groupbuy-savings">Savings

<span id="groupbuy-savings-price"><?php echo $currentCurrencySymbol.$groupSavings ?></span>

</div>
</div>
<div id="groupbuy-countdown">Time Left To Buy Deal

<span id="countdown-days"> </span> days <span id="countdown-hours"> </span>:<span id="countdown-minutes"> </span>:

</div>
<div id="groupbuy-number-sold">The Number of Items left to Get Deal:

<span id="DealAmount"> <?php echo $groupDealLeft ?></span>

</div>
<span id="how-it-wrks"><a href="/group-deal">How it works</a></span>

</div>
<?php } ?>
<!– Daily Deal Code End–>
[/php]

[css]
/* Daily Deal CSS */

#groupbuy-hdr {
width: 380px;
height: 80px;
background-color: #ccc;
color: white;
}
#groupbuy-countdown {
width: 380px;
text-align: center;
font: bold 26px "Lucida Grande", Lucida, Verdana, sans-serif;
margin: 10px;
color: red;
}
#groupbuy-number-sold {
text-align: center;
font: 18px "Lucida Grande", Lucida, Verdana, sans-serif;
width: 380px;
height: 80px;
color: white;
background-color: #ccc;
padding-top: 10px;
}
span#DealAmount {
font-size: 32px;
font-weight: bold;
}
#groupbuy-savings {
width: 125px;
height: 32px;
float: right;
text-align: center;
font: bold 16px "Lucida Grande", Lucida, Verdana, sans-serif;
}
#groupbuy {
position: relative;
margin-top: 20px;
}
#groupbuy-retai-value {
width: 125px;
height: 32px;
float: left;
text-align: center;
font: bold 16px "Lucida Grande", Lucida, Verdana, sans-serif;
}
#groupbuy-discount {
width: 125px;
height: 32px;
float: right;
text-align: center;
font: bold 16px "Lucida Grande", Lucida, Verdana, sans-serif;
}
#grp-buy-name {
font-weight: bold;
font-size: 24px;
text-align: center;
width: 380px;
height: 22px;
padding-top: 10px;
}
#groupbuy-l2 {
float: left;
width: 250px;
}
[/css]

Comments (6)

  1. Ernestknox007

    thanks it works

  2. Peter

    First of all, thanks for sharing your thoughts and code! But unfortunatly this does not work with Magento 1.5.1. I followed all your steps and checked it all over again. But nothing changes in frontend, also after cleaning cash and reindex everything.

  3. Peter

    Ok, sorry it does the job. But when you use an other language $isGroupDeal == “Yes” have to be change to the correct localisation. For example in Dutch this has to be changed to “Ja”.

    Now the I have to figure out how to show up time left correctly. Because I get: NaN days NaN:NaN:

    Do you have a suggestion?

  4. pardeep kumar

    @peter
    to get the timer working
    Replace:
    Countdown(new Date(“”));

    to:
    Countdown(new Date(“”));

    Also add

    after
    :

    Thanks,
    Pardeep

    1. Subhan

      Pradeep…. I did not understand what to replace with what! since both are same.

  5. Aksam Zarook

    Is this guide still working on new Magento installations? I want to build an ecommerce store with a daily deals section for a client.

Leave a Comment

Your email address will not be published. Required fields are marked *

*