Category Archives: Magento

A New registration form for wholesale customer……

It is quite easy after doing this, but before doing, it looks very ugly
my motto is to create a new form for registration of a specific customer group. Here I will take “Wholesale” customer group for this example
So It need some basic step as we here can also see the override in magento which will also apply in it.
So first describe the way of it.
1. First we have to create the controller action for this method
2. the we have to override Helper for get the controller method
3. Now we have to override the Block for create the function to generate the wholesale register form url
4. Now we have to create the wholesale register form in template
5. Then we have to edit login.phtml to give the link for the customer to select the wholesale/general customer form
6. Finally we have to edit the customer layout for the page

Now here I give the code one by one
1. A xml file for the module
location:: app/etc/modules/Li_Customer.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<modules>
		<Li_Customer>
			<active>true</active>
			<codePool>local</codePool>
		</Li_Customer>
	</modules>
</config>

2. New new override module in local folder
Location:: local/Li/Customer/etc/confog.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Li_Customer>
            <version>0.1.0</version>
        </Li_Customer>
    </modules>
    <frontend>
        <routers>
            <customer>
                <use>standard</use>
                <args>
                    <module>Li_Customer</module>
                    <frontName>customer</frontName>
                </args>
            </customer>
        </routers>
</frontend>	
<global>
	<blocks>
	  <customer>
		  <rewrite>
			  <form_login>Li_Customer_Block_Form_Login</form_login>
		 </rewrite>
	  </customer>
   </blocks>

 	<routers>
		<customer>
			<rewrite>
				<li_customer_account>
				  <from><![CDATA[#^/account/#]]></from>
				  <to>/customer/account/</to>
				</li_customer_account>
			</rewrite>
		</customer>
	</routers>
	<helpers>
		  <customer>
			  <rewrite>
				  <data>Li_Customer_Helper_Data</data>
			 </rewrite>
		  </customer>
	 </helpers>
</global>
</config>

3. Now we can begin our work
Override controller
Localtion: Li/Customer/controllers/AccountController.php

<?php 
/**
******
**# Controllers are not autoloaded so you will have to do it manually:
**/
?>
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Li_Customer_AccountController extends Mage_Customer_AccountController
{
	
   public function createwholesaleAction()
    {
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*');
            return;
        }
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->renderLayout();
    }
}

4.Override Helper
Location:Li/Customer/Helper/Data.php

<?php

class Li_Customer_Helper_Data extends Mage_Customer_Helper_Data
{
   /**
     * Retrieve Wholesale customer register form url
     *
     * @return string
     */
    public function getWholesaleRegisterUrl()
    {
        return $this->_getUrl('customer/account/createwholesale');
    }
}

5. Override Block
Location: Li/Customer/Block/Form/Login.php

<?php

class Li_Customer_Block_Form_Login extends Mage_Customer_Block_Form_Login
{
   // override existing method
  //write new function
   /**
     * Retrieve create new Whole sale account url
     *
     * @return string
     */
    public function getCreateWholesaleAccountUrl()
    {
        $url = $this->getData('create_account_url');
        if (is_null($url)) {
            $url = $this->helper('customer')->getWholesaleRegisterUrl();
        }
        return $url;
    }
}

6. customer layout for the new url
Location: yourtheme/layout/customer.xml

<!--after <customer_account_create translate="label">-->

<!-- new wholesale account
	-->
	<customer_account_createwholesale translate="label">
        <label>WholeSale Customer Account Registration Form</label>
        <!-- Mage_Customer -->
        <remove name="right"/>
        <remove name="left"/>

        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="customer/form_register" name="customer_form_wholesaleregister" template="customer/form/wholesaleregister.phtml">
                <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                    <label>Form Fields Before</label>
                </block>
            </block>
        </reference>
    </customer_account_createwholesale>

7.Link for the user 
Location: yourtheme/template/customer/form/login.phtml

<div class="buttons-set">
                    <button type="button" title="<?php echo $this->__('Create a Wholesale Customer Account') ?>" class="button" onclick="window.location='<?php echo $this->getCreateWholesaleAccountUrl() ?>';"><span><span><?php echo $this->__('Create a Wholesale Customer Account') ?></span></span></button>
                </div>

Add this where you want to see…

8. Now the register form
Location: yourtheme/template/customer/form/wholesaleregister.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Create account form template
 *
 * @see Mage_Customer_Block_Form_Register
 */
?>
<?php $this->setShowAddressFields(true); ?>
<div class="account-create">
    <div class="page-title">
        <h1><?php echo $this->__('Create an Account') ?></h1>
    </div>
    <?php echo $this->getChildHtml('form_fields_before')?>
    <?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
    <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="form-validate">
        <div class="fieldset">
            <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl() ?>" />
            <input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl() ?>" />
            <h2 class="legend"><?php echo $this->__('Personal Information') ?></h2>
            <ul class="form-list">
                <li class="fields">
                    <?php echo $this->getLayout()->createBlock('customer/widget_name')->setObject($this->getFormData())->toHtml() ?>
                </li>
                <li>
                    <label for="email_address" class="required"><em>*</em><?php echo $this->__('Email Address') ?></label>
                    <div class="input-box">
                        <input type="text" name="email" id="email_address" value="<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>" title="<?php echo $this->__('Email Address') ?>" class="input-text validate-email required-entry" />
                    </div>
                </li>           
                <?php if ($this->isNewsletterEnabled()): ?>
                <li class="control">
                    <div class="input-box">
                        <input type="checkbox" name="is_subscribed" title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" id="is_subscribed"<?php if($this->getFormData()->getIsSubscribed()): ?> checked="checked"<?php endif; ?> class="checkbox" />
                    </div>
                    <label for="is_subscribed"><?php echo $this->__('Sign Up for Newsletter') ?></label>
                </li>
                <?php endif ?>
            <?php $_dob = $this->getLayout()->createBlock('customer/widget_dob') ?>
            <?php if ($_dob->isEnabled()): ?>
                <li><?php echo $_dob->setDate($this->getFormData()->getDob())->toHtml() ?></li>
            <?php endif ?>
            <?php $_taxvat = $this->getLayout()->createBlock('customer/widget_taxvat') ?>
            <?php if ($_taxvat->isEnabled()): ?>
                <li><?php echo $_taxvat->setTaxvat($this->getFormData()->getTaxvat())->toHtml() ?></li>
            <?php endif ?>
            <?php $_gender = $this->getLayout()->createBlock('customer/widget_gender') ?>
            <?php if ($_gender->isEnabled()): ?>
                <li><?php echo $_gender->setGender($this->getFormData()->getGender())->toHtml() ?></li>
            <?php endif ?>
            </ul>
        </div>
    <?php if($this->getShowAddressFields()): ?>
        <div class="fieldset">
            <input type="hidden" name="create_address" value="1" />
            <h2 class="legend"><?php echo $this->__('Address Information') ?></h2>
            <ul class="form-list">
                <li class="fields">
                    <div class="field">
                        <label for="company"><?php echo $this->__('Company') ?></label>
                        <div class="input-box">
                            <input type="text" name="company" id="company" value="<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>" title="<?php echo $this->__('Company') ?>" class="input-text" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="telephone" class="required"><em>*</em><?php echo $this->__('Telephone') ?></label>
                        <div class="input-box">
                            <input type="text" name="telephone" id="telephone" value="<?php echo $this->htmlEscape($this->getFormData()->getTelephone()) ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text required-entry" />
                        </div>
                    </div>
                </li>
                <li class="wide">
                    <label for="street_1" class="required"><em>*</em><?php echo $this->__('Street Address') ?></label>
                    <div class="input-box">
                        <input type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getFormData()->getStreet(1)) ?>" title="<?php echo $this->__('Street Address') ?>" id="street_1" class="input-text required-entry" />
                    </div>
                </li>
            <?php for ($_i=2, $_n=$this->helper('customer/address')->getStreetLines(); $_i<=$_n; $_i++): ?>
                <li class="wide">
                    <div class="input-box">
                        <input type="text" name="street[]" value="<?php echo $this->htmlEscape($this->getFormData()->getStreet($_i)) ?>" title="<?php echo $this->__('Street Address %s', $_i) ?>" id="street_<?php echo $_i?>" class="input-text" />
                    </div>
                </li>
            <?php endfor ?>
                <li class="fields">
                    <div class="field">
                        <label for="city" class="required"><em>*</em><?php echo $this->__('City') ?></label>
                        <div class="input-box">
                            <input type="text" name="city" value="<?php echo $this->htmlEscape($this->getFormData()->getCity()) ?>" title="<?php echo $this->__('City') ?>" class="input-text required-entry" id="city" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="region_id" class="required"><em>*</em><?php echo $this->__('State/Province') ?></label>
                        <div class="input-box">
                            <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" class="validate-select" style="display:none;">
                                <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                            </select>
                            <script type="text/javascript">
                            //<![CDATA[
                                $('region_id').setAttribute('defaultValue', "<?php echo $this->getFormData()->getRegionId() ?>");
                            //]]>
                            </script>
                            <input type="text" id="region" name="region" value="<?php echo $this->htmlEscape($this->getRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
                        </div>
                    </div>
                </li>
                <li class="fields">
                    <div class="field">
                        <label for="zip" class="required"><em>*</em><?php echo $this->__('Zip/Postal Code') ?></label>
                        <div class="input-box">
                            <input type="text" name="postcode" value="<?php echo $this->htmlEscape($this->getFormData()->getPostcode()) ?>" title="<?php echo $this->__('Zip/Postal Code') ?>" id="zip" class="input-text validate-zip-international required-entry" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="country" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
                        <div class="input-box">
                            <?php echo $this->getCountryHtmlSelect() ?>
                        </div>
                    </div>
                </li>
            </ul>
            <input type="hidden" name="default_billing" value="1" />
            <input type="hidden" name="default_shipping" value="1" />
        </div>
    <?php endif; ?>
        <div class="fieldset">
            <h2 class="legend"><?php echo $this->__('Login Information') ?></h2>
            <ul class="form-list">
                <li class="fields">
                    <div class="field">
                        <label for="password" class="required"><em>*</em><?php echo $this->__('Password') ?></label>
                        <div class="input-box">
                            <input type="password" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" />
                        </div>
                    </div>
                    <div class="field">
                        <label for="confirmation" class="required"><em>*</em><?php echo $this->__('Confirm Password') ?></label>
                        <div class="input-box">
                            <input type="password" name="confirmation" title="<?php echo $this->__('Confirm Password') ?>" id="confirmation" class="input-text required-entry validate-cpassword" />
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="buttons-set">
            <p class="required"><?php echo $this->__('* Required Fields') ?></p>
            <p class="back-link"><a href="<?php echo $this->escapeUrl($this->getBackUrl()) ?>" class="back-link"><small>&laquo; </small><?php echo $this->__('Back') ?></a></p>
            <button type="submit" title="<?php echo $this->__('Submit') ?>" class="button"><span><span><?php echo $this->__('Submit') ?></span></span></button>
        </div>
    </form>
    <script type="text/javascript">
    //<![CDATA[
        var dataForm = new VarienForm('form-validate', true);
        <?php if($this->getShowAddressFields()): ?>
        new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>, undefined, 'zip');
        <?php endif; ?>
    //]]>
    </script>
