Posted by: james | August 31, 2009

New module for warr in mage

first of all go to app/etc/modules/Form_Warranty.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Form_Warranty>
<active>true</active>
<codePool>local</codePool>
</Form_Warranty>
</modules>
</config>

after doing that go to app/design/frontend/default/default/template/warranty/form.phtml

<?php
$token = uniqid();
?>
<h2 align=”center”>Contact Details</h2>
<form id=”warrenty” action=”add” method=”post” name=”warrenty”>
<input type=”hidden” name=”regcode” id=”regcode” value=”<?php echo $token; ?>”>
<table width=”100%”>
<tr>
<td>Title:</td>
<td height=”31″>
<select name=”title” id=”title”>
<option>Choose</option>
<option>Mr.</option>
<option>Mrs.</option>
<option>Miss.</option>
<option>Ms.</option>
</select>
</td>
</tr>
<tr></tr>
<tr>
<td height=”31″>First Name:</td>
<td height=”31″><input id=”fname” type=”text” name=”fname” /></td>
<td height=”31″>Last Name:</td>
<td height=”31″><input id=”lname” type=”text” name=”lname” /></td>
</tr>
<tr>
<td height=”31″>Street Address:</td>
<td height=”31″><input  id=”address” name=”address” type=”text”></input></td>
</tr>
<tr>
<td height=”31″>Suburb/Town:</td>
<td height=”31″ width=”200″><input id=”town” type=”text” name=”town” /></td>
<td height=”31″>Post Code:</td>
<td height=”31″><input id=”pcode” type=”text” name=”pcode” /></td>
</tr>
<tr>
<td>State:</td>
<td height=”31″>
<select name=”state” id=”state”>
<option>Choose</option>
<option>ACT</option>
<option>NSW</option>
<option>NT</option>
<option>QLD</option>
<option>SA</option>
<option>TAS</option>
<option>VIC</option>
<option>WA</option>
</select>
</td>
</tr>
<tr>
<td height=”31″>Email:</td>
<td height=”31″><input id=”mail” type=”text” name=”mail” /></td>
</tr>
<tr>
<td></td>
<td colspan=”2″>(Please double check your email address)</td>
</tr>
<tr>
<td>Daytime Ph No.:</td>
<td height=”31″><input id=”daytime” type=”text” name=”daytime” /></td></td>
</tr>

<tr>
<td></td>
<td colspan=”4″>Do you wish to receive new product info from Magento Comm. Pvt. Ltd </td>
</tr>
<tr>
<td></td>
<td><input type=”checkbox” name=”isyes” id=”isyes”>&nbsp;&nbsp;&nbsp;Yes</td>
</tr>

<tr>
<td></td>
<td>
<h2 align=”center”>Reel Purchase Details</h2>
</td>
</tr>
<!–<tr>
<td>Brand:</td>
<td height=”31″>
<select name=”brand” id=”brand”>
<option>First</option>
<option>Second</option>
</select></td>
</tr>
–>
<tr>
<td>Brand:</td>
<td height=”31″>
<select name=”brand” id=”brand”>
<?php foreach ($this->getAttText(‘computer_manufacturers’) as $brand): ?>
<option>
<?php echo $brand[‘label’] ?>
</option>
<?php endforeach; ?>
</select></td>
</tr>
<tr>
<td height=”31″>Series Name:</td>
<td><input type=”text” name=”series” id=”series” /></td>
</tr>
<tr>
<td height=”31″> Model Size:</td>
<td><input type=”text” name=”size” id=”size”></td>
</tr>

<tr>
<td>Purchase Date:</td>
<td>
<select name=”day” id=”day”>
<?php for($i=1;$i<32;$i++)
{
echo “<option>”;
echo $i;
echo “</option>”;
}
?>
</select>

<select name=”month” id=”month”>

<?php for($i=1;$i<13;$i++)
{
echo “<option>”;
echo $i;
echo “</option>”;
}
?>

</select>

