Archive for the ‘Developent’ Category

It’s 2011 and right now everybody is jumping on the group buying bandwagon. Companies like Groupon, Living Social, Google and Facebook are all trying to leverage their massive user base to offer steep discounts to consumers. Retailers are slowly starting to pull themselves out of the recession are are desperate to find new customers. Group buying is now a viable way to get new customers. I’ve had a number of clients that have looked into this and after doing a ROI check, they find that they would actually loose money on the deals. One client in particular asked me if there was any existing extensions to Magento that could fulfill their needs. These extensions include:

Group Buy for $399.00
Great Deals Buying Extension for $299.00

I think that both of these extensions are great, but overpriced for what my clients were looking for. A quick way to offer group deals and track how many have been purchased.

After sitting down and thinking for a while I came upon a quick hack that you can use to create your own “Group Buy” functionality for Magento. We used JavaScript to create a countdown functionality, used inventory control to count the number of items left and use attributes to let our templates know that we want to display the item as a “Group Buy”. It should only take about 20 minutes to set up the functionality if you know your way around a Magento installation.

Magento Attribute group_deal

Set up Magento Attributes

To create this Magento hack you will need to create two separate custom attributes on the administrative side of Magento. Start by creating a new attribute Catalog -> Attributes -> Manage Attributes -> Add New Attribute. 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 “” 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.

Magento Group Buy Product Creation

Before we modify our Magento Template code, we need to set up our products correctly so they display them as a “Group Buy” products. Create or Edit a product that you want to offer the group deal with. To make this work on the product, we have to set the proper group buy attributes, set Magento to track the inventory of the product and offer it “On-Sale” for a set period of time.

Since we have already placed our attributes in the product “Prices” tab, we can set up the product with absolute ease. Start by setting the “Special Price” to whatever you’re going to offer the deal at. You’re 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“.

Group Buy view.phtml changes

Once you have made these changes to the products, you only have to change two files and add an image for the CSS files to serve up. There is only two files that you need to modify in your templates: Your Theme:/template/catalog/product/view.phtml and the CSS in your Skin Code, Your Theme:/css/style.css. You’ll want to add the following code to the view.phtml file after

<!--?php echo $_helper--->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?>

in the view.phtml file

Code to add:

 <!--Group Buy Code-->
<!--?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">Va Va Voom Group Deal</div>
<div id="groupbuy-l2">
<div id="groupbuy-retai-value">Value 

<span id="groupbuy-retail">$<!--?php echo $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 $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 } ?-->
<!-- /Group Buy Code -->

Group Buy style.css changes

Now add the following code to your style.css file:

/* Group Buy CSS */
#groupbuy-hdr {
width: 380px;
height: 80px;
background: url(../images/groupbuy-hdr.gif) no-repeat center center;
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: url(../images/groupbuy-hdr.gif) no-repeat;
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;
}

Finally add the following graphics to your theme skin files: Your Theme:/images/ for it to display like the illustration below. You can change the CSS code as needed to display the deal to fit your theme.

groupbuy-hdr
groupbuy-hdr

That’s it. You won’t have things fancy features like email notification if the deal doesn’t go through or any of the fancy bells and whistles that the two above extensions have to offer, but you can use it to quickly convince people to all jump in on a group deal without having to pay 50% of your net sales to another company.
Magento Group Buy Results

A number of our clients wanted to upgrade to the new WordPress 3.0. When performing the upgrades for our clients, we found that almost 1 out of every 2 clients experienced the all too common “Fatal Error: Allowed Memory Size” problem.

The WordPress forums suggested using a plug-in called Memory Bump to fix these errors. The instructions are quite clear in disabling all plug-ins before installing Memory Bump. Once it was installed, it should address the issue. After following their instructions 100%, we were not able to resolve the issue.

My initial research found that Some expert solutions have been offered including editing the php.ini file and adding “memory_limit = 128M ;”. We tried this and found that the solution did not work.

A number of sites suggested an easier solution to the problem:

  • Fire up your favorite command line editor
  • Open the “wp-config.php” file
  • Add “define(‘WP_MEMORY_LIMIT’, ’128M’);” after
  • Save the file

