Posted by: james | September 12, 2009

new one..

local/form/company/block/name.php
<?php
class Form_Company_Block_Name extends Mage_Adminhtml_Block_Widget_Grid
{

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

protected function _prepareCollection()
{
$collection = Mage::getResourceModel(‘customer/customer_collection’)
->addNameToSelect()
->addAttributeToSelect(’email’)
->addAttributeToSelect(‘customer_code’)
->addAttributeToSelect(‘created_at’)
->addAttributeToSelect(‘group_id’)
->joinAttribute(‘billing_postcode’, ‘customer_address/postcode’, ‘default_billing’, null, ‘left’)
->joinAttribute(‘billing_city’, ‘customer_address/city’, ‘default_billing’, null, ‘left’)
->joinAttribute(‘billing_telephone’, ‘customer_address/telephone’, ‘default_billing’, null, ‘left’)
->joinAttribute(‘company’, ‘customer_address/company’,’default_billing’,null,’left’)
->joinAttribute(‘billing_region’, ‘customer_address/region’, ‘default_billing’, null, ‘left’)
->joinAttribute(‘billing_country_id’, ‘customer_address/country_id’, ‘default_billing’, null, ‘left’);

$this->setCollection($collection);

return parent::_prepareCollection();
}

protected function _prepareColumns()
{
$this->addColumn(‘entity_id’, array(
‘header’    => Mage::helper(‘customer’)->__(‘ID’),
‘width’     => ’50px’,
‘index’     => ‘entity_id’,
‘type’  => ‘number’,
));
/*$this->addColumn(‘firstname’, array(
‘header’    => Mage::helper(‘customer’)->__(‘First Name’),
‘index’     => ‘firstname’
));
$this->addColumn(‘lastname’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Last Name’),
‘index’     => ‘lastname’
));*/
$this->addColumn(‘name’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Name’),
‘index’     => ‘name’
));
$this->addColumn(’email’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Email’),
‘width’     => ‘150’,
‘index’     => ’email’
));

$this->addColumn(‘Company’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Company Name’),
‘width’     => ‘150’,
‘index’     => ‘company’
));

$this->addColumn(‘customer_code’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Customer Code’),
‘width’     => ‘150’,
‘index’     => ‘customer_code’
));

$groups = Mage::getResourceModel(‘customer/group_collection’)
->addFieldToFilter(‘customer_group_id’, array(‘gt’=> 0))
->load()
->toOptionHash();

$this->addColumn(‘group’, array(
‘header’    =>  Mage::helper(‘customer’)->__(‘Group’),
‘width’     =>  ‘100’,
‘index’     =>  ‘group_id’,
‘type’      =>  ‘options’,
‘options’   =>  $groups,
));

$this->addColumn(‘Telephone’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Telephone’),
‘width’     => ‘100’,
‘index’     => ‘billing_telephone’
));

$this->addColumn(‘billing_postcode’, array(
‘header’    => Mage::helper(‘customer’)->__(‘ZIP’),
‘width’     => ’90’,
‘index’     => ‘billing_postcode’,
));

$this->addColumn(‘billing_country_id’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Country’),
‘width’     => ‘100’,
‘type’      => ‘country’,
‘index’     => ‘billing_country_id’,
));

$this->addColumn(‘billing_region’, array(
‘header’    => Mage::helper(‘customer’)->__(‘State/Province’),
‘width’     => ‘100’,
‘index’     => ‘billing_region’,
));

$this->addColumn(‘customer_since’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Customer Since’),
‘type’      => ‘datetime’,
‘align’     => ‘center’,
‘index’     => ‘created_at’,
‘gmtoffset’ => true
));

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn(‘website_id’, array(
‘header’    => Mage::helper(‘customer’)->__(‘Website’),
‘align’     => ‘center’,
‘width’     => ’80px’,
‘type’      => ‘options’,
‘options’   => Mage::getSingleton(‘adminhtml/system_store’)->getWebsiteOptionHash(true),
‘index’     => ‘website_id’,
));
}

