Add custom fields in review form - magento

I am looking forward to create a custom fields 'Email Id' & One drop-down in Review form .
I have tried this one but not saving the data, its hows the fields only
app\code\core\Mage\Review\Model\Mysql4\Review.php
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);
Now add email,fname in the review_detail table in the database also go to app\code\core\Mage\Adminhtml\Block\Review\Edit\Form.php also add :
$fieldset->addField('fname', 'text', array( // New field 2
'label' => Mage::helper('review')->__('First Name'),
'required' => true,
'name' => 'fname'
));
$fieldset->addField('email', 'text', array( // New field 1
'label' => Mage::helper('review')->__('Email'),
'required' => true,
'name' => 'email'
));
before to
$fieldset->addField('nickname', 'text', array(
'label' => Mage::helper('review')->__('Nickname'),
'required' => true,
'name' => 'nickname'
));

Modify the Mage core class is a bit scary, which will be difficult to upgrade magento core class in the future. You can override the specific class by your own custom module (See module creator if you want to setup one)
Module's config.xml, add the models rewrite in as below:
<global>
<models>
<review_mysql4>
<rewrite>
<review>[[Your Company]]_[[Your Module]]_Model_Review</review>
</rewrite>
</review_mysql4>
</models>
...
</global>
And the specified class will extend from the Magento core class you want to override:
class [[Your Company]]_[[Your Module]]_Model_Review
extends Mage_Review_Model_Mysql4_Review
{
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
....
}
}
Ps. to add the new field in magento review_detail table:
$installer = $this;
$installer->startSetup();
$installer->run("ALTER TABLE review_detail ADD COLUMN email VARCHAR(255) NULL");
$installer->endSetup();

Finally i have solved it...
Open
app\code\core\Mage\Review\Model\Resource\Review.php
you will find this code in line about 150
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
);
Add the new two fields you want to add.
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$detail = array(
'title' => $object->getTitle(),
'detail' => $object->getDetail(),
'nickname' => $object->getNickname(),
'email' => $object->getEmail(), // New field 1
'fname' => $object->getFname(), // New field 2
);
Thats it no more.... :) Happy coding

Related

Adding custom column into configurable product grid in admin

I have created a custom column for associated products (basically every simple product will have that column under "associated products" tab of configurable product). I store information of this field/column into an attribute which belong to configurable product instead of each simple product.
Below is the code for adding a column;
config.xml
<core_block_abstract_to_html_before>
<observers>
<something>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionColumn</method>
</something>
</observers>
</core_block_abstract_to_html_before>
Oberver.php
public function addPositionColumn(Varien_Event_Observer $observer)
{
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid) {
if (!$block->isReadonly()) {
$block->addColumnAfter(
'position_simple',
array(
'header' => Mage::helper('jsonproductinfo')->__('Position'),
'type' => 'input',
'name' => 'position_simple',
'index' => 'position_simple',
'sortable' => false,
),
'name'
);
}
}
}
With above code I am able to add the column into a require grid. And I am also able to save the information which I put inside that column (which is basically an attribute). The only problem I am facing is, I am unable to display the stored information into that column again (If I edit the product). I have also created another observer of type eav_collection_abstract_load_befor but no luck so far.
Below is the code for it:
config.xml
<eav_collection_abstract_load_before>
<observers>
<jsonproductinfo>
<class>namespace_JsonProductInfo_Model_Observer</class>
<method>addPositionToCatalogProductCollection</method>
</jsonproductinfo>
</observers>
</eav_collection_abstract_load_before>
Observer.php
public function addPositionToCatalogProductCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
if (!isset($collection)) {
return;
}
$collection->addAttributeToSelect('position_simple');
}
I would be grateful if someone can point to the mistake or guide me how can I display back that information again into that column.
EDIT And here is the code which creates the "position_simple" attribute.
$this->addAttribute(
'catalog_product',
'position_simple',
array(
'group' => 'General',
'type' => 'varchar',
'input' => 'hidden',
'backend' => '',
'frontend' => '',
'label' => 'Simple Position',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
'is_configurable' => false,
)
);
change 'index' => 'position_simple' to 'index' => 'entity_id' in your Observer.php (function addPositionColumn)
you need to get value of your position_simple attribute from configurable product and use it in added column - one way to do that:
create function in Observer.php
protected function _getDefaultConfigurationId() {
/** #var Mage_Catalog_Model_Product $product */
$product = Mage::registry('current_product');
if ($product) {
return array($product->getData('position_simple'));
}
return '';
}
and use that in your addPositionColumn function like that:
...
'values' => $this->_getDefaultConfigurationId(),
...
After that, there is no need of observer type eav_collection_abstract_load_befor at all.

