Not saving data when add multiple select attribute in product grid - magento

I have created one custom module with add associated products concept. Created successfully. And Its working well.
But when i add "Multi select attribute" column in product grid with that option values, That entity value not saved.
If i removed that option values from that brand attribute drop down, Its saving fine.
I have shown my code below what i did for add multi select attribute column in product grid
under _prepareColumns() method
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand'); // attribute code here
foreach ( $attribute->getSource()->getAllOptions(true, true) as $option)
{
if($option['value'] != '')
$valArr[$option['value']] = $option['label'];
}
$this->addColumn('brand', array(
'header'=> Mage::helper('catalog')->__('Brand'),
'align' => 'left',
'index' => 'brand',
'type' => 'options',
'options' => $valArr,
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands', // Will have to create the renderer.
'filter_condition_callback' => array($this, '_filterBrandCondition')
));
When i hide 'options' => $valArr, , All are working fine.
I can't able to understand, why its happening. Please suggest me your ideas. Thanks in advance.

Have you already created the _filterBrandCondition function ?
What Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands look like ?

Related

magento show content according to condition in admin grid

I have developed custom admin module. I have used the usual methods _prepareCollection and _prepareColumns to show the data in Grid.
protected function _prepareCollection()
{
$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
$collection->getSelect()
->join( array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.seller_id and ce1.attribute_id = "5"', array('seller_name' => 'value'));
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
protected function _prepareColumns()
{
$helper = Mage::helper('sellers');
$currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
$this->addColumn('id', array(
'header' => $helper->__('Request No'),
'index' => 'id'
));
$this->addColumn('Requested Amount', array(
'header' => $helper->__('Requested Amount'),
'index' => 'request_amount'
));
$this->addColumn('Seller Name', array(
'header' => $helper->__('Seller Name'),
'index' => 'seller_name',
));
$this->addColumn('Status', array(
'header' => $helper->__('Status'),
'index' => 'status_flag'
));
All the data shows correctly according to the table values. But I want to show the Request Amount column values preceding with $ sign, e.g. $300 etc. Also, I want to show the status flag according to condition. Means if the status flag is 1 then I want to show the value as "Approved", if flag is 2 then "Pending" etc. How should I customize the collection data and show in grid according to my requirement? Help appreciated.
Thanks.
I have answered to a question similar to your requirement
How to properly add a shipping_description column in magento order grid?
Check my answer and try to compare with your problem. In this example there is the solution for our currency problem too.
So check this out.Hope it will be helpful.
Here you should implement Grid Renderer.
Here is complete tutorial for that : http://inchoo.net/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/
You can customize the value of any colum

Add and show new column in sales_flat_order and show this at order grid in magento

I have added a new column (exported)in sales_flat_order and add at files at this location:
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->addAttributeToSelect('*')
->joinAttribute('exported','sales/order','sales_flat_order.entity_id',null,'left');
}
protected function _prepareColumns()
{
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'name' =>'exported',
'value' =>$this->getExported()==1 ? 'true' : 'false',
));
}
after that it showing on order grid in admin site,but it is not showing value and name,
I am new in magento,so please help me ,
stuck from 2 days.
Thanks for Assistance.
The method _prepareCollection() uses sales_flat_order_grid table as asource, thus you have to add the column to sales_flat_order_grid table and update the values of that column from the appropriate column of sales_flat_order table.
In this case, Magento will automatically update this column in sales_flat_order_grid table for future orders.
The better way to display the boolean column is Yes/No renderer. Use the following code for this in _prepareColumns() method
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'options',
'width' => '70px',
'options' => array(
1 => Mage::helper('sales')->__('Yes'),
0 => Mage::helper('sales')->__('No'),
),
));
There are some other useful articles about cutomizing order grid. Check out the links below:
http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/
http://www.ecomdev.org/2010/07/27/adding-order-attribute-to-orders-grid-in-magento-1-4-1.html
http://www.demacmedia.com/magento-commerce/mini-tutorial-adding-column-to-orders-grid-in-magento-backend/
http://www.atwix.com/magento/column-to-orders-grid/

How to create custom source model for custom attribute type select?

I tried to search this but couldn't find any. When creating a custom product attribute with select type programmatically, Magento always assigns eav/entity_attribute_source_table as the source model.
There are 2 issues with this default source model:
I can't auto populate the field with data taken programmatically from somewhere else other than have to type the data list manually one by one.
Although I have specified the "default" or "default_value" (I can see in the database that the value is there), the field is still showing empty as the first line.
How I can change the default source_model to my own source model for select type?
Thank you
The key you are looking for is to pass a source value in your SQL setup. Make sure your $installer is an EAV setup object.
You would do the following in your setup script:
$installer = $this;
$installer->starSetup();
// Setup customer multiselect attribute
$attr = array(
'backend' => 'eav/entity_attribute_backend_array',
'input' => 'multiselect',
'label' => 'Permissions',
'note' => 'Used for group-based frontend permissions.',
'required' => false,
'sort_order' => '1000',
'source' => 'eav/entity_attribute_source_table', // Change it here
'user_defined' => true
);
$installer->addAttribute('customer', 'permissions', $attr);
// Add options for permissions
$options = array(
'attribute_id' => $installer->getAttributeId('customer', 'permissions'),
'value' => array(
'place_order' => array('Can Place Orders'),
'view_catalog' => array('Can View the Catalog'),
)
);
$installer->addAttributeOption($options);
$installer->endSetup();
Utimately, I believe the source model can be anything that provides a toOptionArray() function.
There is a great example of this in Mage_Customer, installer: mysql4-upgrade-1.5.9.9-1.6.0.0.php
In it, a country source model is being assigned to customer address attribute country_id.
$installer->updateAttribute(
'customer_address',
'country_id',
'source_model',
'customer/entity_address_attribute_source_country'
);
Change this to catalog_product, your attribute, and source model.
You set the source type as shown below.
'source' => 'categoryattr/attribute_source_type',
and create the file Attribute\Source\Type.php and the create the options and set the value 0 for default option.
$this->_options[] = array (
'label' => 'Select Category',
'value' => '0'
);
please refer below for file structure and step by step explanation.
http://www.pearlbells.co.uk/how-to-create-custom-attribute-source-type-in-magento/