</div>

Show a Custom or default attributes in the phtml file

To show a particular attributes value of the products u have to add this simple code

For Text attributes

$_product->getData('attribute_name') 

For Dropdown attributes

$_product->getAttributeText('attribute_name') 

It is so simple….

Add Image in a Custom database and render it

namespace(Imran)/yourmodule(news)/Block/Adminhtml/News/Edit/Tab/Form.php
in adding field

$fieldset->addField('image', 'image', array(
			'label'     => Mage::helper('news')->__('Image'),
			'required'  => false,
			'name'      => 'newsimage',
		));

in controller add those line before save

  if(isset($_FILES['newsimage']['name']) && $_FILES['newsimage']['name'] != '') {
                    echo"I am here";
				try {
					$uploader = new Varien_File_Uploader('newsimage');

	           		$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
					$uploader->setAllowRenameFiles(false);

					$uploader->setFilesDispersion(false);

					$path = Mage::getBaseDir('media').DS;//.'social';
					$uploader->save($path, $_FILES['newsimage']['name']);

				} catch (Exception $e) {
                                    Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                                    Mage::getSingleton('adminhtml/session')->setNewsData($this->getRequest()->getPost());
                                    $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                                    return;
                                }//'social/'.

	  			$imagehere=$postData['image'] = $_FILES['newsimage']['name'];
                             //   print_r($postData); die();

			}

			if(isset($postData['newsimage']['delete'])) $data['image'] = '';

                if($postData['created_time'] != NULL )
                {
                    $datecustom = Mage::app()->getLocale()->date($postData['created_time'], Zend_Date::DATE_SHORT);
                    
                   // print_r($datecustom);die();
                   // $model->setStartDate($date->toString('YYYY-MM-dd HH:mm:ss'));
                }

                 
                $newsModel->setId($this->getRequest()->getParam('id'))
                    //->setTitle($postData['title'])
                   // ->setContent($postData['content'])
                    ->setimage($imagehere)
                   // ->setStatus($postData['status'])
                   // ->setRemarks($postData['remarks'])
                   // ->setcreated_time($datecustom->toString('YYYY-MM-dd HH:mm:ss'))
                    ->save();

