Saving custom attribute value for category in magento - php

I have been trying to create an attribute for the categories in magento at the backend through programmatically. So, I followed steps in http://www.hesselbom.net/magento-custom-attributes-with-selectbox and it works perfectly and even I can able to save the selected values. Whereas, if I try creating a text box attribute, the values is not getting saved. Can anyone guide me how to do this?
Following is my code.
$installer->addAttribute('catalog_category', 'custom_textfield', array(
'type' => 'varchar',
'label' => 'Custom field',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => TRUE,
'required' => FALSE,
'default' => ''
));
$attributeId = $installer->getAttributeId($entityTypeId, 'custom_textfield');
I have also updated the version in the config file accordingly.

Please try with it work for me
$installer->addAttribute('catalog_category', 'custom_textfield', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Custom field ',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->addAttribute('catalog_category', 'custom_textfield', array(
'group' => 'General',
'type' => 'varchar',//can be int, varchar, decimal, text, datetime
'backend' => '',
'frontend_input' => '',
'frontend' => '',
'label' => 'Custom Field',
'input' => 'image', //text, textarea, select, file, image, multilselect
'class' => '',
'source' => '[source model for attribute here]',//this is necessary for select and multilelect, for the rest leave it blank
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
'visible' => true,
'frontend_class' => '',
'required' => false,//or true
'user_defined' => true,
'default' => '',
'position' => 100,//any number will do
));
This should do the trick. :)

After a long search, I found it. Below is the way to create and save attribute value at the admin panel.
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('catalog_category', 'length_waterline_custom', array(
'group' => 'General',
'input' => 'text',
'type' => 'varchar',
'label' => 'Length of Waterline',
'backend' => '',
'visible' => 1,
'required' => false,
'user_defined' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
$eavConfig = Mage::getSingleton('eav/config');

Related

magento2 created custom product attribute but missing in mass update

I've created an attribute programmatically like this
$eavSetup->addAttribute(
Product::ENTITY,
self::mpn,
[
'type' => 'text',
'backend' => '',
'frontend' => '',
'label' => 'mpn',
'input' => '',
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => true,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => '',
]
);
However when I try to select multiple products and mass update this attribute, it doesn't show up.
When I recreated it from the backend it shows up.
Could anyone let me know what option I'm missing so that it appears correctly to perform mass updates on it?
This happens in Magento 2.2.6, 2.2.7 and 2.3 when I tested it.
I found your problem because you are missing input type.
Please change this:
'input' => ''
to any specific type. Example:
'input' => 'text'
Regards

how to pre-fill select box in typo3 backend

First of all excuse my bad english.
I got a problem with my select-field in the BE. I would like to prefill (preselect) all of the available items.
Code in ext_tables.php:
'teilnehmer' => array(
'exclude' => 0,
'label' => 'LLL:EXT:kiwanisext/Resources/Private/Language/locallang_db.xlf:tx_kiwanisext_domain_model_veranstaltung.teilnehmer',
'config' => array(
'type' => 'select',
'foreign_table' => 'fe_users',
'MM' => 'tx_kiwanisext_veranstaltung_user_mm',
'size' => 10,
'autoSizeMax' => 30,
'maxitems' => 9999,
'multiple' => 0,
'wizards' => array(
'_PADDING' => 1,
'_VERTICAL' => 1,
'edit' => array(
'type' => 'popup',
'title' => 'Edit',
'script' => 'wizard_edit.php',
'icon' => 'edit2.gif',
'popup_onlyOpenIfSelected' => 1,
'JSopenParams' => 'height=350,width=580,status=0,menubar=0,scrollbars=1',
),
'add' => Array(
'type' => 'script',
'title' => 'Create new',
'icon' => 'add.gif',
'params' => array(
'table' => 'fe_users',
'pid' => '###CURRENT_PID###',
'setValue' => 'prepend'
),
'script' => 'wizard_add.php',
),
),
),
),
I found nothing helpful in the documentation.
Any hint, tip or help will be much appreciated!
Its not possible to do that with plain TCA config, afaik. You can however define a default value wich will be selected (if none is defines, 1st item will be selected).
'default' => 'myValue'
But to preselect multiple values at once, you have to use JavaScript I guess.
This code worked for me in typo3 6.2. I have a selectbox filled with database records.
I want the records with ID's 1 ans 2 to be preselected in the selectbox:
'thematique' => array(
'exclude' => 0,
'label' => 'LLL:EXT:dk_actus/locallang_db.xml:tx_dkactus_thematique',
'config' => array(
'type' => 'select',
'foreign_table' => 'tx_dkactus_thematique',
'foreign_table_where' => 'ORDER BY tx_dkactus_thematique.uid',
'size' => 10,
'minitems' => 0,
'maxitems' => 99,
'default' => '1,2',
),
),

Zend framework 2 form select element set required false

I have a select element as follows and I want to make it non required field. But I am unable to do so. It gives me error "Value is required and can't be empty"
$this->add(array(
'name' => 'civil_status',
'type' => 'Select',
'attributes' => array(
'id' => 'civil_status',
'class' => 'form-control',
),
'options' => array(
'empty_option' => 'Civil status',
'value_options' => array(
'married' => 'Married',
'single' => 'Single',
'other' => 'other',
),
)
));
I have set the validation as follows
$this->inputFilter->add($factory->createInput(array(
'name' => 'civil_status',
'required' => FALSE,
'allow_empty' => TRUE,
'filters' => array(
array('name' => 'StripTags'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => '2',
'max' => '255',
),
),
),
)));
I tried to remove required from input filter as above and even more I have tried to remove required validation from the controller too as follows. But nothing seams to work. Please let me know if you guys know to fix this issue.
$form->getInputFilter()->get("civil_status")->setRequired(FALSE);
$form->getInputFilter()->get("civil_status")->setAllowEmpty(TRUE);
Select has build in InArray validator you dont need to use StringLength here or filters you only need to use 'required' => false which should work.
$this->inputFilter->add($factory->createInput(array(
'name' => 'civil_status',
'required' => false,
)));
I know it might be strange question but did you add your InputFilter to your Form before you hit $form->IsValid() ?

How add time to datepicker in backend magento

I'am using magento 1.7.2 and I want to add date attribute with time which saves date as well as time in database for that product.
i had tried this code to add new attribute using mysql-setup file in my module.
$setup->addAttribute('catalog_product', 'new_date', array(
'group' => 'General',
'input' => 'date',
'type' => 'datetime',
'label' => 'New Date',
'backend' => 'eav/entity_attribute_backend_datetime',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 1,
'comparable' => 1,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
but this gives me only date to select not time.
Please help me.
Thanks.
Try this for backend (any admin panel form):
$fieldset->addField('your_column_name', 'date',array(
'name' => 'image_link', /* should match with your table column name where the data should be inserted */
'time' => true,
'class' => 'required-entry',
'required' => true,
'format' => $this->escDates(),
'label' => Mage::helper('featuredpopup')->__('From:'),
'image' => $this->getSkinUrl('images/grid-cal.gif')
));
in format u can write directly 'yyyy-MM-dd HH:mm:ss' or one more method like
private function escDates() {
return 'yyyy-MM-dd HH:mm:ss';
}
Hopes this gives u an idea.
Try these (works on Magento 1.8):
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'test_date_time', array(
'input' => 'datetime',
'type' => 'datetime',
'time' => true,
'label' => 'Date&Time',
'visible' => true,
'required' => false,
'user_defined' => true,
'visible_on_front' => true,
'backend' => 'eav/entity_attribute_backend_time_created',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
));
Hello check app/code/local/Magik/Popup/Block/Adminhtml/Popup/Edit/Tab/Form.php
Add below code
$dateFormatIso=Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$fieldset->addField("text_name", "date", array(
"name" => "text_name",
"label" => Mage::helper("modelname")->__("Start Date"),
"title" => Mage::helper("modelname")->__("Start Date"),
"image" => $this->getSkinUrl('images/grid-cal.gif'),
"input_format" => Varien_Date::DATE_INTERNAL_FORMAT,
"format" => $dateFormatIso,
"time" => false,
"value" => "textstart",
));
when creating a custom attribute you just need to add
'input'=> 'datetime' instead of 'input'=> 'date'

make magento custom attribute filterable

Is there a way to make a custom magento product attribute filterable through a setup file and resource file?
I can create the attribute, I can even set the group it goes into but w/out manually going into the admin and adjusting the filterable option on the attribute, I can't get it to be set to filterable (especially filterable - I've tried w/ true/false and 0,1,2). I've tried adjust about every option that makes sense.
ie:
app/code/local/Company/Module/Model/Resource/Eav/Mysql4/Setup.php
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
'attributes' => array(
'attribute_name' => array(
'group' => 'Attribute Set Group',
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Attribute Label',
'input' => 'select',
'class' => '',
'source' => 'eav/entity_attribu
'global' => Mage_Catalog_Model_
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => false,
'searchable' => true,
'filterable' => 1,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => true,
'used_in_product_listing' => true,
'used_for_sort_by' => true,
'unique' => false,
),
),
),
);
}
app/code/local/Company/Module/Model/sql/module_setup/mysql4-install-0.1.0.php
$this->installEntities();
You can add an attribute in the following way:
module_name\sql\machinesearch_setup
Create one SQL setup file like this in your module.
<?php
$installer = $this;
$data= array (
'attribute_set' => 'Default',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'label' => 'Year',
'input' => 'multiselect',
'type' => 'text',
'default_value_text' => 'varchar',
'unique' => false,
'required' => false,
'visible' => true,
'searchable'=> true,
'visible_in_advanced_search' => true,
'html_allowed_on_front' => true,
'comparable' => false,
'backend_type' => 'varchar',
'backend' => 'eav/entity_attribute_backend_array',
'group' => 'General',
'user_defined' => true,
);
$installer->addAttribute('catalog_product','mmy_year',$data);
$data= array
(
'attribute_set' => 'Default',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'label' => 'Make',
'input' => 'multiselect',
'type' => 'text',
'default_value_text' => 'varchar',
'unique'=> false,
'required'=> false,
'visible' => true,
'searchable'=> true,
'visible_in_advanced_search'=> true,
'html_allowed_on_front' => true,
'comparable'=> false,
'backend_type' => 'varchar',
'backend'=> 'eav/entity_attribute_backend_array',
'group' => 'General',
'user_defined'=> true,
);
$installer->addAttribute('catalog_product','mmy_make',$data);
$data= array (
'attribute_set' => 'Default',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'label' => 'Model',
'input' => 'multiselect',
'type' => 'text',
'default_value_text' => 'varchar',
'unique' => false,
'required' => false,
'visible' => true,
'searchable' => true,
'visible_in_advanced_search' => true,
'html_allowed_on_front' => true,
'comparable' => false,
'backend_type' => 'varchar',
'backend' => 'eav/entity_attribute_backend_array',
'group' => 'General',
'user_defined' => true,
);
$installer->addAttribute('catalog_product','mmy_model',$data);
$installer->endSetup();
?>

Categories