After reloading the administrative dashboard all functionally returned to normal.

I understand that WordPress is a complex web application. However, I think that in the near future WordPress needs to address their memory issues. They’ve had these popping up more and more since version 2.0.

Magento has the ability to globally manage inventory levels for your online store. A number of client’s business model was to sell inventory that they picked up from a distributor and therefore didn’t need to manage all items. They did have situations where they purchased items by the case and wanted to to show how many items are left back in stock.

To set and show how many items are left in stock, do the following:

Open app/design/frontend//default/template/catalog/product/view.html

Add the following code to the page where you want to render the available stock message.

<div class="divider"></div>
<div class="inventory-qty">
	<!--inv-qty-->
	<?php
	$__manStock = $_product->getStockItem()->getManageStock();
	$__invAmt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
	if ($__manStock > 0)
		{
		echo $this->__("Only $__invAmt Available in Stock");
		}
?>
	</div>
<div class="divider"></div>

Make sure to set Magento to not manage inventory. On the individual product under the “Inventory” tab using the “Manage Stock” option, un-check “Use Config Settings” and set it to “Yes”. Remember to set the QTY to the amount you have in stock. Make sure to add to your CSS File the styling you want to for the inventory-qty class.

Recently I had to create some custom code for a client to integrate Google’s Affiliate program into the checkout Process. I was surprised to find there wasn’t an explanation on how to do this easily. After a lengthy search on Magento’s community board with no avail.

Google asks you to render an image file with the following code:

<img class='PxgGlobalImage'  src="https://clickserve.cc-dt.com/link/order?vid=[Vendor ID] &oid=[Unique Order ID]&amt=[Sub-Total Amount] &prdsku=[Product 1 ID^Product 2 ID^Product 3 ID] &prdnm=[Product 1 Name^Product 2 Name^Product 3 Name] &prdqn=[Product 1 Quantity^Product 2 Quantity^Product 3 Quantity] &prdpr=[Product 1 Price^Product 2 Price^Product 3 Price] &prcatid=[Product 1 Category ID^Product 2 Category ID^Product 3 Category ID]" alt="" width="1" height="1" />

Here is the steps to implement this on your site.

Open up app/design/frontend/default/theme_name/template/checkout/success.phtml
Cut and Past the following code into the bottom of the page:

<!--Start Google Affiliate Integration-->

<?php
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);

$order = Mage::getModel('sales/order')->load($lastOrderId);
foreach ($order->getAllItems() as $item) {
        $productArray[] = array(
                "product_sku" => $item->getSku(),
                "product_magento_id" => $item->getProductId(),
                "product_name" => $item->getName(),
                "product_qty" => $item->getQtyOrdered(),
                "product_price" => $item->getPrice(),
                "product_discount_amount" => $item->getDiscountAmount(),
                "product_row_price" => $item->getPrice() - $item->getDiscountAmount(),
                 );

        };
?>

<?php
$_totalData = $order->getData();

$_subtotal = $_totalData['subtotal'];

$_orderID = $_totalData['increment_id'];

?>

<img class='PxgGlobalImage'  src="https://clickserve.cc-dt.com/link/
order?vid=KVENDORID&oid=<?php echo "$_orderID"; ?>&amt=<?php echo "$_subtotal"?>&prdsku=<?php foreach ($productArray as $key) {echo $key['product_sku']."^";};
?>&prdnm=<?php foreach ($productArray as $key) {echo $key['product_name']."^";};
?>&prdqn=<?php foreach ($productArray as $key) {echo $key['product_qty']."^";};
?>&prdpr=<?php foreach ($productArray as $key) {echo $key['product_price']."^";};
?>&prcatid=<?php foreach ($productArray as $key) {echo "your-product^";};
?>" width=1 height=1>

<!--End Google Affiliate Integration-->

Save the file to your server and Voilà, you’ve implemented the Tracking Code.

It’s a hack, so if you know a better way, please share in the comments. I still need to work to add code to properly add child categories where “Default_Category” is being placed in the pixel tracking.