To show in admin html interface
namespace(Imran)/yourmodule(news)/Block/Adminhtml/News/Grid.php

$this->addColumn('image', array(
            'header'    => Mage::helper('news')->__('Image'),
            'align'     =>'center',
            'width'     => '50px',
            'height'    => '100px',
            'filter'    => false,
            'sortable'  => false,
            'renderer'  => 'news/adminhtml_widget_grid_renderer',
	));

namespace(Imran)/yourmodule(news)/Block/Adminhtml/Widget/Grid/Renderer.php

<?php
/** http://www.magentix.fr **/

class Imran_News_Block_Adminhtml_Widget_Grid_Renderer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
	
	public function render(Varien_Object $row) {
		return ($this->_getImage($row));
	}
	
	protected function _getImage(Varien_Object $row) {
		$img = $row->image != '' ? '<img width="50" height="50" src="'.Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$row->image.'" alt="" />' : '';
		return $img;
	}
	
}

Create a new date field at any database and save the record

In u r Form u need to add this code to make a date field to put the date information in to it

$dateFormatIso = Mage::app()->getLocale() ->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
            $fieldset->addField('created_time', 'date', array(
                'label' => Mage::helper('news')->__('Create Date'),
                'title' => Mage::helper('news')->__('Create Date'),
                'name' => 'created_time',
                'image' => $this->getSkinUrl('images/grid-cal.gif'),
                'format' => $dateFormatIso,
                'value' => 'created_time',
                //'required' => true,
               ));