<select name=”year” id=”year”>
<?php for($i=1995;$i<2010;$i++)
{
echo “<option>”;
echo $i;
echo “</option>”;
}
?>
</select>
</td>
</tr>
<tr>
<td>Retail Store Name:</td>
<td><input type=”text” id=”store” name=”store”></td>
</tr>
</form>
<tr>
<td><input type=”submit”  value=”SEND”> </td>
</tr>
</table>

app/design/frontend/default/default/template/warranty/thanks.phtml

<?php
$res = $this->getContactName();

?>

<div>
<p><strong><?php echo $this->__(‘Dear,’ .$res[‘fname’] ) ?></strong><br />
<p>
<?php echo $this->__(‘Thank you for your purchase and registering your product.’) ?>
</p>

<p>
<?php echo $this->__(‘This number is unique to each product and individual and will be required if you should need to exercise your

warranty.’) ?>
</p>

<p>
<?php echo $this->__(‘For your future convenience, please print this page, or write down the following Warranty Registration Code:’)

?>
</p>

<p>
<strong><?php echo $this->__($res[‘regcode’]) ?></strong>
</p>

<p>
<?php echo $this->__(‘If you require assistance at anytime, please contact our service centre at:’) ?>
</p>

<p>
<?php echo $this->__(‘new Service Centre’) ?>
</p>

</div>

now for admin panel display go to…

app/design/adminhtml/default/default/template/warranty/new.phtml
<?php

?>

<div>
<table cellspacing=”0″>
<tr>
<td><h3><?php echo $this->__(‘Warranty’) ?></h3></td>
</tr>
</table>
</div>
<?php
$new = $this->getFirstName();
foreach($new as $key=>$data)
{
/*foreach($val as $data)
{
return $val;*/
?>
<div>
<div>
<table cellspacing=”0″>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘FirstName’) ?></label></td>
<td><strong><?php echo $data[‘fname’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘LastName’) ?></label></td>
<td><strong><?php echo $data[‘lname’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘Address’) ?></label></td>
<td><strong><?php echo $data[‘address’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘Town’) ?></label></td>
<td><strong><?php echo $data[‘town’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘Pincode’) ?></label></td>
<td><strong><?php echo $data[‘pcode’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘State’) ?></label></td>
<td><strong><?php echo $data[‘state’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘E-mail Id.’) ?></label></td>
<td><strong><?php echo $data[‘mail’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘Contact No.’) ?></label></td>
<td><strong><?php echo $data[‘daytime’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘Brand’) ?></label></td>
<td><strong><?php echo $data[‘brand’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘SeriesName’) ?></label></td>
<td><strong><?php echo $data[‘series’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘ModelSize’) ?></label></td>
<td><strong><?php echo $data[‘size’] ?></strong></td>
</tr>
<tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘PurchaseDate’) ?></label></td>
<td><strong><?php echo $data[‘day’].’:’.$data[‘month’].’:’.$data[‘year’].”.”.'(DD:MM:YY)’ ?></strong></td>
</tr><tr>
<td><label><?php echo Mage::helper(‘warranty’)->__(‘StoreName’) ?></label></td>
<td><strong><?php echo $data[‘store’] ?></strong></td>
</tr>
</table>
</div>
</div>

<?php } ?>

Now after that go to app/code/local/Form/Warranty/etc/config.xml

<?xml version=”1.0″?>
<config>
<modules>
<Form_Warranty>
<version>0.1.0</version>
</Form_Warranty>
</modules>
<admin>
<routers>
<warranty>
<use>admin</use>
<args>
<module>Form_Warranty</module>
<frontName>warranty</frontName>
</args>
</warranty>
</routers>
</admin>
<global>
<models>
<warranty>
<class>Form_Warranty_Model</class>
<resourceModel>warranty_mysql4</resourceModel>
</warranty>
<warranty_mysql4>
<class>Form_Warranty_Model_Mysql4</class>
<entities>
<warranty>
<table>warrenty</table>
</warranty>
</entities>
</warranty_mysql4>
</models>

