Magento add attribute on top of the group - magento

I have magento 1.8. and i want to add product attribute in product. I can do all of that but when I want to add specific attribute to be located on top of others (sorting order in back office) in group. How can i do this?
$this->addAttribute('catalog_product', 'my_subtitle', array(
'attribute_model' => NULL,
'backend' => NULL,
'type' => 'text',
'table' => NULL,
'frontend' => NULL,
'input' => 'text',
'label' => 'Subtitle',
'frontend_class' => NULL,
'source' => NULL,
'required' => '0',
'user_defined' => true,
'default' => NULL,
'unique' => '0',
'note' => NULL,
'input_renderer' => NULL,
'visible' => '1',
'searchable' => '1',
'filterable' => '1',
'comparable' => '1',
'visible_on_front' => '1',
'is_html_allowed_on_front' => '1',
'is_used_for_price_rules' => '0',
'filterable_in_search' => '0',
'used_in_product_listing' => '1',
'used_for_sort_by' => '0',
'is_configurable' => '0',
'visible_in_advanced_search' => '0',
'position' => '0',
'wysiwyg_enabled' => '0',
'used_for_promo_rules' => '0',
'apply_to' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,));

Try adding:
'sort_order' => -1, // Or 0
Ie.
$this->addAttribute('catalog_product', 'my_subtitle', array(
'sort_order' => -1, // Or 0
...
)
);
This way, your new attribute should be displayed before the rest, as per the sort_order.

Related

Codeigniter insert_batch fail weird array becomes string

So now I am passing a json and here is the result of echo '<pre>' . var_export($data, true) . '</pre>';:
array (
0 =>
array (
'booking_id' => 99,
'item_type' => '67',
'sales_item_seq' => '1',
'package_item_id' => '0',
'package_item_seq' => '0',
'package_group' => '0',
'package_group_rowspan' => '0',
'package_group_subdata_rowspan' => '0',
'channel_id' => '380',
'name_of_channel_programme' => '123',
'schedule_from' => '0000-00-00 00:00:00',
'schedule_to' => '0000-00-00 23:59:59',
'no_of_unit' => '123.00',
'exposure_inside_per_unit' => '',
'exposure_duration' => '123',
'advertising_offier' => '0.00',
'special_discount' => '0',
'net' => '0.00',
't_n_c' => '',
'remark' => '',
'status' => '1',
'create_datetime' => '2018-11-14 17:00:33',
'update_datetime' => '2018-11-14 17:00:33',
'channel' => '2',
'package_name' => '',
'sale_item_name' => 'hello',
'cat_id' => '1',
'aftersales_type' => '',
'typing_guide' => '',
'position' => '',
'platform_des' => 'hello',
'nature_des' => 'hello',
'unit_des' => 'Account',
),
...
...
...
9 =>
array (
'booking_id' => 99,
'item_type' => '59',
'sales_item_seq' => '1',
'package_item_id' => '0',
'package_item_seq' => '0',
'package_group' => '0',
'package_group_rowspan' => '0',
'package_group_subdata_rowspan' => '0',
'channel_id' => '0',
'name_of_channel_programme' => 'N/A',
'schedule_from' => '0000-00-00 00:00:00',
'schedule_to' => '0000-00-00 00:00:00',
'no_of_unit' => '123.00',
'exposure_inside_per_unit' => 'N/A',
'exposure_duration' => 'N/A',
'advertising_offier' => '1000.00',
'special_discount' => '100',
'net' => '0.00',
't_n_c' => '',
'remark' => '',
'status' => '1',
'create_datetime' => '2018-11-14 17:00:33',
'update_datetime' => '2018-11-14 17:00:33',
'channel' => '',
'package_name' => '',
'sale_item_name' => 'Service Charge',
'cat_id' => '7',
'aftersales_type' => '',
'typing_guide' => 'N/A',
'position' => 'N/A',
'platform_des' => 'N/A',
'nature_des' => 'Operations',
'unit_des' => 'Campaign',
),
10 =>
array (
'booking_id' => 99,
'item_type' => '0',
'sales_item_seq' => '0',
'package_item_id' => '161',
'package_item_seq' => '0',
'package_group' => '1',
'package_group_rowspan' => '6',
'package_group_subdata_rowspan' => '1',
'channel_id' => '39',
'name_of_channel_programme' => 'hello',
'schedule_from' => '0000-00-00 00:00:00',
'schedule_to' => '0000-00-00 23:59:59',
'no_of_unit' => '1.00',
'exposure_inside_per_unit' => '0',
'exposure_duration' => '',
'advertising_offier' => '180000.00',
'special_discount' => '100',
'net' => '0.00',
't_n_c' => '',
'remark' => '',
'status' => '1',
'create_datetime' => '2018-11-14 17:00:33',
'update_datetime' => '2018-11-14 17:00:33',
'channel' => 'Catch',
'package_name' => 'hello',
'sale_item_name' => 'hello',
'cat_id' => '1',
'aftersales_type' => '',
'typing_guide' => 'Name of Programme',
'position' => '',
'platform_des' => 'hello',
'nature_des' => 'Live',
'unit_des' => 'Live Segment',
'package_id' => '28',
),
...
...
...
'unit_des' => 'Video',
'package_id' => '28',
),
)
It looks fine to me when I view it on an online viewer. and after $this->db->insert_batch('table_name',$data) here is the error returned saying there is Array in the code.
Error Number: 1064
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near 'Array' at line 1
And I can find it at the end of the followings (think this is the raw output of the insert_batch):
INSERT INTO `table_name` () VALUES
(
'0.00',
'',
100,
'1',
'2',
'380',
'2018-11-14 17:06:46',
'123',
'',
'67',
'123',
'Access Right',
'0.00',
'123.00',
'0',
'0',
'0',
'0',
'0',
'',
'hello',
'',
'',
'hello',
'1',
'0000-00-00 00:00:00',
'0000-00-00 23:59:59',
'0',
'1',
'',
'',
'Account',
'2018-11-14 17:06:46'
)
,
...
...
...
(
'1000.00',
'',
100,
'7',
'',
'0',
'2018-11-14 17:06:46',
'N/A',
'N/A',
'59',
'N/A',
'Operations',
'0.00',
'123.00',
'0',
'0',
'0',
'0',
'0',
'',
'N/A',
'N/A',
'',
'Service Charge',
'1',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'100',
'1',
'',
'N/A',
'Campaign',
'2018-11-14 17:06:46'
)
,
array
I have no idea why there becomes an array for all the elements from 10 th onwards.
Please let me know if you require more information. Thank you!
You're array indexes doesn't match. 1 - 9 doesn't have package_id
You may add this to ensure all array has package_id index:
array_walk($array, function(&$val){ if (!isset($val['package_id'])) $val['package_id'] = null; });

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

Resources