Magento Admin formfield multiselect selected

I´m currently developing a custom module for magento thats going to list employees.
I have figured out almost everything. The only thing I got left is how the selected values is going to be highlighted.
The problem I´m having is for the backend.
I got 2 tabs per employee, one for employee data and one tab for magento categories.
1 employee can have 1 or more categories.
The database table that the categories are stored in are a non-eav table.
So my question is
What in a multiselect determines which values are selected? As it is now, only one value is selected.
I think you can do this by simply passing in an array of the id's to be selected into the 'value' attribute of the field being added for the multiselect in the _prepareForm() method. Something like the following.
$fieldset->addField('category_id', 'multiselect', array(
'name' => 'categories[]',
'label' => Mage::helper('cms')->__('Store View'),
'title' => Mage::helper('cms')->__('Store View'),
'required' => true,
'values' => Mage::getSingleton('mymodule/mymodel')->getMymodelValuesForForm(),
'value' => array(1,7,10),
));
The id of the form element (e.g. category_id) must not be an attribute in your model, otherwise when the form values get set with $form->setValues() later on, the attribute value will be overwritten.
I normally store multiple selections as a text column separated by commas much like most magento modules handles stores which requires a slightly different approach as shown below.
In the form block for the tab with the multiselect, you firstly define the element to be displayed like so in the _prepareForm() method. You then get the values from the model and set put them into the form data.
protected function _prepareForm()
{
...
$fieldset->addField('store_id', 'multiselect', array(
'name' => 'stores[]',
'label' => Mage::helper('cms')->__('Store View'),
'title' => Mage::helper('cms')->__('Store View'),
'required' => true,
'values' => Mage::getSingleton('adminhtml/system_store')->getStoreValuesForForm(false, true),
));
...
if ( Mage::getSingleton('adminhtml/session')->getMymodelData() )
{
$data = Mage::getSingleton('adminhtml/session')->getMymodelData();
} elseif ( Mage::registry('mymodel_data') ) {
$data = Mage::registry('mymodel_data')->getData();
}
$data['store_id'] = isset($data['stores']) ? explode(',', $data['stores']) : array();
$form->setValues($data);
}
I normally store the selected stores (categories as in your case) in the main model as a text column and comma separated values of ids, hence the explode.
In the controller for for the edit action, I put the model being edited into the mage registry so we can load it and it's values in the step above.
Mage::register('mymodel_data', $model);
Thanks for answering.
This is how my field looks like:
$fieldset->addField('npn_CatID', 'multiselect', array(
'label' => Mage::helper('employeelist')->__('Kategori'),
'class' => 'required-entry',
'required' => true,
'name' => 'npn_CatID',
'values' => $data,
'value' => array(3,5)
));
npn_CatID is the value in my db where the category id is saved.
I have tried to change the name and field ID but cant get it working.
When its the field id is like above ONE value is selected and its the last one inserted for the chosen employee
My data array looks likes
array(array('value' => '1', 'label' => 'USB'), array('value' => '2', 'label' => 'Memories'))

How to customize the database value in magento customer grid

I created new magento grid for customer module for special purpose.
In that there have a column usertype it have value as 0,1,2.
It will displayed in customer grid page as 0,1,2.
But i need to display if value is,
0 -> Inactive
1 -> Activated
2 -> Baned
How can i dothis?
This is my code grid.php in _prepareColumns() :
$this->addColumn('usertype', array(
'header' => Mage::helper('customer')->__('Usertype'),
'width' => '150',
'index' => 'usertype'
));
If this is possible in magento.
if your greed implements Mage_Adminhtml_Block_Widget_Grid I suggest you to modify
you addColumn call to
$this->addColumn('usertype',
array(
'header'=> Mage::helper('customer')->__('Usertype'),
'width' => '150px',
'index' => 'usertype',
'type' => 'options',
'options' => $values
));
Where $values should be formatted as
array( 'value_id' => 'value_label')
Now you have dropdown created with values.
Then update _prepareCollection() function and add attribute values to customer grid collection
$collection->joinAttribute('usertype', 'customer/usertype', 'entity_id', null, 'left');
I got the solution from this
By using rendere will help to load vlaues to each row.

Resources