<resources>
<warranty_setup>
<setup>
<module>Form_Warranty</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</warranty_setup>
<warranty_write>
<connection>
<use>core_write</use>
</connection>
</warranty_write>
<warranty_read>
<connection>
<use>core_read</use>
</connection>
</warranty_read>
</resources>
<blocks>
<warranty>
<class>Form_Warranty_Block</class>
</warranty>
</blocks>

<helpers>
<warranty>
<class>Form_Warranty_Helper</class>
</warranty>
</helpers>
</global>

<adminhtml>
<menu>
<warranty translate=”title” module=”warranty”>
<title>Warranty</title>
<sort_order>200</sort_order>
<action>warranty/contact</action>
</warranty>
</menu>
</adminhtml>

<frontend>
<routers>
<warranty>
<use>standard</use>
<args>
<module>Form_Warranty</module>
<frontName>warranty</frontName>
</args>
</warranty>
</routers>

</frontend>

</config>

Now go to app/code/local/Form/Warranty/Block/Contact.php

<?php
class Form_Warranty_Block_Contact extends Mage_Adminhtml_Block_Widget_Grid_Container
{
protected $_blockGroup = ‘warranty’;
public function __construct()
{
$this->_controller = ‘contact’;
$this->_headerText = Mage::helper(‘warranty’)->__(‘Warranties’);
$this->_addButtonLabel = Mage::helper(‘warranty’)->__(‘Create New Warranty’);
parent::__construct();
if (!Mage::getSingleton(‘admin/session’)->isAllowed(‘warranty/contact/actions/create’)) {
$this->_removeButton(‘add’);
}
}
}

Now go to app/code/local/Form/Warranty/Block/Data.php

<?php

class Form_Warranty_Block_Data extends Mage_Adminhtml_Block_Template
{
public function __construct()
{
parent::__construct();
$this->setTemplate(‘warranty/new.phtml’);
}

public function getFirstName()
{
$id = $this->getRequest()->getParam(‘id’);
$form = Mage::getModel(‘warranty/warranty’);
$d = $form->fetchData($id);
return $d;
}
}

Now go to app/code/local/Form/Warranty/Block/Form.php

<?php

class Form_Warranty_Block_Form extends Mage_Core_Block_Template
{

public function __construct()
{
parent::__construct();
$this->setTemplate(‘warranty/form.phtml’);

Mage::app()->getFrontController()->getAction()->getLayout()->getBlock(‘root’)->setHeaderTitle(Mage::helper(‘warranty’)->__(‘Warranty’));
$this->_filterModelName = ‘catalog/layer_filter_attribute’;
}

public function getAttText($attributeCode)
{
$product = Mage::getModel(‘catalog/product’);

return $product->getResource()
->getAttribute($attributeCode)
->getSource()
->getAllOptions($this->getData($attributeCode));
}
}

Now go to app/code/local/Form/Warranty/Block/Thanks.php

<?php
class Form_Warranty_Block_Thanks extends Mage_Core_Block_Template
{
public function __construct()
{
parent::__construct();
$this->setTemplate(‘warranty/thanks.phtml’);
}

public function getContactName()
{
return Mage::getSingleton(‘warranty/session’)->getData(‘last_saved_warranty’,true);
}

}

Now go to app/code/local/Form/Warranty/Block/Contact/Grid.php

<?php
class Form_Warranty_Block_Contact_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

public function __construct()
{
parent::__construct();
$this->setId(‘contact_grid’);
$this->setUseAjax(true);
}

protected function _prepareCollection()
{
$collection = Mage::getResourceModel(‘warranty/warranty_collection’);
$collection->addExpressionFieldToSelect(‘contact_name’,’CONCAT(title, ” “, fname, ” “, lname)’);
$collection->addExpressionFieldToSelect(‘date’,’CONCAT(day, “/”, month, “/”, year)’);

return parent::_prepareCollection();
}

