yii method to disable selected options from multi select dropdown - drop-down-menu

I am using Yii dropdown with active records in that I am using a multiselect dropdown. I am creating data with in which I am selected multiple options from the dropdown. While updating I want to disable selected options which I selected at time of creation.
<code>
<?php
$savedSections = helpers::getQuestionnaireSectionList($model->questionnaire_id);
$data = helpers::getSection();
$listData = CHtml::listData($data, 'section_id', 'section_name');
$htmlOptions = array('size' => '5', 'multiple' => 'true','style'=>'width: 333px');
$queSection->section_ref_id = $savedSections; #sec2
echo $form->listBox($queSection,'section_ref_id',$listData, $htmlOptions); #sec1
?>
<code>
Now here #sec1 is showing output with multiple options and I am also getting selected options but I want to disable all the selected options which are coming from #sec2
Please help me if you have any ideas.

change your $htmlOptions to be like this:
$htmlOptions = array(
'size' => '5',
'multiple' => 'true',
'options'=>array(45=>array('disabled'=>'disabled')),
);
45 here is a section_id
and if you want to find out how it's implemented you can take a look a this
https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php#L2516

Related

Not saving data when add multiple select attribute in product grid

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 ?

Magento: Add Custom Attribute to Order Grid

I have a custom attribute in my product that i want it to appears in the orders grid, the attribute is added to mg_catalog_product_flat_1 table but when i try to make the above join i get an error, all other built in attributes like name, sku works fine so how can i get this done
Please check my code below
$collection->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'Productid' => new Zend_Db_Expr('group_concat(`sales/order_item`.product_id SEPARATOR ",")'),
//'manufacturer' => new Zend_Db_Expr('group_concat(`sales/order_item`.manufacturer_value SEPARATOR ",")'),
'name' => new Zend_Db_Expr('group_concat(`sales/order_item`.name SEPARATOR ",")'),
)
);
$collection->getSelect()->group('main_table.entity_id');
parent::setCollection($collection);
$this->addColumn('manufacturer', array(
'header' => Mage::helper('sales')->__('manufacturer'),
'width' => '100px',
'index' => 'manufacturer',
'type' => 'text',
));
If i uncomment manufacturer part i get an error a
An item is not the equivalent of a product. If you want to get attribute of a product in an item, you need to call the $item->getProduct() function to be able to get all the attributes of the product that are not defined in the item.
Then, you need to apply it to your collection. To do that, you can use the function walk of the collection object to apply a function on each element. The problem, in my opinion, is that you need to loop over you collection of order and then on the collection of items to get the attribute you need.
Another solution is to follow the recommandation of custom prdoduct's attribute to quote/order item. This mean the attribute will be added to all items all the time but will be avaiable like sku...
Hope it helps,

Magento - How can I add or remove a custom option from a product in the cart?

