Call specific tab on edit form in custom module in magento - magento

I created one custom module in magento.When i click on the grid it moves to edit form where i can see three tabs like tab1,tab2,tab3.By default tab1 is selected.Now i want to add one link on grid and when customer click on that link browser redirect user to the tab3.How can i do that.My tab code as follow :
protected function _beforeToHtml()
{
$this->addTab('form_section', array(
'label' => Mage::helper('mymodule')->__('Information'),
'title' => Mage::helper('mymodule')->__('Information'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_form')->toHtml(),
));
$this->addTab('form_section1', array(
'label' => Mage::helper('mymodule')->__(' Management'),
'title' => Mage::helper('mymodule')->__('Management'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_managment')->toHtml(),
));
$this->addTab('form_section2', array(
'label' => Mage::helper('mymodule')->__('Results'),
'title' => Mage::helper('mymodule')->__('Results'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result')->toHtml(),
));
return parent::_beforeToHtml();
}
My link code like that one on grid listing page. <a class="viewit" href="http://localhost/project/index.php/mymodule/adminhtml_mymodule/view/id/4/key/83063e416ef7f9cfb7825d01e4519293/">View</a>.My contoller function as:
public function viewAction()
{
$this->loadLayout();
$block = $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result');
// $this->_addContent($this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result'))
//->_addLeft($this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tabs'));
$this->getLayout()->getBlock('content')->append($block);
$this->renderLayout();
}

The code at Mage_Adminhtml_Block_Widget_Tabs::addTab suggests that tabs have property active. Try adding it to your addTab call:
$this->addTab('form_section2', array(
'label' => Mage::helper('mymodule')->__('Results'),
'title' => Mage::helper('mymodule')->__('Results'),
'content' => $this->getLayout()->createBlock('mymodule/adminhtml_mymodule_edit_tab_result')->toHtml(),
'active' => true
));
Or you can extend your Grid's row URLs with parameter activeTab set to 'form_section2' (the name of the active tab) and add the following code to the _beforeToHtml function of the Tabs block class:
$param = Mage::app()->getRequest()->get('activeTab');
if (array_key_exists($param, $this->_tabs)) {
$this->_tabs[$param]->setActive();
}

Related

ajax call in magento 2

I have created a custom module in Magento2 where currently I'm selecting a customer and entered multiple order numbers, it will saved into a custom table in the database.
Currently I have to entered order numbers in a textarea but now I want to display all orders after choosing the customer which are not in Complete status.
From this section admin choose orders by clicking on the right side checkbox and Saved it.
Can anyone help me to solve this problem?
Existing Module’s Layout
Want to modify the above layout to the following one: In this desired system when admin change the customer name order numbers associated with that customer will be listed.
New invoice
Code I have used to create the customer dropdown field:
$fieldset->addField('customer_id', 'select', array(
'label' => __('Customer'),
'name' => 'customer_id',
'title' => __('Customer'),
'values' => $this->getCustomerOptionArray()
));
protected function getCustomerOptionArray()
{
$options = array();
$options[] = array(
'value' => 0,
'label' => __('Select Customer'),
);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerObj = $objectManager->create('Magento\Customer\Model\Customer')->getCollection();
foreach ($customerObj as $customerObjdata ){
$options[] = array(
'value' => $customerObjdata->getId(),
'label' => $customerObjdata->getName(),
);
}
return $options;
}

Add onclick method on checkbox on grid in sales order?

I have added a custom column at sales_order_grid table and add this code at _prepareColumns() functions at grid.php and this checkbox is now showing but i cann't add onclick function at this column ,
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'field_name'=>'exported_',
'values' => array(1,2),//$this->_getExported(),//
'onclick' => $this->getJsObjectName('addRelatedToExport'),
));
I am stuck from 4 days,Help me ,
Thanks in advance.
Include this function in your grid file. Grid.php
protected function _prepareMassaction(){
$this->setMassactionIdField('entity_id'); // code to make the checkbox related with
$this->getMassactionBlock()->setFormFieldName('form_field_name');
$this->getMassactionBlock()->addItem('addRelatedToExport', array(
'label'=> Mage::helper('ModuleName')->__('Add to Export'),
'url' => $this->getUrl('*/*/massRelatedExport')
));
return $this;
}
And then in the same module controller e.g ModuleName/controllers/adminhtml/someController
public function massRelatedExportAction(){
// your code here
}

Magento: only existing countries in drop-down filter for "Country" column in Grid View

I have created a custom Grid View with the "Country" column:
$this->addColumn('ship_country', array(
'header' => $this->__('Country'),
'index' => 'countrycode',
'type' => 'country'
));
The collection list which is displayed in the grid has only 2 countries: Ireland and UK.
Problem: the Filter Header for country column shows the drop-down list with all possible, over 200, countries stored inside Magento.
Question: is it possible to force filter to show only Ireland and UK in the drop-down?
Like this:
I have solved this problem with the following code:
$this->addColumn('ship_country', array(
'header' => $this->__('Country'),
'index' => 'countrycode',
'type' => 'options',
'options' => Mage::helper('mymodule')->getCountries(),
));
Where Helper getCountries() method looks something like this:
public function getCountries() {
$collection = Mage::getModel('mymodule/entity')->getCollection();
$collection->getSelect()->group('countrycode');
$countries = array();
foreach($collection as $item)
$countries[$item->getcountrycode()] = Mage::getModel('directory/country')->load($item->getcountrycode())->getName();
return $countries;
}

Add mailto functionality in admin field

How can i new field in admin filed that contain mailto functionality
$fieldset->addField('email', 'link', array(
'label' => Mage::helper('mumodule')->__('Email'),
"target"=>"_blank",
'mailto' => Mage::registry('mumodule')->getData('email'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
using this way i cant add functionality.
is it possible to add new filed with mailto functionality?
You must create your own form field renderer. For this you will need a custom module. If you don't know how to do that here's a good starting point: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_an_admin_form_module
Create a new file in app/code/[local/community]/MyCompany/MyModule/Varien/Data/Form/Element/Mailto.php with this content:
class MyCompany_MyModule_Varien_Data_Form_Element_Mailto extends Varien_Data_Form_Element_Abstract {
public function __construct($data) {
parent::__construct($data);
$this->setType('link');
}
public function getElementHtml() {
$html = $this->getBeforeElementHtml();
if ($this->getValue()) {
$html .= ' ';
}
$html .= $this->getAfterElementHtml();
return $html;
}
After that go to your form file and add this to the fieldset:
$fieldset->addType('mailto','MyCompany_MyModule_Varien_Data_Form_Element_Mailto');
$fieldset->addField('email', 'mailto', array(
'label' => Mage::helper('mymodule')->__('Email'),
'name' => 'email',
));
Of course, you should replace MyCompany namespace with the namespace that you already use in the module and MyModule with your module name. Also don't forget to place the file in the code pool where your module already exists: local/community
i achieve in simple way
$fieldset->addField('email', 'link', array(
'label' => Mage::helper('mumodule')->__('Email'),
'target' => '_blank',
'href' => 'mailto:' . urlencode(Mage::registry('mumodule')->getData('email')),
'class' => 'required-entry',
));
mailto: is part of the URL so it should be assigned in the href attribute:

Drupal AJAX Replace

I'm creating a custom user settings page. I have one field: zip_code that get's it's initial value from a custom user field. I have a custom function that pulls external data using the value of the zip_code.
I currently have the default value of the field set to the custom user field (if it's available). This is working as designed; however, I want to give the user the ability to change their zip code via an Ajax callback. This would replace the already populated radio buttons with new ones. I can't seem to wrap my head around this. Here's my code:
function settings_shopping_form($form, &$form_state) {
include_once "external.inc";
// Get user fields
global $user;
$user_fields = user_load($user->uid);
$zipcode = $user_fields->zip_code['und']['0']['value'];
if(isset($zipcode)) {
$form['zip_code'] = array(
'#title' => t('Zip Code'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => $zipcode,
'#ajax' => array(
'callback' => 'settings_form_callback',
'wrapper' => 'textfields',
),
);
$storename = getmystorename($zipcode);
if(count($storename) > 0) {
$form['textfields'] = array(
'#prefix' => '<div id="textfields">',
'#suffix' => '</div>',
'#type' => 'fieldset' );
$form['textfields']['stores'] = array(
'#type' => 'radios',
'#title' => t('Choose your store:'),
'#options' => $storename,
'#default_value' => $storename[1], );
} else {
$form['textfields']['incorrect'] = array(
'#title' => t('Sorry, there are no stores available near you. Check back later'),
'#type' => 'fieldset', );
}
}
My callback function is very simple:
function settings_form_callback($form, $form_state) {
return $form['textfields'];
}
To reiterate: I want to add the ability to replace the populated radio buttons with new buttons generated by the getmystorename function when the zip_code field is changed.
I ended up taking an example from the examples module (love it!):
$defaults = !empty($form_state['values']['zip_code']) ? $form_state['values']['zip_code'] : $zipcode;
$storename = getmystorename($defaults);
I put this before the start of my form so that the values load before the form builder.

Resources