protected function _prepareColumns()
{

$this->addColumn(‘id’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘ID’),
‘align’         => ‘right’,
‘width’         => ’20px’,
‘index’         => ‘id’,
));

$this->addColumn(‘contact_name’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘Name’),
‘align’         => ‘left’,
‘width’         => ‘150px’,
‘index’         => ‘contact_name’,
‘type’          => ‘text’,
‘truncate’      => 50,
‘escape’        => true,
));

$this->addColumn(‘mail’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘Mail ID’),
‘align’         => ‘left’,
‘index’         => ‘mail’,
‘type’          => ‘text’,
‘escape’        => false,
));

$this->addColumn(‘daytime’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘Contact No.’),
‘align’         => ‘left’,
‘index’             => ‘daytime’,
‘type’              => ‘text’,
‘escape’        => true,
));
$this->addColumn(‘brand’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘BRAND’),
‘align’         => ‘left’,
‘index’             => ‘brand’,
‘type’              => ‘text’,
‘escape’        => true,
));
$this->addColumn(‘series’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘SERIES’),
‘align’         => ‘left’,
‘index’             => ‘series’,
‘type’              => ‘text’,
‘escape’        => true,
‘width’         => ’80px’,
));
$this->addColumn(‘date’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘DATE’),
‘align’         => ‘left’,
‘index’             => ‘date’,
‘type’              => ‘datetime’,
‘escape’        => true,
‘width’            =>’150px’,
));
$this->addColumn(‘regcode’, array(
‘header’        => Mage::helper(‘warranty’)->__(‘REGISTRATION CODE’),
‘align’         => ‘left’,
‘index’             => ‘regcode’,
‘type’              => ‘text’,
‘escape’        => true,
));
$this->addColumn(‘action’,
array(
‘header’    => Mage::helper(‘warranty’)->__(‘Action’),
‘width’     => ’50px’,
‘type’      => ‘action’,
‘getter’     => ‘getId’,
‘actions’   => array(
array(
‘caption’ => Mage::helper(‘warranty’)->__(‘View’),
‘url’     => array(‘base’=>’*/*/view’),
‘field’   => ‘id’
)
),
‘filter’    => false,
‘sortable’  => false,
));
return parent::_prepareColumns();
}

//    public function getRowUrl($row)
//    {
//        if (Mage::getSingleton(‘admin/session’)->isAllowed(‘supplier/supplier/actions/edit’)) {
//            return $this->getUrl(‘*/*/edit’, array(‘id’ => $row->getId()));
//        }
//        return false;
//    }
//
//    public function getGridUrl()
//    {
//        return $this->getUrl(‘*/*/grid’, array(‘_current’=>true));
//    }

}

Now go to app/code/local/Form/Warranty/controllers/ContactController.php

<?php

class Form_Warranty_ContactController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout()
->_addContent($this->getLayout()->createBlock(‘warranty/contact’))
->renderLayout();
}

protected function _initAction()
{
$this->loadLayout()
->_setActiveMenu(‘Warranty’);
//->_addBreadcrumb($this->__(‘Sales’), $this->__(‘Sales’))
//->_addBreadcrumb($this->__(‘Orders’), $this->__(‘Orders’));
return $this;
}

protected function _initContact()
{
$id = $this->getRequest()->getParam(‘id’);

$form = Mage::getModel(‘warranty/warranty’);
$data = $form->fetchData($id);
return $data;
}

public function gridAction()
{
$this->loadLayout();
$this->getResponse()->setBody(
$this->getLayout()->createBlock(‘warranty/contact_grid’)->toHtml()
);
}

public function viewAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock(‘warranty/data’));
$this->renderLayout();
}
/*$form = Mage::getModel(‘warranty/warranty’);
$data = $form->fetchData($id);
return $data;*/
/*$this->loadLayout();
$this->_setActiveMenu(‘warranty’);
$this->_addBreadcrumb(Mage::helper(‘adminhtml’)->__(‘Warranty’), Mage::helper(‘adminhtml’)->__(‘Warranty’));
$this->renderLayout();

$form = Mage::getModel(‘warranty/warranty’);
$form->fetchData();
*/
/*if ($contact = $this->_initContact()) {
$this->_initAction()
->renderLayout();
}*/

}