I'm trying to add or remove custom options from a product in the cart. The custom options are defined against the product itself in the back end, I'm not trying to make up a new custom option dynamically or anything like that. All of my custom options are single checkboxes, in case it makes a difference.
I'm using an observer on checkout_cart_update_items_after and looping through Mage::getSingleton('checkout/session')->getQuote()->getAllItems(). I can see which items currently have a custom option selected using
$orderOptions = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct());
if ( isset($orderOptions['info_buyRequest']['options']) )
// cart item has options selected.
In the first instance I'd really like to be able to remove these custom options. I expected to be able to find something like $item->removeOption($optionId);, but I can't find any way of doing this.
In the second instance I'd really like to be able to add a custom option to an item. I've tried various ways of doing this including $item->addOption(array('code'=>$optionCode, 'value'=>1));.
I can't get either to work, and I'm sure I'm just missing something quite simple. Can you help?
If you want to specify custom product options on-the-fly on quote items (Ex:adding Delivery date with each product in the orders), you can make use of an observer toadd a custom option.
Example:
<controller_action_predispatch_checkout>
<observers>
<options_observer>
<class>YOUR_CLASS_NAME</class>
<method>setProductInfo</method>
</options_observer>
</observers>
</controller_action_predispatch_checkout>
$deliveryDate = $prId['delivery_date'];
if (!empty($deliveryDate)) {
$opt['options'] = array($optionID => $deliveryDate);
$request->setParams($opt);
}
return $this;
Another way to add option is
$item->addOption(array(
'code' => 'additional_options',
'value' => serialize($additionalOptions),
));
Suppose you have below option
$option = array(
'title' => 'Auto Date & Time',
'type' => 'date_time',
'is_require' => 1,
'sort_order' => 0,
'is_delete' => '',
'previous_type' => '',
'previous_group' => '',
'price' => '0.00',
'price_type' => 'fixed',
'sku' => ''
);
Fetch $product->getOptionInstance() directly
$product->getOptionInstance()->addOption($option);
$product->setHasOptions(true); //mention that the product has custom options
To delete the custom option:
if($product->getOptions() != ''{
foreach ($product->getOptions() as $opt){
$opt->delete();
}
$product->setHasOptions(0)->save();
}
Hope it helps !!!

How to set filter in grid of admin in magento?

I am working on magento 1.7 version.
I have a grid in magento admin. When I click on a particular row it opens a form and two tabs in left sidebar.
when I click on one tab it is displaying a grid in right side.
Now I want that in this grid a filter should be auto selected.
Ex.-
http://d.pr/i/UuB4
http://d.pr/i/BN1N
In this, category should be auto selected in filter and how to get current row id in tabs.php in _beforeToHtml().
I am using following code for tabs
protected function _beforeToHtml() {
$this->addTab('form_section', array(
'label' => Mage::helper('test')->__('Category'),
'title' => Mage::helper('test')->__('Category'),
'content' => $this->getLayout()->createBlock('test/adminhtml_category_edit_tab_form')->toHtml(),
));
$this->addTab('tab_section', array(
'label' => Mage::helper('test')->__('Images'),
'title' => Mage::helper('test')->__('Images'),
'content' => $this->getLayout()->createBlock('test/adminhtml_book_grid')
->toHtml()
));
return parent::_beforeToHtml();
}
any help would be much appreciated.
you can use this code to set the filter value -
$this->setDefaultFilter(array('category'=>3));
where 3 - category id in your grid's _prepareCollection() method.

How to add admin user attributes in Magento

I'd like to add some new attributes to the admin users in Magento. These users are different than customers (just to make it clear) and it's only possible to set their user/name/lastname/mail/pass, but I'd like to add a few new attributes.
To do so, I guess I can use the addattribute function, but I need to find out which is the id of these admin users. For example, if I want to add a new attribute to a customer, I can use a function like this:
$setup->addAttribute('customer','attribute_id', $attr );
So, in this case, 'customer' is the id for customers. How can I find out which id is used for admin users? (this question can be extended to "How can I find the different id for the different types of attributes in Magento?").
==There is a chance that there is no way to change this. I've taken a look at the admin_user table and it's quite simple, all fields are there. So maybe there are no attributes in this case.==
Thanks
You can find all such ids (entity ids) in the eav_entity_type table.
And yes, there is no record for admin user. Because all data about admin users are stored in flat tables but not in eav. So to add a new attribute to admin user, you need to add a new column in the admin_user table
You will need to add a column to the admin_user table.
$installer->getConnection()->addColumn($installer->getTable('admin/user'), 'location', array(
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
'length' => 256,
'nullable' => true,
'default' => null
));
Then, if you want to add/edit this field from the backend you need to rewrite the method Mage_Adminhtml_Block_Permissions_User_Edit_Tab_Main::_prepareForm and add a new element in there:
$fieldset->addField('location', 'select', array(
'name' => 'is_active',
'label' => Mage::helper('adminhtml')->__('location'),
'id' => 'is_active',
'title' => Mage::helper('adminhtml')->__('location'),
'class' => 'input-select',
'style' => 'width: 80px',
'options' => array('1' => Mage::helper('adminhtml')->__('Yes'), '0' => Mage::helper('adminhtml')->__('No')),
));
Clear the cache and it should work.
No option till 1.7
thats what i use in the template to show the sku to an specific user bit dirty but works fine:
<?php
//EGS SKU added for Power User
$_powerUser = 777;
if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $_powerUser)
{
echo '<div class="price-from">' . $_product->getSku() . '</div>';
}
?>

Resources