Magento addAttribute to a specific product tab (admin) - php

Is it possible to use the addAttribute function to add an attribute directly to a specific product new & edit tab? For example the price tab?

Sure, just specify the tab by attribute 'group':
$installer->addAttribute('catalog_product', 'my_custom_product_attr',
array(
...
'group' => 'Tab XY',
...
));
You may also want to order your attribute inside the tab. You can do this by specifying the attribute position:
$installer->addAttribute('catalog_product', 'my_custom_product_attr',
array(
...
'group' => 'Tab XY',
'position' => Z
...
));

Related

how to add custom attribute in catalog/category in magento 1.9

how to add custom attribute in catalog/category in admin general tab which will display only on specific store not for all.
$installer = $this;
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY,
'banner_img1',
array(
'group' => 'General',
'type' => 'text',
'label' => 'Door Banner Image1',
'visible' => true,
'required' => false,
'visible_on_front' => false,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
));
$installer->endSetup();`
but above code create attribute in all store view i want to show only for 1 store
Magento attributes do not work that way. Store scope means that attribute can have different value for each store view, but you can't have it exist for one and not for other.
Even tho there's no way to add an attribute only for one store view, you can upload the image only for particular store view and add the check in your theme which will output the attribute only if it's present.

Magento custom dependent category attributes

I have some custom attributes for my project.
Attribute1 : Use in home page sidebar(yes/no)
if it is yes show the below attribute.
Attribute2 : Browse image
I want to add attribute2 based on the attribute1. Only when the Use in Home Page Sidebar is enabled , my new attribute will be shown below of the current. I.e., it will be a dependent attribute. Does somebody know the script for adding dependent attributes in Magento?
Previously i added custom attributes by
$this->startSetup();
$this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'use_home_page_side_bar', array(
'group' => 'General',
'input' => 'select',
'type' => 'int',
'label' => 'Use in Home Page Sidebar',
'backend' => '',
'source' => 'eav/entity_attribute_source_boolean',
'visible' => true,
'required' => false,
'visible_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$this->endSetup();
Like this script, is there any script for adding dependent attributes?
If you are working on admin forms, then a class exists for automatically hiding elements when the value of fields change.
Below is an example which shows field dependency.
$form = new Varien_Data_Form();
$form->addField('yesno', 'select', array(
'label' => $this->__('Yes or No?'),
'values' => Mage::model('adminhtml/system_config_source_yesnocustom')
->toOptionArray(),
));
$form->addField('custom_value', text, array(
'label' => $this->__('Other'),
));
// Append dependency javascript
$this->setChild('form_after', $this->getLayout()
->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap('yesno', 'yesno')
->addFieldMap('custom_value', 'custom_value')
->addFieldDependence('custom_value', 'yesno', 2) // 2 = 'Specified'
);
You need to map every field name to an element ID. You can add as many field mappings and field dependencies in this way as you wish.
I have created simple category attribute dependency by adding new input renderer for attribute. It is working this way:
You have several attributes:
– my_attribute
– my_attribute_text
– my_attribute_select
Note that they all start from my_attribute.
First attribute has boolean type. When it is set to true – other attributes that start from my_attribute is visible.
Source - https://github.com/elpas0/category_dependence
Description - http://nwdthemes.com/2015/02/20/magento-category-attributes-dependency/

Magento - How can I set a diffrent phtml for a block in an observer?

Here is what I'm trying to do:
I need to add a tab on category edit page on the backend (admin panel).
I add it from an Observer file this way:
$tabs = $observer->getEvent()->getTabs();
$tabs->addTab('features', array(
'label' => Mage::helper('catalog')->__('Related Pages'),
'content' => '',
));
The problem is that I do not know how to properly populate the 'content' attribute so I was thinking of getting the "Content" block and manually assigning to it a different phtml file.
Can it be done?
Thanks in advance.
Try this.
$tabs->addTab('features', array(
'label' => Mage::helper('catalog')->__('Related Pages'),
'content' => Mage::app()->getLayout()->createBlock('[module]/[block]')->setTemplate('path/to/template.phtml')->toHtml(),
));
So you need to create you own block that will be rendered by the path/to/template.phtml template.
If you don't need any logic in your template you can skip the creation of the block and use adminhtml/template. Something like this.
$tabs->addTab('features', array(
'label' => Mage::helper('catalog')->__('Related Pages'),
'content' => Mage::app()->getLayout()->createBlock('adminhtml/template')->setTemplate('path/to/template.phtml')->toHtml(),
));

Yii CGridView customizing column head sort icons and row links

I am dealing with the CGridView widget in Yii. I've customized most of it, but can't seem to customize the icons that appear when you click on the column headers to sort the data. (little arrows that point either up or down depending on the sort order) Also, the icons are completely gone after adding in the 'columns' option. A portion of the code in my view is below:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager' => array('cssFile' => '/css/myCss.css'),
'cssFile' => '/css/myCss.css',
'summaryText' => 'Showing {start} - {end} of {count} data rows.',
'htmlOptions' => array('id' => 'grid'),
'columns' => array(
array(
'name' => 'name',
'value' => '$data->name',
),
array(
'name' => 'description',
'value' => '$data->description',
),
array(
'name' => 'date',
'value' => '$data->date',
),
),
));
?>
Yii's documentation isn't clear at all on this and there doesn't seem to be anyone (that I could find) that also has this issue.
->Also, a related question:
How would I make each row an anchor link? I need each row to be a link to view the details about the clicked row. I know that cgridview provides view, edit, and delete links at the end of the row if told to, but is it possible to get the entire row to be a single anchor link? I know how to do this manually in html, but don't know how to do this inside cgridview.
If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid.
In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:
'columns'=>array(
...
array(
'name'=>'name',
'value'=>'CHtml::link($data->name, "#myAnchor")',
'type'=>'html'
),
...
)
I am not sure what version of Yii you're working on, but let's try this code
<?php
'columns' => array(
array(
...
'type' => 'html',
'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),

How to create new button in Yiibooster TBGridview

I'm using Yiibooster and the TbGridView to show some results. I'm also using the following code to provide smart looking icons to a view, update and delete link.
array(
'htmlOptions' => array('nowrap'=>'nowrap'),
'class'=>'bootstrap.widgets.TbButtonColumn',
'viewButtonUrl'=>'Yii::app()->createUrl("/item/view", array("id"=>$data["id"], "sector" => $data["sector"]["slug"],"title" => $data["slug"]))',
'updateButtonUrl'=>'Yii::app()->createUrl("/item/update", array("id"=>$data["id"]))',
'deleteButtonUrl'=>null,
)
What I'd like to do is basically be able to show another button in there or in replace of the delete button. I'm just unsure how (or where specifically) I need to code the values for the this button.
I'm currently looking at the TbButtonColumn.php file and tried just adding a button just to see if it would work it didn't.
What would be the correct process to to do this?
Thanks in advance
Jonny
There is a buttons parameter for additional buttons, it is in docs od CButtonColumns, here is sample from link:
array(
'class'=>'CButtonColumn',
// Template to set order of buttons
'template' => '{postview} {preview}',
// Buttons config
'buttons' => array(
'postview' => array(
'label' => '...', // text label of the button
'url' => '...', // the PHP expression for generating the URL of the button
'imageUrl' => '...', // image URL of the button. If not set or false, a text link is used
'options' => array(...), // HTML options for the button tag
'click' => '...', // a JS function to be invoked when the button is clicked
),
'preview' => array(
// Another button config
),
),
),
NOTE: This is example for CButtonColumn but TbButtonColumn is a subclass of CButtonColumn, so everything applies to both.

Categories