Now go to app/code/local/Form/Warranty/controllers/DataController.php

<?php

class Form_Warranty_DataController extends Mage_Adminhtml_Controller_Action
{

/*public function __construct()
{
parent::_construct;
$this->setTemplate(‘warrenty/new.phtml’);
}*/

public function newAction()
{
//$this->setTemplate(‘warrenty/new.phtml’);
$this->loadLayout();
$this->getLayout()->getBlock(‘content’)->append(
$this->getLayout()->createBlock(‘warranty/data’)
);
$this->_setActiveMenu(‘warranty’);
$this->_addBreadcrumb(Mage::helper(‘adminhtml’)->__(‘Warranty’), Mage::helper(‘adminhtml’)->__(‘Warranty’));
$this->renderLayout();

$form = Mage::getModel(‘warranty/warranty’);
$form->fetchData();

}
}

Now go to app/code/local/Form/Warranty/controllers/FormController.php

<?php

class Form_Warranty_FormController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();

$this->getLayout()->getBlock(‘content’)->append(
$this->getLayout()->createBlock(‘warranty/form’)
);
$this->getLayout()->getBlock(‘head’)->setTitle($this->__(‘Warranty’));

$this->renderLayout();
}

public function addAction()
{
$data = $this->getRequest()->getPost();

$form = Mage::getModel(‘warranty/warranty’)
->setData($this->getRequest()->getPost());

//$form->addDataNew($form);

$errors = $form->validate();

try
{
if(empty($errors))
{
}
else
{
Mage::getSingleton(‘core/session’)->setWarrentyFormData($this->getRequest()->getPost());
if (is_array($errors)) {
foreach ($errors as $errorMessage) {
Mage::getSingleton(‘core/session’)->addError($errorMessage);
$this->_redirect(‘warranty/form/’);
}
}
else {
$form->save();
Mage::getSingleton(‘core/session’)->addSuccess($this->__(‘Your Record has been inserted’));
$this->_redirect(‘warranty/thanks/’);
Mage::getSingleton(‘warranty/session’)->setData(‘last_saved_warranty’,$form);
}
}
}
catch (Mage_Core_Exception $e) {
Mage::getSingleton(‘core/session’)->addError($e->getMessage())
->setWarrentyFormData($this->getRequest()->getPost());
$this->_redirect(‘warranty/form/’);
}

catch (Exception $e) {
Mage::getSingleton(‘core/session’)->setWarrentyFormData($this->getRequest()->getPost())
->addException($e, $this->__(‘Can\’t save Data’));

$this->_redirect(‘warranty/form/’);
}
}
}

Now go to app/code/local/Form/Warranty/controllers/ThanksController.php

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

$this->getLayout()->getBlock(‘content’)->append(
$this->getLayout()->createBlock(‘warranty/thanks’)
);
$this->getLayout()->getBlock(‘head’)->setTitle($this->__(‘Warranty’));

$this->renderLayout();
}

}

Now go to app/code/local/Form/Warranty/Helper/Data.php

<?php

class Form_Warranty_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Now go to app/code/local/Form/Warranty/Model/Warranty.php

<?php

class Form_Warranty_Model_Warranty extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init(‘warranty/warranty’);
}

public function addDataNew($form)
{

//$data = Mage::getModel(‘warrenty/warrenty’);
//$d = $this->_getResource()->newData($data);

/*    $data = Mage::getModel(‘warrenty/warrenty_data’)
->setData($this->getRequest()->getPost());
print_r($data); exit;*/

$d = $this->_getResource()->newData($form);
}