Use this below code to u r controller to save it into the database

$postData = $this->getRequest()->getPost();
                $newsModel = Mage::getModel('news/news');


                if($postData['created_time'] != NULL )
                {
                    $datecustom = Mage::app()->getLocale()->date($postData['created_time'], Zend_Date::DATE_SHORT);
                   // print_r($datecustom);die();
                   // $model->setStartDate($date->toString('YYYY-MM-dd HH:mm:ss'));
                }


                $newsModel->setId($this->getRequest()->getParam('id'))
                  //  ->setTitle($postData['title'])
                  //  ->setContent($postData['content'])
                  //  ->setStatus($postData['status'])
                  //  ->setRemarks($postData['remarks'])
                    ->setcreated_time($datecustom->toString('YYYY-MM-dd HH:mm:ss'))
                    ->save();

A Basic Brand new module ….

First u should use this type of structure of the directory of files

These file is under app/code/local/Imran……….

Imran
—–/News
———–/Block/News.php
——————/Adminhtml/News.php
—————————–/News/Grid.php & Edit.php
———————————–/Edit/Form.php & Tabs.php
—————————————/Tab/Form.php
———–/Helper/Data.php
———–/Model/News.php
—————–/Mysql4/News.php
————————/News/Collection.php
———–/controllers/IndexController.php
———–/controllers/Adminhtml/NewsController.php
———–/etc/config.xml
———–/sql
————–/news_setup/mysql4-install-0.1

app/etc/modules/Imran_News.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : Imran_News.xml.xml
    Created on : July 26, 2010, 10:14 AM
    Author     : Imran
    Description:
        Purpose of the document follows.
