add tab in admin dashboard magento 1.7.0.2 - magento

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 :)

Related

Magento 1.9: Why aren't certain values showing on the Sales > Orders grid?

Why are the payment methods not showing on my Sales > Orders grid?
I can get the column showing with the drop down list of payment options but the payment method values are not showing on the list of orders.
This is the query that produces the orders list:
SELECT `main_table`.*, `payment`.`method`
FROM
`sales_flat_order_grid` AS `main_table`
INNER JOIN `sales_flat_order_payment` AS `payment`
ON main_table.entity_id=payment.parent_id
The column I need to display the values for is called method and returns the correct results, for example worldpay_cc. The values are returned from the query but just aren't showing in the grid.
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->join(array('payment'=>'sales/order_payment'),'main_table.entity_id=payment.parent_id','method');
$collection->addProductData();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array(
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
Any ideas?
My guess would be that you haven't mapped the payment methods correctly maybe:
Mage_Adminhtml_Block_Sales_Order_Grid
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => array( // <--- The mapping, here
'worldpay_cc' => 'Worldpay',
'cashondelivery' => 'Cash on Delivery',
'pay' => 'Pay',
'paypal_express' => 'Paypal Express',
)
));
return parent::_prepareColumns();
}
I would change the above to:
protected function _prepareColumns()
{
$this->addColumn('method', array(
'header' => $this->__('Payment Method'),
'index' => 'method',
'type' => 'options',
'width' => '70px',
'options' => $this->getActivePaymentMethods()
));
return parent::_prepareColumns();
}
public function getActivePaymentMethods()
{
$payments = Mage::getSingleton('payment/config')->getActiveMethods();
$methods = array();
foreach ($payments as $paymentCode=>$paymentModel) {
$paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
$methods[$paymentCode] = $paymentTitle;
}
return $methods;
}
With reference to my comment, addProductData is a custom function:
Mage_Sales_Model_Order_Grid_Collection
public function addProductData($attributesCodes)
{
foreach ($attributesCodes as $attributeCode) {
$attributeTableAlias = $attributeCode . '_table';
$attribute = Mage::getSingleton('eav/config')
->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeCode);
$this->getSelect()->join(
array($attributeTableAlias => $attribute->getBackendTable()),
"main_table.product_id = {$attributeTableAlias}.entity_id AND {$attributeTableAlias}.attribute_id={$attribute->getId()}",
array($attributeCode => 'value')
);
$this->_map['fields'][$attributeCode] = 'value';
}
return $this;
}

Magento loose table details in Google sitemap

I have problems with google sitemap.
as you can see in here, I lost the detail table!...if i click add sitemap i get white page!
How can do to restore?
thank you
regards
You may have issue in "/app/code/core/Mage/Adminhtml/Block/Sitemap/Grid.php". So check the file. Here is a code of Grid.php
class Mage_Adminhtml_Block_Sitemap_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('sitemapGrid');
$this->setDefaultSort('sitemap_id');
}
protected function _prepareCollection()
{
$collection = Mage::getModel('sitemap/sitemap')->getCollection();
/* #var $collection Mage_Sitemap_Model_Mysql4_Sitemap_Collection */
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('sitemap_id', array(
'header' => Mage::helper('sitemap')->__('ID'),
'width' => '50px',
'index' => 'sitemap_id'
));
$this->addColumn('sitemap_filename', array(
'header' => Mage::helper('sitemap')->__('Filename'),
'index' => 'sitemap_filename'
));
$this->addColumn('sitemap_path', array(
'header' => Mage::helper('sitemap')->__('Path'),
'index' => 'sitemap_path'
));
$this->addColumn('link', array(
'header' => Mage::helper('sitemap')->__('Link for Google'),
'index' => 'concat(sitemap_path, sitemap_filename)',
'renderer' => 'adminhtml/sitemap_grid_renderer_link',
));
$this->addColumn('sitemap_time', array(
'header' => Mage::helper('sitemap')->__('Last Time Generated'),
'width' => '150px',
'index' => 'sitemap_time',
'type' => 'datetime',
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sitemap')->__('Store View'),
'index' => 'store_id',
'type' => 'store',
));
}
$this->addColumn('action', array(
'header' => Mage::helper('sitemap')->__('Action'),
'filter' => false,
'sortable' => false,
'width' => '100',
'renderer' => 'adminhtml/sitemap_grid_renderer_action'
));
return parent::_prepareColumns();
}
/**
* Row click url
*
* #return string
*/
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('sitemap_id' => $row->getId()));
}
}

