For this you can change on this file path
local/yourmodule/block/adminhtml/yourmodulename/edit/tab/form.phtml
you use below functions,
<?php
class Addon_Testing_Block_Adminhtml_Testing_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
// This for get category detail
public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
{
$level++;
//-----new start for only 3 level category
if($level>3)
{
return $values;
}
//-----new close
$values[$node->getId()]['value'] = $node->getId();
$values[$node->getId()]['label'] = str_repeat("---", $level) . $node->getName();
foreach ($node->getChildren() as $child)
{
$values = $this->buildCategoriesMultiselectValues($child, $values, $level);
print_r($values);
}
return $values;
}
public function load_tree()
{
$tree = Mage::getResourceSingleton('catalog/category_tree')->load();
$store = 1;
$parentId = 1;
$tree = Mage::getResourceSingleton('catalog/category_tree')->load();
$root = $tree->getNodeById($parentId);
if($root && $root->getId() == 1)
{
$root->setName(Mage::helper('catalog')->__('Root'));
}
$collection = Mage::getModel('catalog/category')->getCollection()
->setStoreId($store)
->addAttributeToSelect('name')
->addAttributeToSelect('is_active');
$tree->addCollectionData($collection, true);
return $this->buildCategoriesMultiselectValues($root, array());
}
//This is for product id
function getProductCollection()
{
$model = Mage::getModel('catalog/product'); //getting product model
$collection = $model->getCollection(); //products collection
$count = 0;
foreach ($collection as $product) //loop for getting products
{
$a = $count++;
$values[$a]['value'] = $a;
$values[$a]['label'] = $product->getId();
}
return $values;
}
// This is for Product Sku
function getProductCollectionskus()
{
$model = Mage::getModel('catalog/product'); //getting product model
$collection = $model->getCollection(); //products collection
$count = 0;
foreach ($collection as $product) //loop for getting products
{
$a = $count++;
$values[$a]['value'] = $a;
$values[$a]['label'] = $product->getSku();
}
return $values;
}
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('testing_form', array('legend'=>Mage::helper('testing')->__('Item information')));
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('testing')->__('Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
$fieldset->addField('girl', 'text', array(
'label' => Mage::helper('testing')->__('Girl'),
'class' => 'required-entry',
'required' => true,
'name' => 'girl',
));
$fieldset->addField('filename', 'file', array(
'label' => Mage::helper('testing')->__('File'),
'required' => false,
'name' => 'filename',
));
// Here, call above Functions
$pids = $this->getProductCollection();
$skus = $this->getProductCollectionskus();
$categories_values = $this->load_tree();
//echo "<pre>";
//print_r($pids);
//echo "</pre>";
//$categories_values = $this->load_tree();
//echo '<pre>';
//print_r($skus);
//echo "</pre>";
$fieldset->addField('productid', 'multiselect', array(
'name' => 'productid',
'label' => Mage::helper('testing')->__('Select Product ID'),
'required' => true ,
'values' => $pids,
));
$fieldset->addField('productsku', 'multiselect', array(
'name' => 'productsku',
'label' => Mage::helper('testing')->__('Select Product Sku'),
'required' => true ,
'values' => $skus,
));
$fieldset->addField('productsku', 'multiselect', array(
'name' => 'productsku',
'label' => Mage::helper('testing')->__('Select Category'),
'required' => true ,
'values' => $categories_values,
));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('testing')->__('Content'),
'title' => Mage::helper('testing')->__('Content'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => false,
'required' => true,
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('testing')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('testing')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('testing')->__('Disabled'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getTestingData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getTestingData());
Mage::getSingleton('adminhtml/session')->setTestingData(null);
} elseif ( Mage::registry('testing_data') ) {
$form->setValues(Mage::registry('testing_data')->getData());
}
return parent::_prepareForm();
}
}
Magento
local/yourmodule/block/adminhtml/yourmodulename/edit/tab/form.phtml
you use below functions,
<?php
class Addon_Testing_Block_Adminhtml_Testing_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
// This for get category detail
public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
{
$level++;
//-----new start for only 3 level category
if($level>3)
{
return $values;
}
//-----new close
$values[$node->getId()]['value'] = $node->getId();
$values[$node->getId()]['label'] = str_repeat("---", $level) . $node->getName();
foreach ($node->getChildren() as $child)
{
$values = $this->buildCategoriesMultiselectValues($child, $values, $level);
print_r($values);
}
return $values;
}
public function load_tree()
{
$tree = Mage::getResourceSingleton('catalog/category_tree')->load();
$store = 1;
$parentId = 1;
$tree = Mage::getResourceSingleton('catalog/category_tree')->load();
$root = $tree->getNodeById($parentId);
if($root && $root->getId() == 1)
{
$root->setName(Mage::helper('catalog')->__('Root'));
}
$collection = Mage::getModel('catalog/category')->getCollection()
->setStoreId($store)
->addAttributeToSelect('name')
->addAttributeToSelect('is_active');
$tree->addCollectionData($collection, true);
return $this->buildCategoriesMultiselectValues($root, array());
}
//This is for product id
function getProductCollection()
{
$model = Mage::getModel('catalog/product'); //getting product model
$collection = $model->getCollection(); //products collection
$count = 0;
foreach ($collection as $product) //loop for getting products
{
$a = $count++;
$values[$a]['value'] = $a;
$values[$a]['label'] = $product->getId();
}
return $values;
}
// This is for Product Sku
function getProductCollectionskus()
{
$model = Mage::getModel('catalog/product'); //getting product model
$collection = $model->getCollection(); //products collection
$count = 0;
foreach ($collection as $product) //loop for getting products
{
$a = $count++;
$values[$a]['value'] = $a;
$values[$a]['label'] = $product->getSku();
}
return $values;
}
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('testing_form', array('legend'=>Mage::helper('testing')->__('Item information')));
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('testing')->__('Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
$fieldset->addField('girl', 'text', array(
'label' => Mage::helper('testing')->__('Girl'),
'class' => 'required-entry',
'required' => true,
'name' => 'girl',
));
$fieldset->addField('filename', 'file', array(
'label' => Mage::helper('testing')->__('File'),
'required' => false,
'name' => 'filename',
));
// Here, call above Functions
$pids = $this->getProductCollection();
$skus = $this->getProductCollectionskus();
$categories_values = $this->load_tree();
//echo "<pre>";
//print_r($pids);
//echo "</pre>";
//$categories_values = $this->load_tree();
//echo '<pre>';
//print_r($skus);
//echo "</pre>";
$fieldset->addField('productid', 'multiselect', array(
'name' => 'productid',
'label' => Mage::helper('testing')->__('Select Product ID'),
'required' => true ,
'values' => $pids,
));
$fieldset->addField('productsku', 'multiselect', array(
'name' => 'productsku',
'label' => Mage::helper('testing')->__('Select Product Sku'),
'required' => true ,
'values' => $skus,
));
$fieldset->addField('productsku', 'multiselect', array(
'name' => 'productsku',
'label' => Mage::helper('testing')->__('Select Category'),
'required' => true ,
'values' => $categories_values,
));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('testing')->__('Content'),
'title' => Mage::helper('testing')->__('Content'),
'style' => 'width:700px; height:500px;',
'wysiwyg' => false,
'required' => true,
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('testing')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('testing')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('testing')->__('Disabled'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getTestingData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getTestingData());
Mage::getSingleton('adminhtml/session')->setTestingData(null);
} elseif ( Mage::registry('testing_data') ) {
$form->setValues(Mage::registry('testing_data')->getData());
}
return parent::_prepareForm();
}
}
No comments:
Post a Comment