-->
<config>
    <modules>
        <Imran_News>
            <active>true</active>
            <codePool>local</codePool>
        </Imran_News>
    </modules>
</config>

app/code/local/Imran/News/Block/News.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php 
class Imran_News_Block_News extends Mage_Core_Block_Template
{
    public function __construct()
    {
        parent::__construct();
        $this->setTemplate('news/news.phtml');
    }
}

app/code/local/Imran/News/Block/Adminhtml/News.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_controller = 'adminhtml_news';
        $this->_blockGroup = 'news';
        $this->_headerText = Mage::helper('news')->__('Item Manager');
        $this->_addButtonLabel = Mage::helper('news')->__('Add Item');
        parent::__construct();
    }
}

app/code/local/Imran/News/Block/Adminhtml/News/Grid.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('newsGrid');
        // This is the primary key of the database
        $this->setDefaultSort('news_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('news/news')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('news_id', array(
            'header'    => Mage::helper('news')->__('ID'),
            'align'     =>'right',
            'width'     => '50px',
            'index'     => 'news_id',
        ));

        $this->addColumn('title', array(
            'header'    => Mage::helper('news')->__('Title'),
            'align'     =>'left',
            'index'     => 'title',
        ));

        /**/
        $this->addColumn('content', array(
            'header'    => Mage::helper('news')->__('Item Content'),
            'width'     => '150px',
            'index'     => 'content',
        ));
        

        $this->addColumn('created_time', array(
            'header'    => Mage::helper('news')->__('Creation Time'),
            'align'     => 'left',
            'width'     => '120px',
            'type'      => 'date',
            'default'   => '--',
            'index'     => 'created_time',
        ));

        $this->addColumn('update_time', array(
            'header'    => Mage::helper('news')->__('Update Time'),
            'align'     => 'left',
            'width'     => '120px',
            'type'      => 'date',
            'default'   => '--',
            'index'     => 'update_time',
        ));


        $this->addColumn('status', array(

            'header'    => Mage::helper('news')->__('Status'),
            'align'     => 'left',
            'width'     => '80px',
            'index'     => 'status',
            'type'      => 'options',
            'options'   => array(
                1 => 'Active',
                0 => 'Inactive',
            ),
        ));

//add a new field in database and it show in grid mode in magento admin panel ....
         $this->addColumn('remarks', array(
            'header'    => Mage::helper('news')->__('Remarks'),
            'align'     =>'left',
            'index'     => 'remarks',
        ));

        return parent::_prepareColumns();
    }

    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }


}

app/code/local/Imran/News/Block/Adminhtml/News/Edit.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
    public function __construct()
    {
        parent::__construct();

        $this->_objectId = 'id';
        $this->_blockGroup = 'news';
        $this->_controller = 'adminhtml_news';

        $this->_updateButton('save', 'label', Mage::helper('news')->__('Save Item'));
        $this->_updateButton('delete', 'label', Mage::helper('news')->__('Delete Item'));
    }

    public function getHeaderText()
    {
        if( Mage::registry('news_data') && Mage::registry('news_data')->getId() ) {
            return Mage::helper('news')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('news_data')->getTitle()));
        } else {
            return Mage::helper('news')->__('Add Item');
        }
    }
}

app/code/local/Imran/News/Block/Adminhtml/News/Edit/Tabs.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{

    public function __construct()
    {
        parent::__construct();
        $this->setId('news_tabs');
        $this->setDestElementId('edit_form');
        $this->setTitle(Mage::helper('news')->__('News Information'));
    }

    protected function _beforeToHtml()
    {
        $this->addTab('form_section', array(
            'label'     => Mage::helper('news')->__('Item Information'),
            'title'     => Mage::helper('news')->__('Item Information'),
            'content'   => $this->getLayout()->createBlock('news/adminhtml_news_edit_tab_form')->toHtml(),
        ));

        return parent::_beforeToHtml();
    }
}

app/code/local/Imran/News/Block/Adminhtml/News/Edit/Form.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form(array(
                                        'id' => 'edit_form',
                                        'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
                                        'method' => 'post',
                                     )
        );

        $form->setUseContainer(true);
        $this->setForm($form);
        return parent::_prepareForm();
    }
}

