Tuesday, March 29, 2011

Create a simple custom module

Step One

Inform Magento that you have a custom module.
app/etc/modules/Fido_All.xml Notice the _All in the xml file name. I can declare all of my modules here. (Say I have more than Example, I can also declare my Example2 module in this file).






true
local





I have informed Magento that I have an active module (you can turn it off from here by setting ‘active’ to false. I have also informed Magento that it is located in the ‘local’ code pool.

Step Two

Configure your new module. Note the file locations (need to create directories as necessary).
app/code/local/Fido/Example/etc/config.xml






0.1.0





Fido_Example_Block






I have informed Magento of my module version (it’s an arbitrary version). Version matters when you set up your module to be update-able. (A newer version will inform Magento to run the update files if you have them).

I have also informed Magento that my module contains block files which are found in fido/example/block. My class name will have “Fido_Example_Block”. If you want to see the many possibilities of stuff that goes in here, check out Mage config files (such as Catalog/etc/config.xml). You’ll also see other xml files in there. Those explanations are for another post.

Step Three

Here is my block code. It doesn’t really do anything, but shows some functionality.
app\code\local\Fido\Example\Block\View.php


/**
* Example View block
*
* @codepool Local
* @category Fido
* @package Fido_Example
* @module Example
*/
class Fido_Example_Block_View extends Mage_Core_Block_Template
{
private $message;
private $att;

protected function createMessage($msg) {
$this->message = $msg;
}

public function receiveMessage() {
if($this->message != '') {
return $this->message;
} else {
$this->createMessage('Hello World');
return $this->message;
}
}

protected function _toHtml() {
$html = parent::_toHtml();

if($this->att = $this->getMyCustom() && $this->getMyCustom() != '') {
$html .= '
'.$this->att;
} else {
$html .= '
No Custom Attribute Found';
}

return $html;
}
}


The function receiveMessage() just returns “Hello World”
The function _toHtml() is responsible for outputting the template associated with the block. Make sure you run paret::_toHtml and return it as part of any other items returned in that function!

Step Four

Here we create our template (phtml) file.
app\design\frontend\default\fido\template\example\view.phtml


/**
* Fido view template
*
* @see Fido_Example_Block_View
*
*/
?>

This is the output of the fido example:


echo $this->receiveMessage();
?>




This just outputs some HTML and also runs the receiveMessage() function from our block (view.php).

Two caveats here. By placing our view.phtml file in it’s location, we have created our own theme. You must make sure that
a) Magento knows about your theme (Admin->System->Design)
and
b) If you use the this block in a CMS page, you set the CMS page to use your theme (Admin->CMS->Manage Pages->’Your Page’->Custom Design->Custom Theme drop down)

You’re custom module is now ready for use.


{{block type="fido_example/view" my_custom="Test" template="example/view.phtml" }}


Or something like this in the Layout Update XML area (Custom Design area in a CMS page)





//this will add your block in the right column


Now you should successfully have your block and the Hello World message being displayed (on your CMS page).

Monday, March 28, 2011

Adding a Syntax Highlighter to your Blogger blog

At last after several hours of scavenging google for a way to publish code in an organize manner which are eye friendly for visitors. I have manage to friend this wonderful blog that demonstrate step-by-step on how to do it.
Check on the link below:


http://www.cyberack.com/2007/07/adding-syntax-highlighter-to-blogger.html


Credits goes to the Author of http://www.cyberack.com and to Alex Gorbatchev
who create and manage the SyntaxHighlighter.

Hope this provides additional help

Cheers,
Spawn

Sunday, March 27, 2011

Free Wonderful Magento Templates

While Searching over the web for free magento templates, I have stumbled upon this wonderful website which shares about 12-13 Free Magento Templates. Really really nice templates. I can't believe its free, but it is. So, I decided to share it with your guys. Enjoy!

Here are some samples if the said templates.






You can download them at the link below.

http://www.magento-templates.com/free/


Cheers,
Spawn

Thursday, March 24, 2011

Magento - How to insert a custom tab in One Page Checkout?

Christian Young quoted
"I found a nice extension from Inchoo which will insert a customizable tab in Magento OnePage Checkout. So I used this extension and extended it a little bit to fit the requirements."

"What I want to do is to add a Terms & Conditions tab before placing an order. So here's the code.
/home/donnafiera/magento/app/design/frontend/default/default/template/checkout/onepage/heared4us.phtml"




<form id="co-heared4us-form" action="">
<?php
echo "I have read the <a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."test.pdf' target='_Blank'>TERMS AND CONDITIONS</a>";
?><br/><br/>

<label><input id="chkaccept" type="checkbox" name="useraccept" value="yes" />&nbsp;Accept</label><br/>
</form>
<script type="text/javascript">

function formValidation(oEvent) {
oEvent = oEvent || window.event;
var txtField = oEvent.target || oEvent.srcElement;

var t1ck=true;

if(!document.getElementById("chkaccept").checked ){ t1ck=false;}

if(t1ck){document.getElementById("btnTerms").disabled = false; }
else{document.getElementById("btnTerms").disabled = true; }
}

window.onload = function () {
var btnTerms = document.getElementById("btnTerms");
var chkaccept=document.getElementById("chkaccept");
var t1ck=false;
document.getElementById("btnTerms").disabled = true;
chkaccept.onclick = formValidation;
}
</script>
<div class="button-set">
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<div id="heared4us-buttons-container">
<button id="btnTerms" type="button" class="form-button right" onclick=" heared4us.save();"><span><?php echo $this->__('Continue') ?></span></button>
<span id="heared4us-please-wait" style="display:none;" class="opc-please-wait">
<img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" class="v-middle" alt="" /> &nbsp; <?php echo $this->__('Loading next step...') ?> &nbsp;
</span>
</div>
</div>


Original Article was posted by Mike Christian Young @ http://workingmagento.blogspot.com/2011/02/magento-how-to-insert-custom-tab-in-one.html

Cheers,
Spawn

Working Magento

Since, I don't have any interesting things in mind to post, I'd like to refer visitors to one of the most helpful site that tackles about Magento. As some know, magento is an eCommerce platform, this is widely used to make Online Shops. As a first time magento user, I find it very hard to adjust to this kind of Platform even though I have had backgrounds on other content management systems such as Joomla, Drupal, Wordpress, etc. But I Stumble upon this wonderful blogger that focuses hes articles on magento. Really, really great help.

I'd like to share the link of Mr. Michael Christian Young (Magentologist)
http://workingmagento.blogspot.com/

Cheers,
Spawn

A fresht start on Magento

This is my first Blog post. :)

I've decided to make this page to put some on the new things I found on Magento and to make a note on those things. This is for me and my associates to share with and if you are also on Magento and Ecommerce, this might be of help to you, so please fell free to read the posts.


Cheers,
Spawn