Hey guys im using the installer in my module to add a new EAV product attribute to the Default attribute set. So far its working great, but there are 2 little things that bother me.
public function getDefaultEntities(){
return array(
'catalog_product' => array(
'entity_model' => 'catalog/product',
'attribute_model' => 'catalog/resource_eav_attribute',
'table' => 'catalog/product',
'additional_attribute_table' => 'catalog/eav_attribute',
'entity_attribute_collection' => 'catalog/product_attribute_collection',
'attributes' => array(
'disable_sale' => array(
'group' => 'General',
'label' => 'Disable Sale',
'type' => 'int',
'input' => 'select',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'is_visible_on_front' => true,
'used_in_product_listing' => true,
)
)
)
);
}
I want my attribute set to be visible on product details page and catalog listing per default.
'is_visible_on_front' => true,
'used_in_product_listing' => true,
The problem is that both values are not set to be visible.
What am i doing wrong?
I haven't done this with attributes per-se, but try both 'integers' 1 AND 'string' "1" in your code and see if it works.
is_visible_on_front change to visible_on_front and then check.
Found the answer here at stackoverflow:
Magento module setup/installer script
Setup class should extend from
Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
Now the installer is aware of the additional attributes and its working like a charme.
Related
I created a custom entity with an image field. But I can not display the alt and title fields.
Here is my code:
$fields['main_img'] = BaseFieldDefinition::create('image')
->setLabel(t('Main image of the hardware'))
->setSettings([
'file_directory' => 'hardware',
'file_extensions' => 'png jpg jpeg',
])
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'image',
'weight' => -30,
))
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
Could you tell me how to display the alt and title fields of my image and maybe someone knows where the documentation is for doing that because I can not find it?
Thank you all
I loaded one of my node field definitions with $node->getFieldDefinitions():
I believe you can try something like this:
->setDisplayOptions('form', array(
'label' => 'above',
'type' => 'image_image',
'weight' => -30,
'settings' => [
'alt_field' => TRUE,
'alt_field_required' => TRUE, //optional
'title_field' => TRUE,
'title_field_required' => TRUE, //optional
],
))
Thank Dmytro.
I feel a little stupid but it's life.
It was enough to add 'alt_field_required' => FALSE and 'title_field' => TRUE in setSettings.
But as title and alt is displayed that when we download an image I thought it did not work.
A day of lost!
I am adding attribute by updating sql script, like this,
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer_address', 'group_id', array(
'label' => 'Address group',
'visible' => true,
'required' => false,
'type' => 'int',
'input' => 'select',
'source' => 'address_group/address_attribute_source_group',
'user_defined' => 1,
'position' => 100
));
.
.
.
$installer->endSetup();
I am unable to understand what is meant by following line, I am unable to find any explanation about it
'source' => 'address_group/address_attribute_source_group',
I am unable to comment on your post. Trying to understand if you have copied this code from somewhere. From your code I understand that you want to add a "Customer Address Attribute" named as "customer_address"
'source' => 'address_group/address_attribute_source_group'
The implication of the above is the path. You should have a folder/file path as below:
/app/code/local/Address/Group/Model/Address/Attribute/Source/Group.php
Group.php:
class Address_Group_Model_Address_Attribute_Source_Group ...
Since, this attribute is of TYPE => "SELECT", you should be having the options array in this file "Group.php"
Options Array should be something very similar to:
public function toOptionsArray() {
return array(
array(
'label' => '',
'value' => ''
),
array(
'label' => Yes,
'value' => 1
),
array(
'label' => No,
'value' => 0
)
);
}
Let me know if you got it!
Happy to Help!
Happy Coding...
It points to the class that provides options for the attribute. As attribute uses select input it requires options to be provided. This class is created by calling Mage::getModel() and passing the value of source to it. To find the class you need to find node models/address_group in config.xml files of the available modules. This will provide class prefix. Next what comes after slash is added to that prefix in order to create class name. So in this case it will resolve to something like Company_AddressGroupModule_Model_Address_Attribute_Source_Group. This class need to implement toOptionsArray method that returns an array in the following format:
array(
array('value' => 'option_value', 'label' => 'option_label'),
...
);
I created a new module and I managed to list all the orders from the shop.
I also added a button (with this code).
$link= Mage::helper('adminhtml')->getUrl('adminhtml/order/sync/') .'id/$entity_id';
$this->addColumn('action_edit', array(
'header' => $this->helper('catalog')->__('Action'),
'width' => 15,
'sortable' => false,
'filter' => false,
'type' => 'action',
'actions' => array(
array(
'url' => $link,
'caption' => $this->helper('catalog')->__('Sync'),
),
)
));
I really don't know how to assign an action to this button. What I should create in my custom module ? A new controller?
I need to display something or get some data when I click this button...
thank you very much
I think you should write
public function YourActionNameAction()
{
}
in your Module controller file
I have a customer attribute which I setup using this script (I've only pasted part of it, the part related to the attribute)
$setup->addAttribute('customer', 'age', array(
'label' => 'Age',
'type' => 'int',
'input' => 'select',
'user_defined' => true,
'source' => 'eav/entity_attribute_source_table',
'visible' => true,
'required' => false,
'visible_on_front' => true
));
I would like to set the front end label of the attribute to "How old are you?" but keep the Admin label to "Age". How could I do this?
Thanks in advance,
Ok I managed after looking into magento
$labels = array();
$labels[0] = 'Age';//default store label
$labels[1] = 'Label for store with id 1';
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'age');
$oAttribute->setData('store_labels', $labels);
$oAttribute->save();
This did the trick.
Hope it helps someone else.
I can not really find a satisfying answer to the following question:
What would be the best practice for a module to add a new product attribute to all attribute_sets (and possibly at a certain location).
All approaches I can find seem to refer to adding a new attribute to just one attribute set.
There is a magento way for it
Example:
$installer->addAttribute('catalog_product', 'test_me', array(
'label' => 'test Me',
'input' => 'textarea',
'type' => 'text',
'class' => '',
'global' => true,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'apply_to' => 'simple,configurable',
'visible_on_front' => true,
'is_configurable' => false,
'wysiwyg_enabled' => true,
'used_in_product_listing' => true,
'is_html_allowed_on_front' => true,
'group' => 'Config',
'sort_order' => 25
));
To add attribute to every attribute_set you need to set 'user_defined' = true and set 'group' = 'your_group_name'. If needed magento will add your group to every attribute set, and attach attribute to it.
Once you add an attribute you may assign it to one or all attribute sets, it isn't unique to the first set you assign it to. Does this answer your question?