app/code/local/Imran/News/Block/Adminhtml/News/Edit/Tab/Form.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Block_Adminhtml_News_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
 
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);
        $fieldset = $form->addFieldset('news_form', array('legend'=>Mage::helper('news')->__('Item information')));

        $fieldset->addField('title', 'text', array(
            'label'     => Mage::helper('news')->__('Title'),
            'class'     => 'required-entry',
            'required'  => true,
            'name'      => 'title',
        ));

        $fieldset->addField('status', 'select', array(
            'label'     => Mage::helper('news')->__('Status'),
            'name'      => 'status',
            'values'    => array(
                array(
                    'value'     => 1,
                    'label'     => Mage::helper('news')->__('Active'),
                ),

                array(
                    'value'     => 0,
                    'label'     => Mage::helper('news')->__('Inactive'),
                ),
            ),
        ));

        $fieldset->addField('content', 'editor', array(
            'name'      => 'content',
            'label'     => Mage::helper('news')->__('Content'),
            'title'     => Mage::helper('news')->__('Content'),
            'style'     => 'width:98%; height:400px;',
            'wysiwyg'   => true,
            'required'  => true,
        ));
 // add created time in database
       /* $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
            $fieldset->addField('created_time', 'date', array(
            'name' => 'created_time',
            'label' => Mage::helper('news')->__('Created Time'),
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'format' => $outputFormat,
            'time' => true,
            'style' => 'width: 140px;'
        ));
*/
        $outputFormat = Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
        // if($queue->getQueueStatus() == Mage_Newsletter_Model_Queue::STATUS_NEVER) {
            $fieldset->addField('created_time', 'date',array(
              'name'      =>    'created_time',
              'time'      =>    true,
              'format'    =>    $outputFormat,
              'label'     =>    Mage::helper('news')->__('Created Time'),
              'image'     =>    $this->getSkinUrl('images/grid-cal.gif')
            ));
// add a new field in database to show in adding in database in put format in admin panel...
         $fieldset->addField('remarks', 'text', array(
            'label'     => Mage::helper('news')->__('Remarks'),
           // 'class'     => 'required-entry',
            'required'  => false,
            'name'      => 'remarks',
        ));
//print(Mage::getSingleton('adminhtml/session')->getNewsData());
        if ( Mage::getSingleton('adminhtml/session')->getNewsData() )
        {
            $form->setValues(Mage::getSingleton('adminhtml/session')->getNewsData());
          //  print_r($varab);
            Mage::getSingleton('adminhtml/session')->setNewsData(null);
        } elseif ( Mage::registry('news_data') ) {
            $form->setValues(Mage::registry('news_data')->getData());
        }
        return parent::_prepareForm();
    }
}

app/code/local/Imran/News/Helper/Data.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Helper_Data extends Mage_Core_Helper_Abstract
{

}

app/code/local/Imran/News/Model/News.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 	class Fend_Feed_Model_Feed extends Mage_Core_Model_Abstract
	{
		public function _construct() {
			parent::_construct();
			$this->_init('feed/feed');
		}
	} 
 */

?>
<?php

class Imran_News_Model_News extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        parent::_construct();
        $this->_init('news/news');
    }
}

app/code/local/Imran/News/Model/Mysql4/News.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Model_Mysql4_News extends Mage_Core_Model_Mysql4_Abstract
{
    public function _construct()
    {
        $this->_init('news/news', 'news_id');
    }
}

app/code/local/Imran/News/Model/Mysql4/News/Collection.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php

class Imran_News_Model_Mysql4_News_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function _construct()
    {
        //parent::__construct();
        $this->_init('news/news');
    }
}

app/code/local/Imran/News/controllers/IndexController.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * <?php

class Fend_Feed_IndexController extends Mage_Core_Controller_Front_Action
{
	public function indexAction() {
		$this->loadLayout();
		$this->renderLayout();
	}
}

?>
 *  */

?>
<?php
class Imran_News_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
            $this->loadLayout();
            $this->renderLayout();
    }
}

