A) Open your Form.php File "app\code\local\[Namespace]\[Module Name]\Block\Adminhtml\[Modele Name]\Edit\Tab\Form.php"
/* Three functions for call Category list, Product_ids and Product Skus */
<?php
class Addon_Beautygirl_Block_Adminhtml_Beautygirl_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
public function buildCategoriesMultiselectValues(Varien_Data_Tree_Node $node, $values, $level = 0)
{
$level++;
//-----new start for only 3 level category
if($level>3)
{
return $values;
// print_r($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);
}
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());
}
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]['label'] = $product->getId();
$values[$a]['value'] = $product->getId();
//$pids[] = $product->getId();
//return $product->getSku();
}
//print_r($pids);
return $values;
}
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]['label'] = $product->getSku();
$values[$a]['value'] = $product->getSku();
}
//print_r($pids);
return $values;
}
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('beautygirl_form', array('legend'=>Mage::helper('beautygirl')->__('Item information')));
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('beautygirl')->__('Title'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('beautygirl')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('beautygirl')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('beautygirl')->__('Disabled'),
),
),
));
$fieldset->addField('filename', 'file', array(
'label' => Mage::helper('beautygirl')->__('File'),
'required' => true,
'name' => 'filename',
));
/* This Variable's Contain that Function's Values */
$pids = $this->getProductCollection();
$skus = $this->getProductCollectionskus();
$categories_values = $this->load_tree();
$field set->addField('girloneproductid', 'multiselect', array(
'name' => 'girloneproductid',
'label' => Mage::helper('beautygirl')->__('Select Product ID'),
'required' => true ,
'values' => $pids,
));
$fieldset->addField('girloneproductsku', 'multiselect', array(
'name' => 'girloneproductsku',
'label' => Mage::helper('beautygirl')->__('Select Product SKU'),
'required' => false ,
'values' => $skus,
));
$fieldset->addField('girlonecategoryid', 'multiselect', array(
'name' => 'girlonecategoryid',
'label' => Mage::helper('beautygirl')->__('Select Category'),
'required' => false ,
'values' => $categories_values,
));
No comments:
Post a Comment