How to remove sidebar tabs in admin grid form of magento? - 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

Related

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();
}
}

add tab in admin dashboard magento 1.7.0.2

Copy Ordered.php
From
app/code/core/Mage/Adminhtml/Block/Dashboard/Tab/Products
to
app/code/local/Mage/Adminhtml/Block/Dashboard/Tab/Products
Rename New.php
I have modified the following code:
class Mage_Adminhtml_Block_Dashboard_Tab_Products_New extends Mage_Adminhtml_Block_Dashboard_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('productsNewGrid');
}
protected function _prepareCollection()
{
if (!Mage::helper('core')->isModuleEnabled('Mage_Sales')) {
return $this;
}
if ($this->getParam('website')) {
$storeIds = Mage::app()->getWebsite($this->getParam('website'))->getStoreIds();
$storeId = array_pop($storeIds);
} else if ($this->getParam('group')) {
$storeIds = Mage::app()->getGroup($this->getParam('group'))->getStoreIds();
$storeId = array_pop($storeIds);
} else {
$storeId = (int)$this->getParam('store');
}
$todayStartOfDayDate = Mage::app()->getLocale()->date()
->setTime('00:00:00')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$todayEndOfDayDate = Mage::app()->getLocale()->date()
->setTime('23:59:59')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
$collection
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayEndOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayStartOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter(
array(
array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
)
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('name', array(
'header' => $this->__('Product Name'),
'sortable' => false,
'index' => 'product_name'
));
$this->addColumn('price', array(
'header' => $this->__('Price'),
'width' => '120px',
'type' => 'currency',
'currency_code' => (string) Mage::app()->getStore((int)$this->getParam('store'))->getBaseCurrencyCode(),
'sortable' => false,
'index' => 'product_price'
));
$this->addColumn('ordered_qty', array(
'header' => $this->__('Quantity Ordered'),
'width' => '120px',
'align' => 'right',
'sortable' => false,
'index' => 'qty_ordered',
'type' => 'number'
));
$this->setFilterVisibility(false);
$this->setPagerVisibility(false);
return parent::_prepareColumns();
}
/*
* Returns row url to show in admin dashboard
* $row is bestseller row wrapped in Product model
*
* #param Mage_Catalog_Model_Product $row
*
* #return string
*/
public function getRowUrl($row)
{
// getId() would return id of bestseller row, and product id we get by getProductId()
$productId = $row->getProductId();
// No url is possible for non-existing products
if (!$productId) {
return '';
}
$params = array('id' => $productId);
if ($this->getRequest()->getParam('store')) {
$params['store'] = $this->getRequest()->getParam('store');
}
return $this->getUrl('*/catalog_product/edit', $params);
}
}
Then Copy Grids.php
From
app/code/core/Mage/Adminhtml/Block/Dashboard/
to
app/code/local/Mage/Adminhtml/Block/Dashboard/
added the following code:
$this->addTab('new_products', array(
'label' => $this->__('New Product'),
'content' => $this->getLayout()->createBlock('adminhtml/dashboard_tab_products_new')->toHtml(),
'class' => 'ajax'
));
I want to add a new product tab in admin dashboard,beside customers.I don't know what wrong with the New.php.I click the new product tab,it's not working.How to fix it?
I have managed to get this working with only a few more lines to change.
Update the Dashboard controller Mage_Adminhtml_DashboardController to add the new action
public function productsNewAction()
{
$this->loadLayout();
$this->renderLayout();
}
Update the admin layout.xml design\adminhtml\default\default\layout\main.xml to add the new section
<adminhtml_dashboard_productsnew>
<block type="core/text_list" name="root" output="toHtml">
<block type="adminhtml/dashboard_tab_products_new" name="adminhtml.dashboard.tab.products.new"/>
</block>
</adminhtml_dashboard_productsnew>
The you would just need to update your code in the Grids.php to the following.
$this->addTab('new_products', array(
'label' => $this->__('New Product'),
'url' => $this->getUrl('*/*/productsNew', array('_current'=>true)),
'class' => 'ajax'
));
This should then work using a call to the url rather than the block content.
You then need to select the attributes you want to show. You can do this by selecting all or by attribute code.
$collection->addAttributeToSelect('*')
$collection->addAttributeToSelect('name');
Important is the column index defined in _prepareColumns match these attribute codes Otherwise you will just get an empty row.
I would suggest packaging these changes into a new module with a controller, layout.xml and block files. There are lots of great tutorials around on how to do this, but obviously you don't have to :)

magento tabbed backend like catalog/product for custom entity