$this->addColumn(‘action’,
array(
‘header’    =>  Mage::helper(‘customer’)->__(‘Action’),
‘width’     => ‘100’,
‘type’      => ‘action’,
‘getter’    => ‘getId’,
‘actions’   => array(
array(
‘caption’   => Mage::helper(‘customer’)->__(‘Edit’),
‘url’       => array(‘base’=> ‘*/*/edit’),
‘field’     => ‘id’
)
),
‘filter’    => false,
‘sortable’  => false,
‘index’     => ‘stores’,
‘is_system’ => true,
));

$this->addExportType(‘*/*/exportCsv’, Mage::helper(‘customer’)->__(‘CSV’));
$this->addExportType(‘*/*/exportXml’, Mage::helper(‘customer’)->__(‘XML’));
return parent::_prepareColumns();
}

protected function _prepareMassaction()
{
$this->setMassactionIdField(‘entity_id’);
$this->getMassactionBlock()->setFormFieldName(‘customer’);

$this->getMassactionBlock()->addItem(‘delete’, array(
‘label’    => Mage::helper(‘customer’)->__(‘Delete’),
‘url’      => $this->getUrl(‘*/*/massDelete’),
‘confirm’  => Mage::helper(‘customer’)->__(‘Are you sure?’)
));

$this->getMassactionBlock()->addItem(‘newsletter_subscribe’, array(
‘label’    => Mage::helper(‘customer’)->__(‘Subscribe to newsletter’),
‘url’      => $this->getUrl(‘*/*/massSubscribe’)
));

$this->getMassactionBlock()->addItem(‘newsletter_unsubscribe’, array(
‘label’    => Mage::helper(‘customer’)->__(‘Unsubscribe from newsletter’),
‘url’      => $this->getUrl(‘*/*/massUnsubscribe’)
));

$groups = $this->helper(‘customer’)->getGroups()->toOptionArray();

array_unshift($groups, array(‘label’=> ”, ‘value’=> ”));
$this->getMassactionBlock()->addItem(‘assign_group’, array(
‘label’        => Mage::helper(‘customer’)->__(‘Assign a customer group’),
‘url’          => $this->getUrl(‘*/*/massAssignGroup’),
‘additional’   => array(
‘visibility’    => array(
‘name’     => ‘group’,
‘type’     => ‘select’,
‘class’    => ‘required-entry’,
‘label’    => Mage::helper(‘customer’)->__(‘Group’),
‘values’   => $groups
)
)
));

return $this;
}

public function getGridUrl()
{
return $this->getUrl(‘*/*/grid’, array(‘_current’=> true));
}

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

local/formcompany/etc/config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Form_Company>
<version>0.1.0</version>
</Form_Company>
</modules>
<admin>
<routers>
<company>
<use>admin</use>
<args>
<module>Form_Company</module>
<frontName>company</frontName>
</args>
</company>
</routers>
</admin>
<global>
<blocks>
<adminhtml>
<rewrite>
<customer_grid>Form_Company_Block_Name</customer_grid>
</rewrite>
</adminhtml>
<company>
<class>Form_Company_Block</class>
</company>
</blocks>
<models>
<company>
<class>Form_Company_Model</class>
<resourceModel>company_mysql4</resourceModel>
</company>
</models>

<resources>
<company_setup>
<setup>
<module>Form_Company</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</company_setup>
<company_write>
<connection>
<use>core_write</use>
</connection>
</company_write>
<company_read>
<connection>
<use>core_read</use>
</connection>
</company_read>
</resources>
<blocks>
<company>
<class>Form_company_Block</class>
</company>
</blocks>

<helpers>
<company>
<class>Form_Company_Helper</class>
</company>
</helpers>
</global>

<frontend>
<routers>
<company>
<use>standard</use>
<args>
<module>Form_Company</module>
<frontName>company</frontName>
</args>
</company>
</routers>
</frontend>
</config>

local/form/Customercode/block/Name.php
<?php
class Form_Customercode_Block_Name extends Mage_Adminhtml_Block_Widget_Form
{
public function __construct()
{
parent::__construct();
}

public function initForm()
{
$form = new Varien_Data_Form();
$form->setHtmlIdPrefix(‘_account’);
$form->setFieldNameSuffix(‘account’);

$customer = Mage::registry(‘current_customer’);

$fieldset = $form->addFieldset(‘base_fieldset’,
array(‘legend’=>Mage::helper(‘customer’)->__(‘Account Information’))
);

$this->_setFieldset($customer->getAttributes(), $fieldset);

if ($customer->getId()) {
$form->getElement(‘website_id’)->setDisabled(‘disabled’);
$form->getElement(‘created_in’)->setDisabled(‘disabled’);
} else {
$fieldset->removeField(‘created_in’);
}

$form->getElement(’email’)->addClass(‘validate-email’);
//$form->getElement(‘customer_code’)->addClass(‘validate-email’);

/*$new_field = $fieldset->addField(‘customer_code’,’text’,
array(
‘title’ => Mage::helper(‘customer’)->__(‘Enter Customer Code’),
‘label’ => Mage::helper(‘customer’)->__(‘Enter Customer Code’),
‘legend’ => Mage::helper(‘customer’)->__(‘Enter Customer Code’),
‘name’ => ‘customer_code’,
)
);*/

if ($customer->getId()) {
if (!$customer->isReadonly()) {
// add password management fieldset
$newFieldset = $form->addFieldset(
‘password_fieldset’,
array(‘legend’=>Mage::helper(‘customer’)->__(‘Password Management’))
);
// New customer password
$field = $newFieldset->addField(‘new_password’, ‘text’,
array(
‘label’ => Mage::helper(‘customer’)->__(‘New Password’),
‘name’  => ‘new_password’,
‘class’ => ‘validate-new-password’
)
);
$field->setRenderer($this->getLayout()->createBlock(‘adminhtml/customer_edit_renderer_newpass’));

// prepare customer confirmation control (only for existing customers)
$confirmationKey = $customer->getConfirmation();
if ($confirmationKey || $customer->isConfirmationRequired()) {
$confirmationAttribute = $customer->getAttribute(‘confirmation’);
if (!$confirmationKey) {
$confirmationKey = $customer->getRandomConfirmationKey();
}
$element = $fieldset->addField(‘confirmation’, ‘select’, array(
‘name’  => ‘confirmation’,
‘label’ => Mage::helper(‘customer’)->__($confirmationAttribute->getFrontendLabel()),
))->setEntityAttribute($confirmationAttribute)
->setValues(array(” => ‘Confirmed’, $confirmationKey => ‘Not confirmed’));

// prepare send welcome email checkbox, if customer is not confirmed
// no need to add it, if website id is empty
if ($customer->getConfirmation() && $customer->getWebsiteId()) {
$fieldset->addField(‘sendemail’, ‘checkbox’, array(
‘name’  => ‘sendemail’,
‘label’ => Mage::helper(‘customer’)->__(‘Send Welcome Email after Confirmation’)
));
}
}
}
}
else {
$newFieldset = $form->addFieldset(
‘password_fieldset’,
array(‘legend’=>Mage::helper(‘customer’)->__(‘Password Management’))
);
$field = $newFieldset->addField(‘password’, ‘text’,
array(
‘label’ => Mage::helper(‘customer’)->__(‘Password’),
‘class’ => ‘input-text required-entry validate-password’,
‘name’  => ‘password’,
‘required’ => true
)
);
$field->setRenderer($this->getLayout()->createBlock(‘adminhtml/customer_edit_renderer_newpass’));

// prepare send welcome email checkbox
$fieldset->addField(‘sendemail’, ‘checkbox’, array(
‘label’ => Mage::helper(‘customer’)->__(‘Send welcome email’),
‘name’  => ‘sendemail’,
‘id’    => ‘sendemail’,
));
}

// make sendemail disabled, if website_id has empty value
if ($sendemail = $form->getElement(‘sendemail’)) {
$prefix = $form->getHtmlIdPrefix();
$sendemail->setAfterElementHtml(
‘<script type=”text/javascript”>’
. ”
$(‘{$prefix}website_id’).disableSendemail = function() {
$(‘{$prefix}sendemail’).disabled = (” == this.value || ‘0’ == this.value);
}.bind($(‘{$prefix}website_id’));
Event.observe(‘{$prefix}website_id’, ‘click’, $(‘{$prefix}website_id’).disableSendemail);
$(‘{$prefix}website_id’).disableSendemail();

. ‘</script>’
);
}

if ($customer->isReadonly()) {
foreach ($customer->getAttributes() as $attribute) {
$element = $form->getElement($attribute->getAttributeCode());
if ($element) {
$element->setReadonly(true, true);
}
}
}

$form->setValues($customer->getData());
$this->setForm($form);
return $this;
}

}
local/form/Customercode/etc/config.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<Form_Customercode>
<version>0.1.0</version>
</Form_Customercode>
</modules>
<admin>
<routers>
<customercode>
<use>admin</use>
<args>
<module>Form_Customercode</module>
<frontName>customercode</frontName>
</args>
</customercode>
</routers>
</admin>
<global>
<blocks>
<adminhtml>
<rewrite>
<customer_edit_tab_account>Form_Customercode_Block_Name</customer_edit_tab_account>>
</rewrite>
</adminhtml>
<customercode>
<class>Form_Customercode_Block</class>
</customercode>
</blocks>
<models>
<customer>
<rewrite>
<entity_customer>Form_Customercode_Model_Mysql4_Code</entity_customer>
</rewrite>
</customer>
<customercode>
<class>Form_Customercode_Model</class>
<resourceModel>customercode_entity</resourceModel>
</customercode>
<customercode_entity>
<class>Form_Customercode_Model_Entity</class>
</customercode_entity>
</models>

<resources>
<customercode_setup>
<setup>
<module>Form_Customercode</module>
<class>Mage_Customer_Model_Entity_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customercode_setup>
<customercode_write>
<connection>
<use>core_write</use>
</connection>
</customercode_write>
<customercode_read>
<connection>
<use>core_read</use>
</connection>
</customercode_read>
</resources>
<blocks>
<customercode>
<class>Form_Customercode_Block</class>
</customercode>
</blocks>

<helpers>
<customercode>
<class>Form_Customercode_Helper</class>
</customercode>
</helpers>

<events>
<controller_action_postdispatch_adminhtml_customer_validate>
<observers>
<customercode>
<type>singleton</type>
<class>customercode/observer</class>
<method>processAfterSaveEvent</method>
</customercode>
</observers>
</controller_action_postdispatch_adminhtml_customer_validate>
</events>
</global>

<frontend>
<routers>
<customercode>
<use>standard</use>
<args>
<module>Form_Customercode</module>
<frontName>customercode</frontName>
</args>
</customercode>
</routers>
</frontend>
</config>
local/form/customercode/model/observer.php
<?php
class Form_Customercode_Model_Observer extends Mage_Core_Model_Abstract
{
public function processAfterSaveEvent(Varien_Event_Observer $observer)
{
$controller = $observer->getEvent()->getControllerAction();
$response = new Varien_Object(Zend_Json::decode($controller->getResponse()->getBody()));

$data = $controller->getRequest()->getPost(‘account’);
if(!$data[‘customer_code’])
{
$response->setError(1);
Mage::getSingleton(‘adminhtml/session’)->addError(Mage::helper(‘adminhtml’)->__(“Please Fill Customer Code Field”));
$controller->_initLayoutMessages(‘adminhtml/session’);
$response->setMessage($this->getLayout()->getMessagesBlock->getGroupedHtml());
}
else
{
$checkCustomer = Mage::getModel(‘customercode/customercode’);
//->setWebsiteId($websiteId);

$i = $checkCustomer->loadByCustomercode($data[‘customer_code’]);
if($i[‘entity_id’]){
//if( $checkCustomer->getId() && ($checkCustomer->getId() != $customer->getId()) ) {
$response->setError(1);
Mage::getSingleton(‘adminhtml/session’)->addError(Mage::helper(‘adminhtml’)->__(‘Customer with the same Customer code already

exists.’));
//$this->_initLayoutMessages(‘adminhtml/session’);
//$response->setMessage($this->getLayout()->getMessagesBlock()->getGroupedHtml());
}
}
$controller->getResponse()->setBody($response->toJson());
}

}

local/form/customercode/model/customercode.php
<?php
// Mage_Core_Model_Abstract
class Form_Customercode_Model_Customercode extends Mage_Customer_Model_Customer
{
public function _construct()
{
$this->_init(‘customercode/customercode’);
}
public function loadByCustomercode($customerCode)
{
$this->_getResource()->loadByCustomercode($this,$customerCode);
return $this;
}
}

local/form/customercode/model/Entity/customercode.php

<?php
//Mage_Core_Model_Mysql4_Abstract
class Form_Customercode_Model_Entity_Customercode extends Mage_Eav_Model_Entity_Abstract
{
public function __construct()
{
$resource = Mage::getSingleton(‘core/resource’);
$this->setType(‘customer’);
$this->setConnection(
$resource->getConnection(‘customer_read’),
$resource->getConnection(‘customer_write’)
);
}
public function loadByCustomercode(Mage_Customer_Model_Customer $customer,$customerCode)
{
$select = $this->_getReadAdapter()->select()
->from($this->getEntityTable(), array($this->getEntityIdField()))
->where(‘customer_code=:’.$customerCode);

$select = $this->_getReadAdapter()->select()
->from($this->getTable(‘customer_entity_varchar’),’entity_id’)
->where(‘value=’.$customerCode);

//SELECT entity_id FROM customer_entity_varchar where attribute_id = 524;

if ($id = $this->_getReadAdapter()->fetchOne($select, array(‘customer_code’ => $customerCode))) {
$this->load($customer, $id);
}
else {
$customer->setData(array());
}
return $this;
}

/*public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false)
{
$select = $this->_getReadAdapter()->select()
->from($this->getEntityTable(), array($this->getEntityIdField()))
//->where(’email=?’, $email);
->where(’email=:customer_email’);
if ($customer->getSharingConfig()->isWebsiteScope()) {
if (!$customer->hasData(‘website_id’)) {
Mage::throwException(Mage::helper(‘customer’)->__(‘Customer website id must be specified, when using website scope.’));
}
$select->where(‘website_id=?’, (int)$customer->getWebsiteId());
}

if ($id = $this->_getReadAdapter()->fetchOne($select, array(‘customer_email’ => $email))) {
$this->load($customer, $id);
}
else {
$customer->setData(array());
}
return $this;
}*/
}

locla/form/Customercode/sql/customercode_setup/mysql4-install-0.1.0.php

<?php

$installer = $this;

/* @var $installer Mage_Customer_Model_Entity_Setup */
$installer->startSetup();

$installer->addAttribute(‘customer’, ‘customer_code’, array(
‘label’        => ‘Customer Code’,
‘visible’      => 1,
‘position’     => 1,
‘required’     => true,
‘searchable’   => true,
‘unique’       => 1,
));

$installer->endSetup();

important notes::

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

public function getCreateUrl()
{
return $this->getUrl(‘*/create/start’);
}
}

local/practice/provider/block/create.php
<?php
class Practice_Provider_Block_Create extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$providerObject = new Varien_Object();
$providerModel  = Mage::getSingleton(‘provider/provider’);
$providerObject->setData($providerModel->getData());
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset(‘new_provider’, array(‘legend’ => Mage::helper(‘provider’)->__(‘Provider Details’)));
$fieldset->addField(‘name’, ‘text’, array(
‘name’      => ‘name’,
‘title’     => Mage::helper(‘provider’)->__(‘Name’),
‘label’     => Mage::helper(‘provider’)->__(‘Name’),
‘maxlength’ => ’50’,
‘required’  => true,
));
$fieldset->addField(‘contact_detail’, ‘text’, array(
‘name’      => ‘contact_detail’,
‘title’     => Mage::helper(‘provider’)->__(‘Contact Detail’),
‘label’     => Mage::helper(‘provider’)->__(‘Contact Detail’),
‘maxlength’ => ‘255’,
‘required’  => true,
));
$fieldset->addField(‘ordering_method’, ‘text’, array(
‘name’      => ‘ordering_method’,
‘title’     => Mage::helper(‘provider’)->__(‘Ordering Method’),
‘label’     => Mage::helper(‘provider’)->__(‘Ordering Method’),
‘maxlength’ => ‘255’,
‘required’  => true,
));
$fieldset->addField(‘submit’, ‘submit’, array(
‘name’      => ‘submit’,
‘title’     => Mage::helper(‘provider’)->__(‘Submit’),
‘maxlength’ => ‘255’,
‘required’  => true,
‘value’     => ‘Submit’
));
$form->setMethod(‘post’);
$form->setUseContainer(true);
$form->setId(‘edit_form’);
$form->setEnctype(‘multipart/form-data’);
$form->setAction($this->getUrl(‘*/*/post’));
$this->setForm($form);
}
}
local/practice/provider/block/edit.php
<?php
class Practice_Provider_Block_Edit extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$providerObject = new Varien_Object();
$providerModel  = Mage::getSingleton(‘provider/provider’);
$providerObject->setData(providerModel->getData());
$form = new Varien_Data_Form(array(
‘id’        => ‘edit_form’,
‘action’    => $this->getUrl(‘*/*/save’, array(‘id’ => $this->getRequest()->getParam(‘id’))),
‘method’    => ‘post’,
‘enctype’   => ‘multipart/form-data’
));
$fieldset = $form->addFieldset(‘edit_provider’, array(‘legend’ => Mage::helper(‘provider’)->__(‘Provider Details’)));
$fieldset->addField(‘name’, ‘text’, array(
‘name’      => ‘name’,
‘title’     => Mage::helper(‘provider’)->__(‘Name’),
‘label’     => Mage::helper(‘provider’)->__(‘Name’),
‘maxlength’ => ’50’,
‘required’  => true,
));
$fieldset->addField(‘contact_detail’, ‘text’, array(
‘name’      => ‘contact_detail’,
‘title’     => Mage::helper(‘provider’)->__(‘Contact Detail’),
‘label’     => Mage::helper(‘provider’)->__(‘Contact Detail’),
‘maxlength’ => ‘255’,
‘required’  => true,
));
$fieldset->addField(‘ordering_method’, ‘text’, array(
‘name’      => ‘ordering_method’,
‘title’     => Mage::helper(‘provider’)->__(‘Ordering Method’),
‘label’     => Mage::helper(‘provider’)->__(‘Ordering Method’),
‘maxlength’ => ‘255’,
‘required’  => true,
));
$form->setUseContainer(true);
$form->setValues(Mage::registry(‘frozen_provider’)->getData());
$this->setForm($form);
return parent::_prepareForm();
}

}
local/p/p/block/grid.php
<?php
class Practice_Provider_Block_Contact_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

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

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