app/code/local/Imran/News/controllers/Adminhtml/NewsController.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * public function indexAction() {
  $this->_initAction()
    ->renderLayout();
}
 * to
 * public function indexAction() {
  $this->_initAction();
  $this->_addContent($this->getLayout()->createBlock('module/adminhtml_module_grid'));
  $this->renderLayout();
}
 *
 */

?>
<?php
 
class Imran_News_Adminhtml_NewsController extends Mage_Adminhtml_Controller_action
{

    protected function _initAction()
    {
        $this->loadLayout()
            ->_setActiveMenu('news/items')
            ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
        return $this;
    }

    public function indexAction() {
        $this->_initAction();
        //$this->_addContent($this->getLayout()->createBlock('news/adminhtml_news_grid'));
        $this->renderLayout();
    }

    public function editAction()
    {
        $newsId     = $this->getRequest()->getParam('id');
        $newsModel  = Mage::getModel('news/news')->load($newsId);

        if ($newsModel->getId() || $newsId == 0) {

            Mage::register('news_data', $newsModel);

            $this->loadLayout();
            $this->_setActiveMenu('news/items');

            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
            $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

            $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

            $this->_addContent($this->getLayout()->createBlock('news/adminhtml_news_edit'))
                 ->_addLeft($this->getLayout()->createBlock('news/adminhtml_news_edit_tabs'));

            $this->renderLayout();
        } else {
            Mage::getSingleton('adminhtml/session')->addError(Mage::helper('news')->__('Item does not exist'));
            $this->_redirect('*/*/');
        }
    }

    public function newAction()
    {
        $this->_forward('edit');
    }

    public function saveAction()
    {
        if ( $this->getRequest()->getPost() ) {
            try {
                $postData = $this->getRequest()->getPost();
                $newsModel = Mage::getModel('news/news');
                $newsModel->setId($this->getRequest()->getParam('id'))
                    ->setTitle($postData['title'])
                    ->setContent($postData['content'])
                    ->setStatus($postData['status'])
                    ->setRemarks($postData['remarks'])
                    ->setcreated_time($postData['created_time'])
                    ->save();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully saved'));
                Mage::getSingleton('adminhtml/session')->setNewsData(false);

                $this->_redirect('*/*/');
                return;
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                Mage::getSingleton('adminhtml/session')->setNewsData($this->getRequest()->getPost());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
                return;
            }
        }
        $this->_redirect('*/*/');
    }

    public function deleteAction()
    {
        if( $this->getRequest()->getParam('id') > 0 ) {
            try {
                $newsModel = Mage::getModel('news/news');

                $newsModel->setId($this->getRequest()->getParam('id'))
                    ->delete();

                Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
                $this->_redirect('*/*/');
            } catch (Exception $e) {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
                $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
            }
        }
        $this->_redirect('*/*/');
    }
}

app/code/local/Imran/News/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : config.xml
    Created on : July 26, 2010, 10:19 AM
    Author     : Imran
    Description:
        Purpose of the document follows.
-->

<config>
    <modules>
        <Imran_News>
            <version>0.1.0</version>
        </Imran_News>
    </modules>
    <frontend>
        <routers>
            <news>
                <use>standard</use>
                <args>
                    <module>Imran_News</module>
                    <frontName>news</frontName>
                </args>
            </news>
        </routers>
        <layout>
            <updates>
                <news>
                    <file>news.xml</file>
                </news>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <news>
                <use>admin</use>
                <args>
                    <module>Imran_News</module>
                    <frontName>news</frontName>
                </args>
            </news>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <news module="news">
                <title>News</title>
                <sort_order>71</sort_order>
                <children>
                    <items module="news">
                        <title>Manage Items</title>
                        <sort_order>0</sort_order>
                        <action>news/adminhtml_news</action>
                    </items>
                </children>
            </news>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <news>
                            <title>News Module</title>
                            <sort_order>200</sort_order>
                        </news>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <news>
                    <file>news.xml</file>
                </news>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <models>
            <news>
                <class>Imran_News_Model</class>
                <resourceModel>news_mysql4</resourceModel>
            </news>
            <news_mysql4>
                <class>Imran_News_Model_Mysql4</class>
                <entities>
                    <news>
                        <table>news</table>
                    </news>
                </entities>
            </news_mysql4>
        </models>
        <resources>
            <news_setup>
                <setup>
                    <module>Imran_News</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </news_setup>
            <news_write>
                <connection>
                    <use>core_write</use>
                </connection>


            </news_write>
            <news_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </news_read>
        </resources>
        <blocks>
            <news>
                <class>Imran_News_Block</class>
            </news>
        </blocks>
        <helpers>
            <news>
                <class>Imran_News_Helper</class>
            </news>
        </helpers>
    </global>