I want to write a module with a custom entity. In the backend it shall look like the backend from products (tabs on the left, forms on the right).
I tried many variants and inspected/copied many things from the core to understand it... well I don't.
Knows anyone a tutorial or the neccessary key points to realize this?
Many thanks
Edit: well, it's not the problem to create own entities, this is well known.
I need help to create the backend, so that the result looks like the tabbed form when editting products
For adding multiple tabs in admin first go through the http://codemagento.com/2011/02/grids-and-forms-in-the-admin-panel/ provided by mpaepper.
after that create below class
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form
Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab
and modify the
Super_Awesome_Block_Adminhtml_Example_Edit_Form to
class Super_Awesome_Block_Adminhtml_Example_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',
'enctype' => 'multipart/form-data',
));
$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Add below code
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
public function __construct() {
parent::__construct();
$this->setId('awesome_tabs');
$this->setDestElementId('edit_form');
$this->setTitle(Mage::helper('awesome')->__('Your Title Here'));
}
protected function _beforeToHtml() {
$this->addTab('form_section', array(
'label' => Mage::helper('awesome')->__('Details'),
'title' => Mage::helper('awesome')->__('Details'),
'content' => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_form')->toHtml(),
));
$this->addTab('secondtab_section', array(
'label' => Mage::helper('awesome')->__('SecondTab'),
'title' => Mage::helper('awesome')->__('SecondTab'),
'content' => $this->getLayout()->createBlock('awesome/adminhtml_awesome_edit_tab_secondtab')->toHtml(),
));
return parent::_beforeToHtml();
}
}
...
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('awesome_form', array('legend'=>Mage::helper('awesome')->__('Header text here')));
$fieldset = $form->addFieldset('example_form', array(
'legend' =>Mage::helper('awesome')->__('Example Information')
));
$fieldset->addField('name', 'text', array(
'label' => Mage::helper('awesome')->__('Name'),
'class' => 'required-entry',
'required' => true,
'name' => 'name',
'note' => Mage::helper('awesome')->__('The name of the example.'),
));
$fieldset->addField('description', 'text', array(
'label' => Mage::helper('awesome')->__('Description'),
'class' => 'required-entry',
'required' => true,
'name' => 'description',
));
$fieldset->addField('other', 'text', array(
'label' => Mage::helper('awesome')->__('Other'),
'class' => 'required-entry',
'required' => true,
'name' => 'other',
));
if (Mage::getSingleton('adminhtml/session')->getExampleData())
{
$data = Mage::getSingleton('adminhtml/session')->getExamplelData();
Mage::getSingleton('adminhtml/session')->getExampleData(null);
}
elseif (Mage::registry('example_data'))
{
$data = Mage::registry('example_data')->getData();
}
else
{
$data = array();
}
return parent::_prepareForm();
}
}
....
class Super_Awesome_Block_Adminhtml_Example_Edit_Tabs_SecondTab extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId('awesomeGrid');
$this->setDefaultSort('awesome_secondtab_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setFilterVisibility(false);
$this->setPagerVisibility(false);
}
protected function _prepareCollection() {
$id = $this->getRequest()->getParam('id');
$collection = Mage::getModel('awesome/secondtab')->getCollection()->addFilter('awesome_id', $id);
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('created_time', array(
'header' => Mage::helper('awesome')->__('Date'),
'index' => 'created_time',
'type' => 'datetime',
'align' => 'left',
'sortable' => false,
));
$this->addColumn('type', array(
'header' => Mage::helper('awesome')->__('Type'),
'align' => 'left',
'index' => 'type',
'sortable' => false,
));
$this->addColumn('amount', array(
'header' => Mage::helper('awesome')->__('Amount'),
'align' => 'left',
'index' => 'amount',
'type' => 'currency',
'currency' => 'amount',
'sortable' => false,
));
$this->addColumn('balance', array(
'header' => Mage::helper('awesome')->__('Balance'),
'align' => 'left',
'index' => 'balance',
'type' => 'currency',
'currency' => 'balance',
'sortable' => false,
));
$this->addColumn('order_number', array(
'header' => Mage::helper('awesome')->__('Order Number'),
'align' => 'left',
'index' => 'order_number',
'sortable' => false,
));
return parent::_prepareColumns();
}
}

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.

CakePHP validation always true

I've been struggling with this for the last hour or so, wondering if some fresh eyes can help.
Model
class User extends AppModel {
public $name = 'User';
public $validate = array(
'email' => array(
'valid' => array(
'rule' => 'email',
'message' => 'The email is not valid'
),
'required' => array(
'rule' => 'notEmpty',
'message' => 'Please enter an email'
)
)
);
}
Controller
class UserController extends AppController {
var $uses = array('User');
function index(){
$users = $this->User->find('all');
$this->set(compact('users'));
}
public function add() {
$this->set('title_for_layout', 'Add new user');
if(isset($this->data) && !empty($this->data)) {
$this->User->set($this->data);
$this->log($this->User->invalidFields(), "debug");
if($this->User->validates()){
if ($this->User->save($this->data)) {
$this->Session->setFlash("Added " . $this->data['User']['name']);
$this->redirect('index');
}
} else {
$this->Session->setFlash('There are errors with your form submit, please see below.');
}
}
}
}
View
<?php
echo $this->Form->create('User');
echo $this->Form->input('name', array('label' => 'Name'));
echo "<div class='clear'></div>";
echo $this->Form->input('email', array('label' => 'Email'));
echo "<div class='clear'></div>";
echo $this->Form->button('Reset', array('type' => 'reset'));
echo $this->Form->button('Add Useer', array('type' => 'submit'));
echo $this->Form->end();
?>
But I never get invalid fields for email? Have I missed something glaring?
If it makes any difference, this is a plugin Im developing so it doesnt sit directly in app/ but in app/Plugins
Thanks
EDIT: So I've been struggling with this for a while now, and still no joy. One thing I have noticed though, when I print out the model details (using var_dump($this->User) ), the [validate] array is empty. For example:
[validate] => Array
(
)
[validationErrors] => Array
(
)
Im presuming this is what the issue is, even though I have declared my $validate array, its somehow being overwritten? Anyone come across this before? Any solutions?
public $validate = array(
'email' => array(
'valid' => array(
'rule' => array('email'),
'message' => 'The email is not valid'
),
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Please enter an email',
'allowEmpty' => false
)
)
);
Try adding rules as array and adding 'allowEmpty' key set to false on the required validation.
Damn! So simple. If I read the cookbook properly at http://book.cakephp.org/1.3/en/view/1114/Plugin-Models it would have told me that
If you need to reference a model within your plugin, you need to include the plugin name with the model name, separated with a dot.
Thus..
var $uses = array('Plugin.User');
works.. Hope this helps someone else!

Resources