public function validate()
{
$errors = array();
if($this->getTitle() == ‘Choose’)
{
//if(!Zend_Validate::is(trim($this->getTitle()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Select Title’);
}
if(!Zend_Validate::is( trim($this->getFname()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter First Name’);
}
else {
if(!Zend_Validate::is( trim($this->getFname()), ‘Alpha’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Only Alphabet in FirstName’);
}
}

if(!Zend_Validate::is( trim($this->getLname()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Last Name’);
}
else {
if(!Zend_Validate::is( trim($this->getLname()), ‘Alpha’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Only Alphabet in lastName’);
}
}

if(!Zend_Validate::is( trim($this->getAddress()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Address’);
}

if(!Zend_Validate::is(trim($this->getTown()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Your Town Name’);
}

if(!Zend_Validate::is(trim($this->getPcode()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Pincode’);
}

if($this->getState() == ‘Choose’)
{
$errors[] = Mage::helper(‘warranty’)->__(‘Please Select State’);
}

if(!Zend_Validate::is(trim($this->getMail()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Email Address’);
}
else
{
if(!Zend_Validate::is(trim($this->getMail()), ‘EmailAddress’)) {
$errors[] = Mage::helper(‘warratny’)->__(‘Please Enter Valid Email-id’);
}
}

if(!Zend_Validate::is(trim($this->getDaytime()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Your Daytime No.’);
}

/*if(!Zend_Validate::is(trim($this->getIsyes()), ‘NotEmpty’)) {
$errors = Mage::helper(‘warrenty’)->__(‘Please Enter ‘)
}*/

if($this->getBrand() == ‘Choose’)
{
$errors[] = Mage::helper(‘warranty’)->__(‘Please Select Brand’);
}

if(!Zend_Validate::is(trim($this->getSeries()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Series Number’);
}

if(!Zend_Validate::is(trim($this->getSize()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Size’);
}

/*if(!Zend_Validate::is(trim($this->getDay()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warrenty’)->__(‘Please Select Day’);
}*/

if(!Zend_Validate::is(trim($this->getStore()), ‘NotEmpty’)) {
$errors[] = Mage::helper(‘warranty’)->__(‘Please Enter Store name’);
}
if(empty($errors))
{
return true;
}
return $errors;
}

public function fetchData($id)
{
return $this->_getResource()->getFname($id);
}
}

Now go to app/code/local/Form/Warranty/Model/Session.php

<?php
class Form_Warranty_Model_Session extends Mage_Core_Model_Session_Abstract
{
public function __construct()
{
$this->init(‘warranty’);
}

}

Now go to app/code/local/Form/Warranty/Model/Mysql4/Warranty.php

<?php
class Form_Warranty_Model_Mysql4_Warranty extends Mage_Core_Model_Mysql4_Abstract
{
protected function _construct()
{
//2 post
$this->_init(‘warranty/warranty’, ‘id’);
}

public function newData($form)
{
//$this->_getWriteAdapter()->insert($this->getTable(‘warrenty’), $data);
$form->save();
echo “Your record has been inserted”;
}

public function callData()
{
$select = $this->_getReadAdapter()->select()
->from($this->getTable(‘warranty’));

$data = $this->_getReadAdapter()->fetchAll($select);
return $data;
}

public function getFname($id)
{
$read = $this->_getReadAdapter();
$select = $read->select()
->from($this->getTable(‘warranty’))
->where(‘id =’ .$id);
//$select = $this->_getReadAdapter()->select()
//    ->from($this->getTable(‘warranty’));
$all = $this->_getReadAdapter()->fetchAll($select);
return $all;
}
}

Now go to app/code/local/Form/Warranty/Model/Mysql4/Warranty/Collection.php

<?php
class Form_Warranty_Model_Mysql4_Warranty_Collection  extends  Mage_Core_Model_Mysql4_Collection_Abstract
{
protected function _construct()
{
$this->_init(‘warranty/warranty’);
}

public function addExpressionFieldToSelect($alias,$fullExpression)
{
$this->getSelect()->from(null, array($alias=>$fullExpression));

$this->_joinFields[$alias] = array(
‘table’ => true,
‘field’ => $fullExpression
);
return $this;

}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: