How to get Manufacturer dropdown in custom module edit form? - magento

I want to add images for each brand, for that i have created a module. in module's edit form i want a manufacturer dropdown list so i can assign image to the particular manufacturer/brand.
its my code for the edit form location:
app/code/local/Root/Brand/Block/Adminhtml/Brand/Edit/Tab/form.php
$fieldset->addField('title', 'select', array(
'name' => 'title',
'label' => 'Brand',
'values' => Mage::getUrl('catalogsearch/advanced/result', array(
'brand' => $option['value']
))
));
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('brand')->__('Brand Image') ,
'required' => false,
'name' => 'filename',
'note' => '(*.jpg, *.png, *.gif)'
));

$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer');
//here, "brandname" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
$fieldset->addField('title', 'select', array(
'label' => Mage::helper('brand')->__('Brand Name'),
'name' => 'title',
'values' => $allOptions
));

Related

Configurable product and its associated product creation using soap api documentation is not in magento api guide.any idea?

I am trying to create a configurable product and its associated product using magento soap api.Product created successfully but configurable product linking with associated product is not working properly guys any idea? This is my code
<?php
$client = new SoapClient('https://sample.com/api/v2_soap?wsdl=1');
// If some stuff requires api authentification,
// then get a session token
$session = $client->login('username', 'Password');
// get attribute set
$attributeSets = $client->catalogProductAttributeSetList($session);
$attributeSet = current($attributeSets);
print_r($attributeSet);
$result = $client->catalogProductCreate($session, 'simple',72, 'product_sku0002', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description',
'additional_attributes' => array(
'single_data' => array(
array(
'key' => 'color',
'value' => 'Red', // Id or label of color, attribute that will be used to configure product
)
),
),
));
var_dump ($result);
$result = $client->catalogProductCreate($session, 'configurable',72, 'Configurable_product_sku0001', array(
'categories' => array(2),
'websites' => array(1),
'name' => 'Confihurable Product name',
'description' => 'Product description',
'short_description' => 'Product short description',
'weight' => '10',
'status' => '1',
'url_key' => 'product-url-key',
'url_path' => 'product-url-path',
'visibility' => '4',
'price' => '100',
'tax_class_id' => 1,
'meta_title' => 'Product meta title',
'meta_keyword' => 'Product meta keyword',
'meta_description' => 'Product meta description',
'associated_skus' => array('product_sku0002'),
'price_changes' => array(
array(
'color' => array(
'Red' => '0'
)
),
),
));
var_dump ($result);
?>
Its working fine using this method follow the link
http://www.bubblecode.net/en/2012/04/20/magento-api-associate-simple-products-to-configurable-or-grouped-product/

Codeigniter: Display multiple images from database for

I'm running a real estate website. I'm trying to list all images in the database for a particular listing on their respective page. I have the following code but it just repeats the same default image instead of showing all images for that listing.
Model:
public function getDetails($listing_id)
{
$this->db->select(
'listings.listing_id AS id,
listings.account_id AS account_id,
listings.nbrhood_id AS nbrhood_id,
listings.price AS price,
listings.convertible AS convertible,
listings.available AS available,
images.file_name AS file_name,
listings.sqft AS sqft,
listings.db_tag AS db_tag,
listings.web_id AS web_id,
listings.description AS description,
bedrooms.beds_num AS beds_val,
bedrooms.beds_name AS beds_text,
bathrooms.baths_num AS baths_val,
bathrooms.baths_name AS baths_text,
nbrhoods.nbrhood_name AS nbrhood,
nbrhoods.image AS nbrhood_image,
types_listings.type_name AS type,
pets.pet_name AS pets'
);
$this->db->join('images', 'images.image_id = listings.image_id', 'left');
$this->db->join('bedrooms', 'bedrooms.beds_id = listings.beds_id');
$this->db->join('bathrooms', 'bathrooms.baths_id = listings.baths_id');
$this->db->join('nbrhoods', 'nbrhoods.nbrhood_id = listings.nbrhood_id');
$this->db->join('types_listings', 'types_listings.type_id = listings.type_id');
$this->db->join('pets', 'pets.pet_id = listings.pet_id');
$this->db->where('listings.listing_id', $listing_id);
$this->db->limit(1);
return $this->db->get($this->table_name)->row();
}
PHP:
<?php foreach ($listing AS $listing_id): ?>
<li data-image-id="<?=$image -> image_id ?>" class="uploaded-image" id="image_<?=$image -> image_id ?>">
<div class="sortableimagewrapper">
<!-- <span class="label label-inverse image-name"> </span> -->
<img src="<?=images_url('110x68/' . $listing -> file_name) ?>" alt="" width="110px" height="68px" class="img-polaroid" />
</div>
</li>
<?php endforeach; ?>
class Listing_Model extends CW_Model {
protected $table_name = 'listings';
protected $order_by = 'listing_id';
protected $primary_key = 'listing_id';
protected $display_val = '';
public $defaults = array(
'status_id' => 1
);
public $qualifiers = array('listing_id', 'account_id', 'status_id', 'image_id', 'file_name', 'featured', 'feature_id', 'deal_id', 'nbrhood_id', 'beds_id', 'baths_id', 'pet_id', 'type_id', 'owner_id', 'web_id', 'price', 'convertible', 'available', 'sqft', 'address', 'unit', 'zip', 'description', 'notes');
public $rules = array(
'new' => array(
'listing_id' => array(
'field' => 'listing_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'account_id' => array(
'field' => 'account_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'status_id' => array(
'field' => 'status_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'image_id' => array(
'field' => 'image_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'file_name' => array(
'field' => 'file_name',
'label' => '',
'rules' => 'trim|xss_clean'
),
'featured' => array(
'field' => 'featured',
'label' => '',
'rules' => 'trim|xss_clean'
),
'feature_id' => array(
'field' => 'feature_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'deal_id' => array(
'field' => 'deal_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'nbrhood_id' => array(
'field' => 'nbrhood_id',
'label' => 'Neighborhood',
'rules' => 'trim|required|xss_clean'
),
'beds_id' => array(
'field' => 'beds_id',
'label' => 'Bedrooms',
'rules' => 'trim|required|xss_clean'
),
'baths_id' => array(
'field' => 'baths_id',
'label' => 'Bathrooms',
'rules' => 'trim|required|xss_clean'
),
'pet_id' => array(
'field' => 'pet_id',
'label' => 'Pets',
'rules' => 'trim|required|xss_clean'
),
'type_id' => array(
'field' => 'type_id',
'label' => 'Listing Type',
'rules' => 'trim|required|xss_clean'
),
'owner_id' => array(
'field' => 'owner_id',
'label' => 'Owner/Landlord',
'rules' => 'trim|required|xss_clean'
),
'web_id' => array(
'field' => 'web_id',
'label' => 'Web ID',
'rules' => 'trim|alpha_dash|xss_clean'
),
'price' => array(
'field' => 'price',
'label' => 'Price',
'rules' => 'trim|required|min_length[3]|integer|xss_clean'
),
'convertible' => array(
'field' => 'convertible',
'label' => 'Convertible',
'rules' => 'trim|is_natural|xss_clean'
),
'dateAvailable' => array(
'field' => 'dateAvailable',
'label' => '',
'rules' => 'trim|xss_clean'
),
'available' => array(
'field' => 'available',
'label' => 'Date Available',
'rules' => 'trim|required|xss_clean'
),
'sqft' => array(
'field' => 'sqft',
'label' => 'Square Feet',
'rules' => 'trim|min_length[3]|integer|xss_clean'
),
'address' => array(
'field' => 'address',
'label' => 'Street Address',
'rules' => 'trim|required|min_length[12]|xss_clean'
),
'unit' => array(
'field' => 'unit',
'label' => 'Unit Number',
'rules' => 'trim|required|max_length[5]|alpha_dash|xss_clean'
),
'zip' => array(
'field' => 'zip',
'label' => 'Zip Code',
'rules' => 'trim|required|exact_length[5]|integer|xss_clean'
),
'description' => array(
'field' => 'description',
'label' => 'Description',
'rules' => 'trim|required|min_length[175]|xss_clean'
),
'notes' => array(
'field' => 'notes',
'label' => 'Notes',
'rules' => 'trim|xss_clean'
),
'amenity_ids[unit][]' => array(
'field' => 'amenity_ids[unit][]',
'label' => 'Unit Amenities',
'rules' => 'trim|xss_clean'
),
'amenity_ids[property][]' => array(
'field' => 'amenity_ids[property][]',
'label' => 'Property Amenities',
'rules' => 'trim|xss_clean'
),
'image_ids[]' => array(
'field' => 'image_ids[]',
'label' => '',
'rules' => 'trim|xss_clean'
)
),
'edit' => array(
'listing_id' => array(
'field' => 'listing_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'account_id' => array(
'field' => 'account_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'status_id' => array(
'field' => 'status_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'image_id' => array(
'field' => 'image_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'file_name' => array(
'field' => 'file_name',
'label' => '',
'rules' => 'trim|xss_clean'
),
'featured' => array(
'field' => 'featured',
'label' => '',
'rules' => 'trim|xss_clean'
),
'feature_id' => array(
'field' => 'feature_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'deal_id' => array(
'field' => 'deal_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'nbrhood_id' => array(
'field' => 'nbrhood_id',
'label' => 'Neighborhood',
'rules' => 'trim|required|xss_clean'
),
'price' => array(
'field' => 'price',
'label' => 'Price',
'rules' => 'trim|required|min_length[3]|integer|xss_clean'
),
'beds_id' => array(
'field' => 'beds_id',
'label' => 'Bedrooms',
'rules' => 'trim|required|xss_clean'
),
'convertible' => array(
'field' => 'convertible',
'label' => 'Convertible',
'rules' => 'trim|is_natural|xss_clean'
),
'baths_id' => array(
'field' => 'baths_id',
'label' => 'Bathrooms',
'rules' => 'trim|required|xss_clean'
),
'dateAvailable' => array(
'field' => 'dateAvailable',
'label' => '',
'rules' => 'trim|xss_clean'
),
'available' => array(
'field' => 'available',
'label' => 'Date Available',
'rules' => 'trim|required|xss_clean'
),
'pet_id' => array(
'field' => 'pet_id',
'label' => 'Pets',
'rules' => 'trim|required|xss_clean'
),
'sqft' => array(
'field' => 'sqft',
'label' => 'Square Feet',
'rules' => 'trim|min_length[3]|integer|xss_clean'
),
'type_id' => array(
'field' => 'type_id',
'label' => 'Listing Type',
'rules' => 'trim|required|xss_clean'
),
'description' => array(
'field' => 'description',
'label' => 'Description',
'rules' => 'trim|required|min_length[175]|xss_clean'
),
'amenity_ids[unit][]' => array(
'field' => 'amenity_ids[unit][]',
'label' => 'Unit Amenities',
'rules' => 'trim|xss_clean'
),
'amenity_ids[property][]' => array(
'field' => 'amenity_ids[property][]',
'label' => 'Property Amenities',
'rules' => 'trim|xss_clean'
),
'owner_id' => array(
'field' => 'owner_id',
'label' => 'Owner/Landlord',
'rules' => 'trim|required|xss_clean'
),
'address' => array(
'field' => 'address',
'label' => 'Street Address',
'rules' => 'trim|required|min_length[12]|xss_clean'
),
'unit' => array(
'field' => 'unit',
'label' => 'Unit Number',
'rules' => 'trim|required|max_length[5]|alpha_dash|xss_clean'
),
'zip' => array(
'field' => 'zip',
'label' => 'Zip Code',
'rules' => 'trim|required|exact_length[5]|integer|xss_clean'
),
'notes' => array(
'field' => 'notes',
'label' => 'Notes',
'rules' => 'trim|xss_clean'
),
'image_ids[]' => array(
'field' => 'image_ids[]',
'label' => '',
'rules' => 'trim|xss_clean'
),
'web_id' => array(
'field' => 'web_id',
'label' => 'Web ID',
'rules' => 'trim|alpha_dash|xss_clean'
)
)
);
public function __construct() {
parent::__construct();
}
public function getNew() {
// Remember everytime you add a field you have to add it to form validation...
$listing = new stdClass();
$listing->listing_id = $this->_get_identifier();
$listing->account_id = $this->session->userdata('account_id');
$listing->status_id = 0;
$listing->feature_id = '';
$listing->image_id = 0;
$listing->nbrhood_id = ''; // Dropdown
$listing->beds_id = ''; // Dropdown
$listing->baths_id = ''; // Dropdown
$listing->pet_id = ''; // Dropdown
$listing->type_id = ''; // Dropdown
$listing->owner_id = ''; // Dropdown
$listing->web_id = 'CWA' . random_string('numeric', 7); // varchar
$listing->featured = ''; // bool
$listing->deal_id = '0'; // bool
$listing->price = ''; // int
$listing->convertible = ''; // bool
$listing->dateAvailable = ''; // Only to populate visible jQuery datapicker
$listing->available = ''; // date
$listing->sqft = ''; // int
$listing->address = ''; // varchar
$listing->unit = ''; // varchar
$listing->description = ''; // text
$listing->zip = ''; // int
$listing->notes = ''; // text
$listing->amenity_ids['unit'] = array(); // Dropdown
$listing->amenity_ids['property'] = array(); // Dropdown
$listing->image_ids = array();
return $listing;
}
I don't know about your data model. You should post it here. If your data model has been done correctly, then this is the line that would change:
$this->db->join('images', 'images.image_id = listings.image_id', 'left');
to
$this->db->join('images', 'images.listing_id = listings.id');
You should store the listing ID in the Images table rather than the other way round.
EDIT:
From data model, I mean database structure. If there are n images for every single 'listing', then you need to store a reference to the 'listing ID' in the 'images' table.
Took over this project from someone else. Where would I add fields to the image table. Right now in CMS it shows multiple images for a listing. The code is:
<?php foreach ($images as $image): ?>
<li data-image-id="<?=$image -> image_id ?>" class="uploaded-image" id="image_<?=$image -> image_id ?>">
<div class="sortableimagewrapper">
<!-- <span class="label label-inverse image-name"> </span> -->
<img src="<?=images_url('110x68/' . $image -> file_name) ?>" alt="" width="110px" height="68px" class="img-polaroid" />
<div class="btn-group">
<button class="btn <?php
if ($image -> image_id == $listing -> image_id)
echo 'btn-warning';
?> image-default"><span class="icon-star <?php
if ($image -> image_id == $listing -> image_id)
echo 'icon-white';
?>"></span></button>
<button class="btn image-remove"><span class="icon-remove"></span></button>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>

How to change comments data with onchange function in addfield in magento

I created custom module and now from admin side on edit form i added extra field select type.
I want to change comments with onchange function for this specific field.See below my code.
$eventElem = $fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
));
$eventElem->setAfterElementHtml("<script type=\"text/javascript\">function checkSelectedItem(selectElement){}</script>");
This is my code i alert the value and i got my value but it cannot show it in comments area .Did someone one know how to fix it ?
Thanks
This will update the comment (onchange) with the current selected option
$fieldset->addField('banner_type', 'select', array(
'label' => Mage::helper('multibanners')->__('Banner Style'),
'required' => false,
'onchange' => 'checkSelectedItem(this.value)',
'name' => 'banner_type',
'values' => array(
array(
'value' => 'Banner 1',
'label' => 'AnySlider',
),
array(
'value' => 'Banner 2',
'label' => 'Content Slider',
),
)
))->setAfterElementHtml("<small id='banner_type_comment'>Comments</small>
<script type=\"text/javascript\">
function checkSelectedItem(selectElement){
$('banner_type_comment').update($('banner_type')[$('banner_type').selectedIndex].text);
}
</script>");

Sort order on custom column from customer grid

On my Admin side customer grid, i have a situacion, some times and some customers on column name i need First Name + Last Name, it's already done by magento core, but some customer i need just to print First name. Take a look on my Grid.php, i need take off last name from 'name' catenation, but when i remove from collection my column sort stop work.
<?php
class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('customerGrid');
$this->setUseAjax(true);
$this->setDefaultSort('entity_id');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('customer/customer_collection')
->addNameToSelect()
->addAttributeToSelect('email')
->addAttributeToSelect('created_at')
->addAttributeToSelect('group_id')
->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');
/*foreach($collection as $customer){
preg_match("/[A-z| ]*//*", $customer->getName(), $name);
$customer->setName($name[0]);
unset($name);
}*/
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('entity_id', array(
'header' => Mage::helper('customer')->__('ID'),
'width' => '50px',
'index' => 'entity_id',
'type' => 'number',
));
/*
$this->addColumn('firstname', array(
'header' => Mage::helper('customer')->__('First Name'),
'index' => 'firstname'
));
$this->addColumn('lastname', array(
'header' => Mage::helper('customer')->__('Last Name'),
'index' => 'lastname'
));
*/
$this->addColumn('name', array(
'header' => Mage::helper('customer')->__('Name'),
'sortable' => true,
'index' => 'name'
));
$this->addColumn('email', array(
'header' => Mage::helper('customer')->__('Email'),
'width' => '150',
'index' => 'email'
));
$groups = Mage::getResourceModel('customer/group_collection')
->addFieldToFilter('customer_group_id', array('gt'=> 0))
->load()
->toOptionHash();
$this->addColumn('group', array(
'header' => Mage::helper('customer')->__('Group'),
'width' => '100',
'index' => 'group_id',
'type' => 'options',
'options' => $groups,
));
$this->addColumn('Telephone', array(
'header' => Mage::helper('customer')->__('Telephone'),
'width' => '100',
'index' => 'billing_telephone'
));
$this->addColumn('billing_postcode', array(
'header' => Mage::helper('customer')->__('ZIP'),
'width' => '90',
'index' => 'billing_postcode',
));
$this->addColumn('billing_country_id', array(
'header' => Mage::helper('customer')->__('Country'),
'width' => '100',
'type' => 'country',
'index' => 'billing_country_id',
));
$this->addColumn('billing_region', array(
'header' => Mage::helper('customer')->__('State/Province'),
'width' => '100',
'index' => 'billing_region',
));
$this->addColumn('customer_since', array(
'header' => Mage::helper('customer')->__('Customer Since'),
'type' => 'datetime',
'align' => 'center',
'index' => 'created_at',
'gmtoffset' => true
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('website_id', array(
'header' => Mage::helper('customer')->__('Website'),
'align' => 'center',
'width' => '80px',
'type' => 'options',
'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
'index' => 'website_id',
));
}
$this->addColumn('action',
array(
'header' => Mage::helper('customer')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('customer')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
$this->addExportType('*/*/exportCsv', Mage::helper('customer')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('customer')->__('Excel XML'));
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('customer');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('customer')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('customer')->__('Are you sure?')
));
$this->getMassactionBlock()->addItem('newsletter_subscribe', array(
'label' => Mage::helper('customer')->__('Subscribe to Newsletter'),
'url' => $this->getUrl('*/*/massSubscribe')
));
$this->getMassactionBlock()->addItem('newsletter_unsubscribe', array(
'label' => Mage::helper('customer')->__('Unsubscribe from Newsletter'),
'url' => $this->getUrl('*/*/massUnsubscribe')
));
$groups = $this->helper('customer')->getGroups()->toOptionArray();
array_unshift($groups, array('label'=> '', 'value'=> ''));
$this->getMassactionBlock()->addItem('assign_group', array(
'label' => Mage::helper('customer')->__('Assign a Customer Group'),
'url' => $this->getUrl('*/*/massAssignGroup'),
'additional' => array(
'visibility' => array(
'name' => 'group',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('customer')->__('Group'),
'values' => $groups
)
)
));
return $this;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=> true));
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}
}
Its wrong way i know, but have to get just first name and don't have other way.
But now this make my sort on columns from grid stop work. I need sort working.
If i remove this 3 lines from my _prepareCollection(), it's work fine but i need it too and with it don't work my sort. I'm crazy with this someone can help???
Ty in advise.
You're best bet would be to load the firstname attribute on the collection and add that as an independent column. Adding column to customer grid in Magento - Data not populating will give you a good start. You should just need to add in ->addAttributeToSelect('firstname') and then add the column in the prepareColumns function...
$this->addColumn('firstname', array(
'header' => Mage::helper('customer')->__('First Name'),
'index' => 'firstname'
));