//$collection->addExpressionAttributeToSelect(‘name’,
//            ‘CONCAT({{title}}, ” “, {{fname}}, ” “, {{lname}})’,
//            array(‘title’, ‘fname’, ‘lname’));
$this->setCollection($collection);
return parent::_prepareCollection();
}

protected function _prepareColumns()
{

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

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

$this->addColumn(‘contact_detail’, array(
‘header’        => Mage::helper(‘provider’)->__(‘Contact Detail’),
‘align’         => ‘left’,
‘index’         => ‘contact_detail’,
‘type’          => ‘text’,
‘escape’        => false,
));

$this->addColumn(‘ordering_method’, array(
‘header’        => Mage::helper(‘provider’)->__(‘Ordering Method’),
‘align’         => ‘left’,
‘index’             => ‘daytime’,
‘type’              => ‘text’,
‘escape’        => true,
‘index’         => ‘ordering_method’,
));

$this->addColumn(‘action’,
array(
‘header’    => Mage::helper(‘provider’)->__(‘Action’),
‘width’     => ’50px’,
‘type’      => ‘action’,
‘getter’     => ‘getId’,
‘actions’   => array(
array(
‘caption’ => Mage::helper(‘provider’)->__(‘Edit’),
‘url’     => array(‘base’=>’*/*/view’),
‘field’   => ‘id’
)
),
‘filter’    => false,
‘sortable’  => false,
));
return parent::_prepareColumns();
}

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

}

local/p/p/controllers/Contactcontroller.php
<?php
class Practice_Provider_ContactController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout()
->_addContent($this->getLayout()->createBlock(‘provider/contact’))
->renderLayout();
}

public function viewAction()
{
$this->loadLayout()
->_addContent($this->getLayout()->createBlock(‘provider/edit’))
->renderLayout();
}

public function saveAction()
{

}
}

local/p/p/controllers/Createcontroller.php
<?php
class Practice_Provider_CreateController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{

}
public function startAction()
{
$this->loadLayout()
->_addContent($this->getLayout()->createBlock(‘provider/create’))
->renderLayout();
}

public function postAction()
{
$form = Mage::getModel(‘provider/provider’)
->setData($this->getRequest()->getPost());

//if you want to set any field to array element then use array..

$form->save();
$this->_redirect(‘/contact/index/’);
}
}
etc/config.xml
<?xml version=”1.0″?>
<config>
<modules>
<Practice_Provider>
<version>0.1.0</version>
</Practice_Provider>
</modules>
<admin>
<routers>
<provider>
<use>admin</use>
<args>
<module>Practice_Provider</module>
<frontName>provider</frontName>
</args>
</provider>
</routers>
</admin>
<global>
<models>
<provider>
<class>Practice_Provider_Model</class>
<resourceModel>provider_mysql4</resourceModel>
</provider>
<provider_mysql4>
<class>Practice_Provider_Model_Mysql4</class>
<entities>
<provider>
<table>provider</table>
</provider>
</entities>
</provider_mysql4>
</models>

<resources>
<provider_setup>
<setup>
<module>Practice_Provider</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</provider_setup>
<provider_write>
<connection>
<use>core_write</use>
</connection>
</provider_write>
<provider_read>
<connection>
<use>core_read</use>
</connection>
</provider_read>
</resources>
<blocks>
<provider>
<class>Practice_Provider_Block</class>
</provider>
</blocks>

<helpers>
<provider>
<class>Practice_Provider_Helper</class>
</provider>
</helpers>
</global>

<adminhtml>
<menu>
<provider translate=”title” module=”provider”>
<title>Provider</title>
<sort_order>200</sort_order>
<action>provider/contact</action>
</provider>
</menu>
</adminhtml>

<frontend>
<routers>
<warranty>
<use>standard</use>
<args>
<module>Practice_Provider</module>
<frontName>provider</frontName>
</args>
</warranty>
</routers>

</frontend>

</config>

local/p/pmodel/provider.php
<?php
class Practice_Provider_Model_Provider extends Mage_Core_Model_Abstract
{
protected function _construct()
{
$this->_init(‘provider/provider’);
}
}
local/p/pmodel/session.php
<?php
class Practice_Provider_Model_Session extends Mage_Core_Model_Session_Abstract
{
public function __construct()
{
$this->init(‘provider’);
}

}
local/p/p/model/provider.php

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

local/p/p/model/mysql/provider/collection.php

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

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

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

}
}

Advertisements

Responses

  1. I don’t know If I said it already but …This blog rocks! I gotta say, that I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, 🙂

    A definite great read..Tony Brown


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: