Does Magento supports attribute with type date, not datetime - magento

I have problem with this format and I don't know does magento support it.
In code I have:
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'release_date', array(
'input' => 'date',
'type' => 'datetime',
'label' => 'Release date',
'backend' => 'eav/entity_attribute_backend_datetime',
'visible' => true,
'required' => false,
'user_defined' => true,
'visible_on_front' => true,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
));
How to change type to date? And how to make it dependable from Magento locale?

Here solution....
$data = array(
"attribute_code" => "date_attribute_3",
"frontend_input" => "date",
"default_value" => "06/19/2014",
"is_unique" => 0,
"is_global"=>"1",
"is_required" => 0,
"apply_to" => array("simple"),
"is_configurable" => 0,
"is_searchable" => 0,
"is_visible_in_advanced_search" => 0,
"is_comparable" => 0,
//"is_global" =>1,
"is_used_for_promo_rules" => 0,
"is_visible_on_front" => 0,
"used_in_product_listing" => 0,
"additional_fields" => array(),
"frontend_label" => array(array("store_id" => "0", "label" => "my date"))
);
$Attribute=Mage::getModel('catalog/product_attribute_api')->create($data);

Related

How to make custom attribute comparable(script)

Code in my Setup.php
'compare_field_freegift' =>
array (
'group' => 'Gift Product',
'label' => 'Gift Inside',
'type' => 'int',
'note' => 'Comparing product field(Yes/No)',
'input' => 'boolean',
'global'=> Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => 1,
'required' => 1,
'user_defined' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 1,//Comparable on Front-end
'apply_to' => 'simple,configurable,downloadable',
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'unique' => 0
)
All things are working fine except making field 'comparable'->True.
I tried with 'true','1' and 1 also but it is not coming.

Magento : set value from config to default attribute value

on the one hand i have field called min pricecf in my module configuration
on the other hand i have an attribute called min_price that i've created unsing install script
this is the attribute :
$setup->addAttribute('catalog_product', 'min_price', array(
'group' => 'Prices',
'input' => 'text',
'type' => 'decimal',
'label' => 'Min Price',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 0,
'default' => 'Here ????',
'comparable' => 1,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
what i wanna do is get the value from min pricecf to min_price and that value should be the default.

Magento 1.8: While adding new product attribute non of the frontend params are set to yes

This is code that I'm using to add new product attribute with frontend settings set to yes:
<?php
$installer = Mage::getResourceModel('catalog/setup','catalog_setup');
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $specCode, array(
'group' => $profileGroupName,
'sort_order' => 1,
'type' => 'varchar',
'backend' => '',
'frontend' => '',
'label' => $specLabel,
'note' => $specNote,
'input' => 'text',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'required' => true,
'user_defined' => true,
'default' => '',
'unique' => false,
'used_for_promo_rules' => true,
'searchable' => true,
'filterable' => true,
'comparable' => true,
'visible' => true,
'visible_on_front' => true,
'visible_in_advanced_search' => true,
'is_configurable' => false
));
...
Almost all the frontend settings are set to true but after installing them in backend I can see that this settings are set to no.
Regards,
Fixed. Code that is working bellow. Just keep to the $attr array key names for this method _prepareValues in this two classes Mage_Eav_Model_Entity_Setup, Mage_Catalog_Model_Resource_Setup. Second class inherits form the first one so if you want to add frontend setting your installer needs to be an object from the second class.
$installer = new Mage_Catalog_Model_Resource_Setup();
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $tradeCode, array(
'group' => $profileGroupName,
'sort_order' => 1,
'type' => 'varchar',
'input' => 'text',
'label' => $tradeLabel,
'note' => $tradeNote,
'required' => 1,
'unique' => 0,
'user_defined' => 1,
'default' => '',
# Additional attribute data - forntend
'frontend_input_renderer' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => 1,
'searchable' => 1,
'filterable' => 1,
'comparable' => 1,
'visible_on_front' => 1,
'wysiwyg_enabled' => 0,
'is_html_allowed_on_front' => 0,
'visible_in_advanced_search' => 1,
'filterable_in_search' => 1,
'used_in_product_listing' => 1,
'used_for_sort_by' => 1,
'apply_to' => '',
'position' => '',
'is_configurable' => 0,
'used_for_promo_rules' => 0,
));
...

How set a default Value with EAV AddAttribute

I want to set up an new attribute-set to my products in magento. This attribute should be type of selection from some options.
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'varchar',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => '',
#'default' => 1,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
));
How can I set optionthree to default value?
Had the same problem. My solution:
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'int',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => 'eav/entity_attribute_source_table',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'visible_in_advanced_search' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
));
Notice the different type (int instead of varchar) and source (eav/entity_attribute_source_table). This is the way Magento represents typical select attributes. Now you can set the default value like this:
$model = Mage::getModel('eav/entity_attribute')
->load($installer->getAttributeId('catalog_product', 'reserve'));
$model
->setDefaultValue($model->getSource()->getOptionId('Keine Angabe'))
->save();
Please use this script:-
$installer->addAttribute('catalog_product', 'reserve', array(
'backend_label' => 'Attribute Reserve',
'type' => 'varchar',
'input' => 'select',
#'backend' => 'eav/entity_attribute_source_boolean',
'frontend' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'unique' => false,
'visible_in_advanced_search' => false,
'option' => array(
'value' => array(
'optionone' => array( 'O' ),
'optiontwo' => array( 'P' ),
'optionthree' => array( 'Kein Angabe' ),
)
),
/**
* This will set the default values,
* as "array" data type is being used to set proper default value
*/
'default' => array(
'optionthree'
),
));
Hope it helps.
Navigate to Catalog >Manage Attributes to create new attribute and manage attribue stes to create new attribute set.
Please check the screenshot

Magento - attribute "input-type" checkbox

I have seen a similar question but I did not find an answer there :
How can I get my custom backend Magento Customer Checkbox Attribute to save my selection?
$installer->addAttribute('catalog_product', 'tip', array(
'group' => 'ISM',
'input' => 'checkbox',
'type' => 'int',
'label' => 'TIP',
'visible' => 1,
'source' => 'eav/entity_attribute_source_boolean',
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 0,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => 1,
'used_in_product_listing' => 0,
'is_html_allowed_on_front' => 1
));
I have created an attribute, but it doesn't save the value when I edit-save or create-save the product.
Use 'input' as int because you always store the value of the checkbox '0' or '1'. And for source you are already using core options boolean that is 0 or 1.

Resources