</config>

app/code/local/Imran/News/sql/news_setup/mysql4-install-0.1.php

<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

?>
<?php
 
$installer = $this;

$installer->startSetup();

$installer->run("

-- DROP TABLE IF EXISTS {$this->getTable('news')};
CREATE TABLE {$this->getTable('news')} (
  `news_id` int(11) unsigned NOT NULL auto_increment,
  `title` varchar(255) NOT NULL default '',
  `content` text NOT NULL default '',
  `status` smallint(6) NOT NULL default '0',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`news_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ");

$installer->endSetup();

The above code is used as a core in formation ……

app/design/your theme/template/news/news.phtml

<h4><?php echo $this->__('Module List') ?></h4>

<?php
        /*
        This will load one record from your database table.
        load(<module>_id) will load whatever ID number you give it.
        */
    /**/
    $news = Mage::getModel('news/news')->load(1);
    echo $news->getNewsId();
    echo $news->getTitle();
    echo $news->getContent();
    echo $news->getStatus();
    

        /*
        This block of code loads all of the records in the database table.
        It will iterate through the collection and the first thing it will do
        is set the Title to the current value of $i which is incremented each
        iteration and then echo that value back out.  At the very end it will
        save the entire collection.
        */
    /**/
    $i = 0;

    $collection = Mage::getModel('news/news')->getCollection();
   // print_r($collection);
    $collection->setPageSize(5);
    $collection->setCurPage(2);
    $size = $collection->getSize();
    $cnt = count($collection);
    foreach ($collection as $item) {
        $i = $i+1;
        $item->setTitle($i);
        echo $item->getTitle();echo '<br/>';
    }

    $collection->walk('save');
    

        /*
        This shows how to load one value, change something and save it.
        */

    /**/
    $object = Mage::getModel('news/news')->load(1);
    $object->setTitle('This is a changed title');
    $object->save();
    
?>

app/design/frontend/your theme/layout/news.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : news.xml
    Created on : July 26, 2010, 10:45 AM
    Author     : Imran
    Description:
        Purpose of the document follows.
-->

<layout version="0.1.0">
    <news_index_index>
        <reference name="content">
            <block type="core/template" name="news" template="news/news.phtml" />
        </reference>
    </news_index_index>
</layout>

app/design/adminhtml/your theme/layout/news.xml

<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : news.xml
    Created on : July 26, 2010, 12:17 PM
    Author     : Imran
    Description:
        Purpose of the document follows.
-->

<layout version="0.1.0">
    <news_adminhtml_news_index>
        <reference name="content">
            <block type="news/adminhtml_news" name="news" />
        </reference>
    </news_adminhtml_news_index>
</layout>

Here it is the most basic of a new module that handle any database. Here I use this code with the help of magento wiki help. And first add a table manually from u r phpmyadmin.

Image add in product description section

I found a new way to add images i product description
1. first upload all images in media directory if u want to use a folder u can also do this. suppose u make a folder in media folder as it is named is fxf
2. use this

<img src="../../media/fxf/your image name" alt=""  />

to defined that images.
3. u must follow the other images tool as u have to defined it’s weight height align or other what u want to use in html imh tag.

Use URL in footer.phtml

It is quit impossible to use the store or skin or other url in footer. so we can use this

<a href="<?php echo $this->getUrl('')?>catalog/seo_sitemap/category">Site Map</a>
<a href="<?php echo $this->getUrl('')?>catalogsearch/term/popular">Popular search</a>
<a href="<?php echo $this->getUrl('')?>catalogsearch/advanced">Advanced search</a>

for skin 
/*$this->getSkinUrl('give the name which url u want');
exam.*/
<img src="<?php echo $this->getSkinUrl('images/pictos/panier.gif') ?>" alt="Mon panier">
%d bloggers like this: