Add new field in bundle item option in admin section - magento

I am new bie in magento.I am creating a bundle product from admin section .when I add the bundle item there is only the title field for information but I need to add one more field for the description like I created a bundle item for computers but I need to show description about it .
Please help .my requirement is to add new field for description along with the title in bundle item option.
any help will be appreciated .

you can add extra field to magento bundle products by editing app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml and few database changes.
EDIT:
first we have to add our custom field to catalog_product_option_type_value table in the database, using a instraller script
<?php
/* #var $installer Mage_Core_Model_Resource_Setup */
$installer = $this;
$installer->getConnection()
->addColumn($installer->getTable('catalog/product_option_type_value'), 'your_custom_field_name’, 'VARCHAR(128) NULL');
$installer->endSetup();
then copy the file in location app\design\adminhtml\default\default\template\catalog\product\edit\options\type\select.phtml
to app\design\adminhtml\default\default\template\companyname\catalog\product\edit\options\type\select.phtml. override the core file
Rewrite: ‘Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select’ block and replace constructor file in it by indicating our phtml file
public function __construct()
{
parent::__construct();
$this->setTemplate('companyname/catalog/product/edit/options/type/select.phtml');
$this->setCanEditPrice(true);
$this->setCanReadPrice(true);
}
open companyname/catalog/product/edit/options/type/select.phtml ile in OptionTemplateSelect varilable in tag we add the line: under 'sort order' field
'<th class="type-title"><?php echo Mage::helper('catalog')->__('your_custom_field_name') ?></th>'+
Add OptionTemplateSelectRow tag to the variable:
'<td><input type="text" class="input-text select-type-details" id="product_option_{{id}}_select_{{select_id}}_title" name="product[options][{{id}}][values][{{select_id}}][your_custom_field_name]" value="{{your_custom_field_name}}">{{checkboxScopeTitle}}</td>'+
now check in backend you should see the custom field by now. to make it required you can add required-entry class to above input field
now for retrieve values from database re-write the block:
Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option
In: 'getOptionValues()' method, cycle: foreach ($option->getValues() as $_value) {
add new key: 'your_custom_field_name' to the variable: $value and the value for it: $_value->getYourCustomField();
now custom field will appear in database
In order for the new attribute to appear on the frontend rewrite the class: Mage_Catalog_Block_Product_View_Options_Type_Select and add the newly added attribute to it. But be aware that depending on the type of Custom Options there different kinds of htmls generate.
please refer this article for more details

Related

Product type not updated for a custum attribute in magento

I have created a custom product type(test) successfully. Now i have added an attribute for catalog section in following manner.
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$data=array(
'type'=>'decimal',
'input'=>'text',
'label'=>'Rent Price',
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'is_required'=>'0',
'is_comparable'=>'0',
'is_searchable'=>'0',
'is_unique'=>'0',
'is_configurable'=>'0',
'use_defined'=>'0',
'apply_to' => array('test')
);
$attributeId = $setup->addAttribute('catalog_product','custum_price',$data);
Every thing is working perfectly but this attribute is showing in every products.I have just checked the table structure and found "catalog_eav_attribute" table is showing "Null" in apply_to field for this attribute.When i edit the value of this field manually and set the value "test",attribute starts showing in test type product.
But i dont want to update in this manner.Please guide me what i have done wrong.
Why are you using attribute type, use attribute set instead. Add the attribute to only the attribute set that is required. Create product using the attribute set and other product wont show this attribute. Check for magento attribute set if you are facing some issue

delete custom customer attribute in magento

I have created a custom attribute for customer in Magento.
I have accidentally set wrong type for my attribute.
Now I want to either modify this attribute or delete this one and then create new attribute.
Can any one tell me whether I can delete or modify custom attribute in magneto or not?
Thanks in advance.
You can create an upgrade script in one of your modules with this content:
$this->updateAttribute('customer', 'attribute_code_here', 'type', 'varchar'); //or any other type
Basically you can change any attribute from customers, categories & products like this;
$entityType = 'customer';//or catalog_category or catalog_product
$attributeCode = 'attribute_code_here';
$changeWhat = 'field_name_here';
$changeInto = 'new value here';
$this->updateAttribute($entityType, $attributeCode, $changeWhat, $changeInto);
To remove an attribute run this:
$this->removeAttribute('customer', 'attribute_code_here');
It follows the same rules as above.

Joomla - Custom Field doesn't show-up on Edit/Update

I've followed this Tutorial to add a custom field to the article content type and I was successful to make a new one with adding the following code:
In File : root/administrator/components/com_content/models/forms/article.xml
Code :
<field name="newText" type="editor" class="inputbox"
label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL"
description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"
filter="ContentHelper::filterText" buttons="true" />
In File : root/administrator/components/com_content/views/article/tmpl/edit.php
Code :
//Our new textbox
<div class="clr"></div>
<label>Article Text - New Text</label>
<div class="clr"></div>
<?php echo $this->form->getInput('newText'); ?>
and altered Database to add a new column for that new field.
ALTER TABLE 'j_content' ADD 'newText' VARCHAR( 255 ) NOT NULL;
On Article posting the data is successfully getting stored in Database.
The new custom field is visible when I'm posting a brand new article. But when I'm editing/updating the same new post, that newly added field is missing.
Is there a way to get this field even when we are editing the post/article.
Please, never overwrite core files or change the core database! This is not a good tutorial because it is not update-safe.
If you need additional fields for your content items, use a special core extension for this instead.
I recommend this one:
http://fieldsattach.com/. This method is update-safe.

magento update attribute1 = attribute2

I have 800 products in my magento store and im trying to change all SKUs, but keep the old ones to another text field. I have found a script that changes all SKUs at once but the problem is that first, i have to insert the text of attribute field SKU, to a new attribute field "old_sku".
How can i update old_sku = sku?
Thanks for any help!
If you do have some PHP knowledge, you could use it to create a PHP script that runs once and replaces all the attribute values. For example, i would do that like so:
<?php
// Magento initialization code; taken from here: http://www.ecomdev.org/2010/06/01/application-bootstrap-in-magento.html
require 'app/Mage.php';
if (!Mage::isInstalled()) {
echo "Application is not installed yet, please complete install wizard first.";
exit;
}
$initializationCode = 'admin';
$initializationType = 'store';
$scope = 'frontend';
Mage::app($initializationCode, $initializationType);
Mage::getConfig()->init();
Mage::getConfig()->loadEventObservers($scope);
Mage::app()->addEventArea($scope);
// Update products
try
{
$products = Mage::getModel('catalog/product')->getCollection();
foreach ($products as $product) {
$product->setOldSku($product->getSku())->save();
}
} catch (Exception $e)
{
echo "Something bad happened: {$e->getMessage()}. Shutting down...";
exit;
}
?>
Just create, let's say, a update_skus.php file within the root directory of your Magento setup (near the index.php file), fill it with the code i've provided and navigate your browser to that file (e. g. http://magento.local/update_skus.php). You should get all the products having their old_sku attribute set exactly to their sku attribute' values.
If you want to keep it really simple then the solution is
a) Add an attribute "old_sku"
b) Export all products
b) Change the CSV - Copy & paste the "sku" column values in "old_sku" and,
d) Import all products
that's it
Hope this helps!!!

Magento - Can't delete mulitple select value in the product admin

I created a new attribute (multiple select) with some values, everything works fine but when I want to delete all the selected values for a product, I get the message "The product attribute has been saved." but the values are still selected.
Notes:
I press Ctrl + Click to unselect the last value before I save.
I set the parameter Value Required of my attribute to No
If I save a product without any value selected yet, then no values get selected
My Indexes are properly refreshed
See below two screens, on the left the parameters of my attribute and on the right my multiple select.
I'm running out of ideas so thanks for your help.
This is a known (annoying) behaviour of the Magento Adminhtml forms.
The problem is that if no value is selected for the multiselect, no value for that attribute is posted when the form is submitted.
On the server side Magento then loads the model, sets all the posted attribute values on the model and saves it.
Because no value was posted the original value that was loaded on the model wasn't updated.
As a solution for attributes with a custom source model I tend to provide an empty option with a special option value (e.g. -1). That value must not be 0 or an empty string.
Then I specify a backend model for that attribute that checks for that special value in the _beforeSave() method. If it is found the backend model unsets the attribute on the model instance.
Here is an example:
Source Model:
class Your_Module_Model_Entity_Attribute_Source_Example
extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
const EMPTY = '-1';
public function getAllOptions()
$options = array(
array('value' => 1, 'label' => 'One'),
array('value' => 2, 'label' => 'Two'),
array('value' => 3, 'label' => 'Three')
);
if ($this->getAttribute()->getFrontendInput() === 'multiselect')
{
array_unshift($options, array('value' => self::EMPTY, 'label' => ''));
}
return $options;
}
}
Backend Model:
class Your_Module_Model_Entity_Attribute_Backend_Example
extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract
{
public function beforeSave($object)
{
$code = $this->getAttribute()->getAttributeCode();
$value = $object->getData($code);
if ($value == Your_Module_Model_Entity_Attribute_Source_Example::EMPTY)
{
$object->unsetData($code);
}
return parent::beforeSave($object);
}
}
If you find a better workaround please let me know.
There is a feature called <can_be_empty> you need to go to your system.xml and add this configuration into your file:
<can_be_empty>1</can_be_empty>
then inspect the element and remove the selected="selected" and hit save, now you can save the multi-select without any values.
Yes I found this a big pain in the bum too BUT it is an improvement on the previous bug which caused drop down attribute selections to be wiped if you tried to update attributes for several products at once.
Anyway, here is my what I do if I want to remove an option from products using a drop down attribute:
Go to Manage attributes
Click Manage Label Options
Add a temporary option to the list
Assign this new attribute option to all the products you want to
change
Delete the temporary attribute option
All solved.
Add a non existent option to html via chrome/firefox developer tool, select that option and save.
eg.
<option value="99999999">Click this to unselect option</option>
Just ran into this problem in Magento 1.7.0.2, my solution :
Use Firefox with Firebug
right-click the multiselect list, choose Inspect with Element and you'll see something like this at the bottom in Firebug :
XLarge
Double-click on selected, right-click, cut, no more selected attribute and just save the page.

Resources