Add multiple tabs and forms in backend of a custom module in magento just like customer backend porsitions

I have created a custom extension just like a customer module and I want backend just like a customer.
My extension has two tables and two models.
My modules are:
Mage::getModel('custommod/reg') - just like Mage::getModel('customer/customer'), reg saves data of registration
Mage::getModel('custommod/personal') - just like Mage::getModel('customer/address'), //personal data of a reg records.
Please check the image below:
Now I am facing the problem to show the data and edit .
In Magento customer admin section, Customer edit position has multiple tabs: Account information, Address etc.
Here, Account information tab saves data in customer/customer
and Address information tab saves data in customer/address.
I like this type of section.
After a long time work i have done it ,Here the solution
The tabs.php show left panel
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
{
public function __construct()
{
parent::__construct();
$this->setId('vendor_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('vendor')->__('Manage Vendor'));
}
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('vendor')->__('General Information'),
'title' => Mage::helper('vendor')->__('General Information'),
'content' => $this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_form')->toHtml(),
));
$this->addTab('vendor_details',array(
'label'=>Mage::helper('vendor')->__('Vendor Store Details'),
'title'=>Mage::helper('vendor')->__('Vendor Store Details'),
'content'=>$this->getLayout()->createBlock('vendor/adminhtml_list_edit_tab_storedetails')->toHtml(),
));
return parent::_beforeToHtml();
}
}
after the form.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$vendor = Mage::registry('vendor_data');
$form = new Varien_Data_Form();
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor Registration')
));
$fieldset->addField('name', 'text', array(
'name' => 'name',
'label' => Mage::helper('vendor')->__('Name'),
'required' => true,
));
$fieldset->addField('email', 'text', array(
'name' => 'email',
'label' => Mage::helper('vendor')->__('Email'),
'required' => true,
));
$fieldset->addField('user_name', 'text', array(
'name' => 'user_name',
'label' => Mage::helper('vendor')->__('User name'),
'required' => true,
));
$fieldset->addField('password', 'password', array(
'name' => 'password',
'class' => 'required-entry',
'label' => Mage::helper('vendor')->__('Password'),
'required' => true,
));
$this->setForm($form);
$form->setValues($vendor->getData());
return parent::_prepareForm();
}
public function filter($value)
{
return number_format($value, 2);
}
}
Second form Storedetails.php
<?php
class Amit_Vendor_Block_Adminhtml_List_Edit_Tab_Storedetails extends Mage_Adminhtml_Block_Widget_Form{
protected function _prepareForm(){
$vendorStore = Mage::registry('vendor_store_details');// new registry for different module
$form = new Varien_Data_Form();
//$form->setFieldNameSuffix('vendor_store');
$fieldset = $form->addFieldset('vendor_form', array(
'legend' => Mage::helper('vendor')->__('Vendor deatsilsn')
));
$fieldset->addField('alternative_email','text',array(
'name' =>'alternative_email',
'label' => Mage::helper('vendor')->__('Alternative Email'),
'required'=> false
));
$fieldset->addField('shopname','text',array(
'name' =>'shopname',
'label' => Mage::helper('vendor')->__('Shop Name'),
'required'=> true,
'class' => 'required-entry',
));
$fieldset->addField('company', 'text', array(
'name' => 'company',
'label' => Mage::helper('vendor')->__('Company'),
'required' => true,
'class' => 'required-entry',
));
$fieldset->addField('street','text',array(
'name' =>'vendor_details[street]',
'label' => Mage::helper('vendor')->__('Street Address'),
'required'=> false
));
$this->setForm($form);
$form->addValues($vendorStore->getData());
return parent::_prepareForm();
}
}

How to remove sidebar tabs in admin grid form of magento?

I am working on Magento community edition 1.7 version.
I have a grid in admin when I click on "Add New" from this grid a form appear but it has some tabs in left side.I need to remove that tabs and want only form.
http://d.pr/i/Qa8i
app/code/community/namespace/test/Block/Adminhtml/test/Edit/Tabs.php
My code for tabs in above file is:
protected function _beforeToHtml() {
$this->addTab('form_section', array(
'label' => Mage::helper('test')->__('Book'),
'title' => Mage::helper('test')->__('Book'),
'content' => $this->getLayout()->createBlock('test/adminhtml_book_edit_tab_form')->toHtml(),
));
return parent::_beforeToHtml();
}
Can anyone solve this problem?
In your Admin controller
please see editAction
$this->_addContent($this->getLayout()->createBlock('<module>/adminhtml_<module>_edit'))
->_addLeft($this->getLayout()->createBlock('<module>/adminhtml_<module>_edit_tabs'));
remove
->_addLeft($this->getLayout()->createBlock('<module>/adminhtml_<module>_edit_tabs'));
then create file name form.php in
app/code/community/namespace/test/Block/Adminhtml/test/Edit/Form.php
and paste the code in
class <Namespace>_<Module>_Block_Adminhtml_<Module>_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$<module>Form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
));
$<module>Form->setUseContainer(true);
$this->setForm($<module>Form);
$fieldset = $<module>Form->addFieldset('<module>_form', array(
'legend' => Mage::helper('<module>')->__('Item Information'),
'class' => 'fieldset-wide',
)
);
$fieldset->addField('<module>_name', 'text', array(
'label' => Mage::helper('<module>')->__('Name'),
'class' => 'required-entry',
'required' => true,
'name' => 'name',
));
if ( Mage::getSingleton('adminhtml/session')->get<Module>Data() )
{
$<module>Form -> setValues(Mage::getSingleton('adminhtml/session')->get<Module>Data());
Mage::getSingleton('adminhtml/session')->get<Module>Data(null);
} elseif ( Mage::registry('<module>_data') ) {
$<module>Form-> setValues(Mage::registry('<module>_data')->getData());
}
return parent::_prepareForm();
}
}
hello check below path app/code/community/namespace/yourmodule/Block/Adminhtml/yourmodule/Edit/Tabs.php
checkfunction _beforeToHtml() & __construct(). comment those you want
Hope this help you

Fieldset in system configuration - Magento Admin module

I am creating an admin module. I have set of fields and i want to create a fieldset each of 3 fields in system configuration, i have created fields but wanted to add fieldset in it.
Any help would be appreciated. Thank you
You haven't given much information i.e Layout of your module, whether you are adding fields in code or .phtml but this is how I am adding fields to a field set:
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('form_settings', array('legend'=>Mage::helper('mymodule')->__('Module Settings')));
$newFieldset = $fieldset->addFieldset('form_settings_test', array('legend'=>Mage::helper('khaosconnect')->__('Order Settings')));
$newFieldset->addField('mysetting1', 'text', array(
'label' => Mage::helper('mymodule')->__('Setting 1'),
'class' => 'required-entry',
'required' => true,
'name' => 'mysetting1',
'value' => "val1",
'style' => 'width:500px'
));
$newFieldset->addField('mysetting2', 'text', array(
'label' => Mage::helper('mymodule')->__('Setting 2'),
'class' => 'required-entry',
'required' => true,
'name' => 'mysetting2',
'value' => "val2",
'style' => 'width:500px'
));
}
EDIT: Updated to show nested fieldsets.

Magento Backend Product list grid

Does anyone know how to add a field containing an input type text element or a dropdown element to a magento backend product list grid?
I managed to add a new column to my custom module backend product listing grid like this:
$this->addColumn('blabla', array(
'header' => Mage::helper('customer')->__('On Hold?'),
'width' => '120',
'index' => 'bla',
'type' => 'options',
'options' => array('1' => 'Yes', '0' => 'No')
));
but this command only adds the dropdown to my grid header, while i need the dropdown to appear in the left side of every product listed on that grid (just like the checkbox appears when you go for instance in backend on a product edit page and you select related products, or upsell products)
Simple and fast solution as tip for next research - rewrite Mage_Adminhtml_Block_Catalog_Product_Grid, function _prepareColumns. Example you will create your block Module_Name_Block_Sample:
class Module_Name_Block_Sample extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
protected function _prepareColumns()
{
$this->addColumn('blabla', array(
'header' => Mage::helper('customer')->__('On Hold?'),
'width' => '120',
'index' => 'bla',
'type' => 'options',
'options' => array('1' => 'Yes', '0' => 'No')
));
return parent::_prepareColumns();
}
}
You will get it as first field. And it may need rewrite _prepareCollection.
But it may be not better solution, I know.
What you need is a custom renderer, where you can display any HTML you want. Something like this:
$this->addColumn('blabla', array(
'header' => Mage::helper('customer')->__('On Hold?'),
'width' => '120',
'index' => 'bla',
'renderer' => 'module/sample_grid_renderer'
));
And then you create your renderer class, where you create HTML you need:
class Module_Name_Block_Sample_Grid_Renderer
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$html = '<select name="row'.$row->getId().'"></select>';
return $html;
}
}
$country = $fieldset->addField('country', 'select', array(
'name' => 'country',
'label' => 'Country',
'values' => Mage::getModel('adminhtml/system_config_source_country') ->toOptionArray()
));
Try it! Have a nice day. Thank you.

Resources