Magento - How to Save entire grid using mass action

I have a warehouse grid in my module. My warehouse contains a lot of products, so when i am going to edit the warehouse, i added a products grid in warehouse edit tab. But, i confused about how to save the entire products grid to database. Really need help.
Here is my Grid
public function __construct() {
parent::__construct();
$this->setId('UnicornInventoryGrid');
$this->setDefaultSort('id_warehouse');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
protected function _prepareCollection() {
$collection = Mage::getModel('inventory/warehouse')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('id_warehouse', array(
'header' => Mage::helper('inventory')->__('id_warehouse'),
'filter_index' => 'main_table.id_warehouse',
'index' => 'id_warehouse',
'width' => '5px',
));
$this->addColumn('warehouse_name', array(
'header' => Mage::helper('inventory')->__('Warehouse Name'),
'filter_index' => 'main_table.warehouse_name',
'index' => 'warehouse_name',
'editable' => 'TRUE',
'width' => '5px',
));
$this->addColumn('created_by', array(
'header' => Mage::helper('inventory')->__('Created By'),
'filter_index' => 'main_table.created_by',
'index' => 'created_by',
'width' => '5px',
'editable' => 'TRUE',
));
$this->addColumn('manager_email', array(
'header' => Mage::helper('inventory')->__('Manager\'s Email'),
'filter_index' => 'main_table.manager_email',
'index' => 'manager_email',
'width' => '5px',
'editable' => 'TRUE',
));
$this->addColumn('phone', array(
'header' => Mage::helper('inventory')->__('Phone'),
'filter_index' => "main_table.phone",
'index' => "phone",
'editable' => 'TRUE',
));
$this->addColumn('street', array(
'header' => Mage::helper('inventory')->__('Street'),
'filter_index' => "ce3.street",
'index' => "street",
'editable' => 'TRUE',
));
$this->addColumn('city', array(
'header' => Mage::helper('inventory')->__('City'),
'filter_index' => 'main_table.city',
'index' => 'city',
'editable' => 'TRUE',
));
$this->addColumn('country', array(
'header' => Mage::helper('inventory')->__('Country'),
'filter_index' => 'main_table.country',
'index' => 'country',
'type' => 'options',
'editable' => 'TRUE',
'options' => array("" => "All Countries" , "Indonesia" => "Indonesia", "US" => "US")
));
$this->addColumn('status', array(
'header' => Mage::helper('inventory')->__('Status'),
'filter_index' => 'main_table.status',
'index' => 'phone',
));
// $this->addColumn('action',
// array(
// 'header' => Mage::helper('inventory')->__('Action'),
// 'width' => '100',
// 'type' => 'action',
// 'getter' => 'getId',
// 'actions' => array(
// array(
// 'caption' => Mage::helper('inventory')->__('Edit'),
// 'url' => array('base'=> '*/*/edit'),
// 'field' => 'id'
// )
// ),
// 'filter' => false,
// 'sortable' => false,
// 'index' => 'stores',
// 'is_system' => true,
// ));
$this->addExportType('*/*/exportCsv', Mage::helper('inventory')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('inventory')->__('XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction() {
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('inventory_warehouse_mass_action');
$this->getMassactionBlock()->addItem('save', array(
'label' => Mage::helper('inventory')->__('Save'),
'url' => $this->getUrl('*/*/massSaveProduct'),
'confirm' => Mage::helper('inventory')->__('Are you sure?')
));
return $this;
}
public function getRowUrl($row) {
return $this->getUrl('*/*/edit', array('id' => $row->getIdWarehouse()));
}
and here is my controller
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
// die("sadfsaf");
}
public function newAction() {
$id = $this->getRequest()->getParam('id');
if(empty($id)) $this->_title($this->__('Admin'))->_title($this->__('Add Warehouse'));
else $this->_title($this->__('Admin'))->_title($this->__('Edit Warehouse'));
$model = Mage::getModel('inventory/warehouse')->load($id);
if ($model->getId() || empty($id)) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if (!empty($data))
$model->setData($data);
Mage::register('warehouse_warehouse_data', $model);
$this->loadLayout();
$this->_setActiveMenu('unicorn_inventory');
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->_addContent($this->getLayout()->createBlock('inventory/adminhtml_warehouse_edit'))
->_addLeft($this->getLayout()->createBlock('inventory/adminhtml_warehouse_edit_tabs'));
$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('inventory')->__('Warehouse does not exist.'));
$this->_redirect('*/*/');
}
}
public function editAction() {
$id = $this->getRequest()->getParam('id');
if(empty($id)) $this->_title($this->__('Admin'))->_title($this->__('Add Warehouse'));
else $this->_title($this->__('Admin'))->_title($this->__('Edit Warehouse'));
$model = Mage::getModel('inventory/warehouse')->load($id);
if ($model->getId() || empty($id)) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if (!empty($data))
$model->setData($data);
Mage::register('inventory_warehouse_data', $model);
$this->loadLayout();
$this->_setActiveMenu('unicorn_warehouse');
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
$this->_addContent($this->getLayout()->createBlock('inventory/adminhtml_warehouse_edit'))
->_addLeft($this->getLayout()->createBlock('inventory/adminhtml_warehouse_edit_tabs'));
$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('inventory')->__('Warehouse does not exist.'));
$this->_redirect('*/*/');
}
}
public function saveAction() {
if ($data = $this->getRequest()->getPost()) {
$model = Mage::getModel('inventory/warehouse');
$model->setData($data)
->setData('id_warehouse' , $this->getRequest()->getParam('id'));
try {
$collection = Mage::getModel('inventory/warehouse')->getCollection();
foreach($collection as $item){
if(($item->getIdWarehouse() == $model->getIdWarehouse()) && ($model->isObjectNew())){
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('inventory')->__("Id '" . $model->getIdWarehouse(). "' already assigned."));
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/new');
return;
}
}
// echo "<pre>";
// var_dump($data);
// echo "</pre>";
// die();
$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('inventory')->__('Warehouse telah disimpan'));
Mage::getSingleton('adminhtml/session')->setFormData(false);
if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
if ($this->getRequest()->getParam('backandnew')) {
$this->_redirect('*/*/new');
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('inventory')->__('Unable to find warehouse to save.'));
$this->_redirect('*/*/');
}
/**
* mass save item(s) action
*/
public function massSaveProductAction() {
$dataIds = $this->getRequest()->getParam('inventory_warehouse_mass_action');
if (!is_array($dataIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('inventory')->__('Please select item(s)'));
} else {
try {
foreach ($dataIds as $dataId) {
// $model = Mage::getModel('inventory/wareproduct')->load($dataId);
$model = Mage::getModel('inventory/wareproduct');
$model->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('supplier')->__('Total of %d record(s) were successfully deleted.', count($dataIds)));
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}
/**
* export grid item to CSV type
*/
public function exportCsvAction() {
$fileName = 'Unicorn_Inventory.csv';
$content = $this->getLayout()->createBlock('warehouse/adminhtml_warehouse_grid')->getCsv();
$this->_prepareDownloadResponse($fileName, $content);
}
/**
* export grid item to XML type
*/
public function exportXmlAction() {
$fileName = 'warehouse_warehouse.xml';
$content = $this->getLayout()->createBlock('warehouse/adminhtml_warehouse_grid')->getXml();
$this->_prepareDownloadResponse($fileName, $content);
}
public function gridAction()
{
$this->loadLayout();
$this->getResponse()->setBody(
$this->getLayout()->createBlock('inventory/adminhtml_warehouse_edit_tab_product')->toHtml()
);
}
So, what should we do, so every row in the grid can submitted and saved to database. Thx a lot for your attention.
In
massSaveProductAction
exchange the lines
$model = Mage::getModel('inventory/wareproduct');
$model->delete();
with
$model = Mage::getModel('inventory/wareproduct');
$model->setData('your_attribute_code',"YOUR_VALUE");
$model->save();
Answer for second question:
Get a collection of whatever entity type you have...
$collection->addFieldToFilter('YOUR_GRID_ID_FIELD', array('in'=>array($gridIds)))
and you have the collection. Iterate over the collection and do whatever is needed...

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

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

Resources