Magento Custom module - how to add custom select box with parent categories

I wrote a module to have my own menu bar, rather than just using categories as a menu bar.
So, here I want to show already added menus while adding new menu in the Tab/Form.php in my custom menu module. How can I show all of the existing menu names as a dropdown/options list on the form. Here is the code that I used to have menu form.
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('menu_form', array('legend'=>Mage::helper('menu')->__('Menu information')));
$note = "Name of this Menu";
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('menu')->__('Menu Name'),
'class' => 'required-entry',
'required' => true,
'note' => $note,
'name' => 'title',
));
$note = "Menu level";
$fieldset->addField('level', 'select', array(
'label' => Mage::helper('menu')->__('Menu level'),
'name' => 'level',
'note' => $note,
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Level 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Level 2'),
),
),
));
$model = Mage::registry('menu');
$fieldset->addField('parent', 'text', array(
'name' => 'conditions',
'label' => Mage::helper('menu')->__('Parent Menu'),
'title' => Mage::helper('menu')->__('Parent Menu'),
'required' => false,
'note' => $note,
))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/conditions'));
$fieldset->addField('target', 'select', array(
'label' => Mage::helper('menu')->__('Open in new window'),
'name' => 'target',
'values' => array(
array(
'value' => "_blank",
'label' => Mage::helper('menu')->__('Yes'),
),
array(
'value' => "_self",
'label' => Mage::helper('menu')->__('No'),
),
),
));
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('menu')->__('Status'),
'name' => 'status',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Enabled'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Disabled'),
),
),
));
$note = "Menu Links to Which page. BaseURL(<b>".str_ireplace("index.php/","",Mage::getBaseUrl())."</b>) Will be Added Dynamically, Please add Your new page Refrence alone";
$fieldset->addField('menulink', 'text', array(
'label' => Mage::helper('menu')->__('URL'),
'required' => true,
'class' => 'required-entry',
'note' => $note,
'name' => 'menulink',
));
$fieldset->addField('position', 'select', array(
'label' => Mage::helper('menu')->__('Position'),
'name' => 'position',
'values' => array(
array(
'value' => 1,
'label' => Mage::helper('menu')->__('Top 1'),
),
array(
'value' => 2,
'label' => Mage::helper('menu')->__('Top 2'),
),
),
));
if ( Mage::getSingleton('adminhtml/session')->getMenuData() )
{
$form->setValues(Mage::getSingleton('adminhtml/session')->getMenuData());
Mage::getSingleton('adminhtml/session')->setMenuData(null);
} elseif ( Mage::registry('menu_data') ) {
$form->setValues(Mage::registry('menu_data')->getData());
}
return parent::_prepareForm();
In this I want to show all the added menus under the parent menu option. What should I write in my Model class so that I can have a drop down list to show them all, and after adding it should be added to database.
Please help me, am struggling here.
You can do this by adding these lines.
It will show already added menus as a dropdown list so that you can choose any of them as a parent menu for current item.
$_menus = Mage::getSingleton('menus/menus')->getCollection();
foreach($_menus as $item)
{
if($item->getParent == NULL){
$_menuItems[] = array(
'value' => $item->getId(),
'label' => $item->getTitle(),
);
}
}
$note = "Choose the parent menus for this item";
$fieldset->addField('parent', 'select', array(
'name' => 'parent',
'label' => Mage::helper('menus')->__('Parent Menu'),
'title' => Mage::helper('menus')->__('Parent Menu'),
'required' => false,
'note' => $note,
'class' => 'HideIt',
'values' => $_menuItems,
));

Resources