Displaying index instead of "__name__label__ *" - php

Using sonata admin Bundle And I have A form to Define the A "Question" model, I have an attribute "choices" which is a collection :
->add('choices', 'collection',
array('allow_add' => true,'allow_delete' => true, 'block_name' => false,
'delete_empty' => true, 'label' => 'choices'))
When I add a choice The label wrote in his top is "_name__label__*", I need to change it to the choice index, anyone found a solution for this ? thank you

Related

Display collection form on page load in Sonata Admin Bundle

Is there an option or a known way to display collection form on page load instead of clicking on "add" button in order to display it ?
I trigger a click event on page load but its not the expected behavior..
Any help would be much appreciated.
Alright, I achieved what I wanted by setting a default collection array on my form field, each Entity object in array imbricates a form, since I needed to display 3 form on page load I instanciated 3 entity, quite logic when I think of it now but a dedicated option could be nice though.
->add('details', CollectionType::class, [
'data' => [new OfferDetail(), new OfferDetail(), new OfferDetail()],
'label' => false,
'required' => true,
'type_options' => [
'delete' => false,
],
], [
'edit' => 'inline',
'inline' => 'table'
])

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.

Symfony : How to create Multiple RadioBoxes using the form Builder

I'm working on a new project where i was asked to create this type of form :
I have created an entity with a json_array attribute that stores this form
configuration.
example :
{
"DescenteCde" : 0 // checked radiobutton is "Aucun"
"WebShopPC" : 1 // checked radiobutton is "Faible"
}
I want to know the easiest way to generate this type of form using the symfony form builder.
I found a solution for my problem. Actually, Symfony framework provides us with A Collection Type that takes a array as a parameter and then we specify the different options and values/
$ImpactApplicationFormBuilder->add('***Configuration***',CollectionType::class, array(
'entry_type' => ChoiceType::class,
'entry_options' => array(
'choices' => array(
'Aucun' => 0,
'Faible' => 1,
'Moyen' => 2,
'Fort'=> 3
),
'multiple' => false,
"expanded" => true ,
),
));
Configuration attibute is of type array so in the form the different keys of your array will be rendered with the given options you provided.
Your result will look like this :
Hope this help anybody with the same problem

How to add new field to product attributes in magento?

i want to send manufacturer email when order is made . For that i want to add email address of manufacturer in Manufacturer product attribute ? How to achieve this ?
I'm gonna assume that you are asking how to do it in code? Anyway, just build a small module with an install script (tutorials all over the web), and make the setup script look something like this:
$installer = $this;
$installer->startSetup();
// check if the attribute exists
if (Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product','calculated_sold')->getId() !== NULL) {
$installer->removeAttribute('catalog_product', 'calculated_sold');
}
// not anymore, that's for sure!
// Note! For product attributes the XML set class needs to be "Mage_Catalog_Model_Resource_Setup"
// instead of "Mage_Customer_Model_Entity_Setup" as you would usually go with.
$installer->addAttribute('catalog_product','calculated_sold', array (
'type' => 'decimal',
'label' => 'Calculated sold',
'input' => 'price', // for filtering to work only certain input types allowed
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'searchable' => true,
'filterable' => true,
'visible' => false,
'required' => false,
'visible_in_advanced_search' => true,
'used_in_product_listing' => true,
'used_for_sort_by' => true,
'apply_to' => 'configurable', // yeah!
));
$installer->endSetup();
This example adds an attribute to keep track of how many items are sold, but it will give you an idea of how to change it for your own needs.

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/

Categories