How to add a note for an attribute in magento? - magento

I have created a new product attribute in Magento using the admin panel. But I can't find where to put a note for that attribute (that is the text that should display below the input field as extra info about it.)
Am I missing something, or is this not possible to implement in the admin panel?
This is an example of how a note on an attribute would look like:
I am using Magento 1.7 CE.

It's not possible through the admin Panel.
By the way, you really should add your attributes programatically. (if you database crash, your done for).
What you need is to modify the column "note" of the eav_attribute table.
You can modify it with the updateAttribute() command in an upgrade script. Example :
$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'color', 'note','my comment');

hmm this might be a bit late, but anyway, I had a similar problem today and solved it in the following intuitive way:
first my problem:
howto get in the extended-search-page the attributes in the a custom order?
for this I've found something here:
http://www.magentocommerce.com/boards/viewthread/11782/
-- they tell:
U might use the custom not used field ´note´ from the mysql table: ´eav_attribute´
therefor you can change in
app\code\core\Mage\CatalogSearch\Model\Advanced.php
the order-by
i.e.
from: ->setOrder('main_table.attribute_id', 'asc')
to: ->setOrder('main_table.note', 'asc')
But then, you still have the prob, how to edit the things properly, without edit anything directly by in a mysql-client; from now on, I have had your problem, my solution:
Model: get/set
in app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
grep: class Mage_Eav_Model_Entity_Attribute_Abstract ex
add: best after search: "n getName"
/**
* Get attribute note
*
* #return string
*/
public function getNote()
{
return $this->_getData('note');
}
/**
* Set attribute note
*
* #param string $name
* #return Mage_Eav_Model_Entity_Attribute_Abstract
*/
public function setNote($note)
{
return $this->setData('note', $note);
}
Controler: set
in app/code/core/Mage/Adminhtml/controllers/Catalog/Product/AttributeController.php
(o.k. this is a shortcut, I think you can add some attributes to "note_text" somewhere, but I have no plan from magento)
search for: "default value" and extend:
from:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
}
to:
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
$data['note'] = $this->getRequest()->getParam('note_text');
}
View:
in ./app/code/core/Mage/Eav/Block/Adminhtml/Attribute/Edit/Main/Abstract.php
after:
$fieldset->addField('default_value_text', 'text', array(
add:
$fieldset->addField('note_text', 'text', array(
'name' => 'note_text',
'label' => Mage::helper('eav')->__('Note Value'),
'title' => Mage::helper('eav')->__('Note Value'),
'value' => $attributeObject->getDefaultValue(),
));
finally I've initiallized the note-field in the mysql table by:
update eav_attribute set note=lpad(attribute_id,10,'0000000000') where attribute_id not in(84,100);
where attributes with the id 84 and 100 have had already some notes.

Related

How to change default prefix "Create/Update" that comes with CRUD?

How can i change, prefix that comes with CRUD operation ie CREATE / UPDATE in laravel NOVA?
And if i can change them, how can i apply translations on them?
prefix "Create" is shown in image.
There is no need to install packages or edit core files 😱. You can easily change this in the language files. Assuming that your app's locale is set to en, the translation file can be found in /resources/lang/vendor/nova/en.json.
In this file, go to the entry you need to edit, in this case
"Create :resource": "Create :resource"
and change the value to what you want it to be. For example, changing it to
"Create :resource": "Create a new :resource"
will turn the text into
Note: You don't need to change core files, You can also do this following way
"Create :resource": "Create :resource"
to "Create :resource": "Create a new :resource"
lets say resource name is post. then the new heading will become Create a new Post You can change heading the way you like from here.
And it will update your heading, without updating core files. #Govert Verschuur provided this solution.
Other way around is -> Default name "Create/Update" is provided in Panel.php file.
/**
* Get the default panel name for a create panel.
*
* #param \Laravel\Nova\Resource $resource
* #return string
*/
public static function defaultNameForCreate(Resource $resource)
{
return __('Create :resource', [
'resource' => $resource->singularLabel(),
]);
}
/**
* Get the default panel name for the update panel.
*
* #param \Laravel\Nova\Resource $resource
* #return string
*/
public static function defaultNameForUpdate(Resource $resource)
{
return __('Update :resource', [
'resource' => $resource->singularLabel(),
]);
}
Change the String here and boom, it will solve your issue.
And as far as translation is concerned is already applied, You just need to provide translation in your en.json or any other file.
Note:
Translation will only be applied on final string, so Add "Create" / "Update" with your label name and if label is not set then with your default name.

Magento, Upgrade 1.7 query failed in custom module with sales_flat_quote_item_option table

I have written a custom module in Magento who add a row in the sales_flat_quote_item_option table.
I use the addOption method with an array as parameter on a quote_item object.
Then I run $quoteItem->save();
With version 1.4 of Magento, everything works like a charm. I tried to upgrade Magento to 1.7 version but my module seems to not working anymore.
After couple try to debug, I figure that the insert query in sales_flat_quote_item_option is not launch at all (according to the query log file).
So I wrote a simple query to insert data and my module is working now.
Maybe someone has been already facing this kind of issue ? I need to do it as clean as possible.
Let me share the code who fails :
public function assignDocumentToQuoteItem(Mage_Sales_Model_Quote_Item $quoteItem, $documentid)
{
if(is_numeric($documentid) && $documentid > 0)
{
/** #var Mage_Catalog_Model_Product */
$product = $quoteItem->getProduct();
$quoteItem->addOption(array(
'product_id' => $product->getId(),
'product' => $product,
'code' => 'documentid',
'value' => $documentid));
$quoteItem->save();
return true;
}
throw new Exception(__METHOD__.' - Document id has to be a numeric value.');
}
Works fine with Magento 1.4 but not with 1.7 any idea here ?
Thank you very much !

Magento - Set product attribute to use default values

This has been asked many times before but with no working answer.
I have multiple stores and some attributes have been overridden. I want to change these attributes to 'use default value' with a script.
Here is an image showing store views and 'use default value' checkboxes
http://dl.dropbox.com/u/3209649/storeviews-and-defaultvalues.png (not allowed to post images yet)
In app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php setData() is used with false for the second argument when 'Use Default Value' has been selected for any attributes.
/**
* Check "Use Default Value" checkboxes values
*/
if ($useDefaults = $this->getRequest()->getPost('use_default')) {
foreach ($useDefaults as $attributeCode) {
$product->setData($attributeCode, false);
}
}
The following code attempts to set the 'name' attribute to 'use default values' for product 1 in store 3 using the same method.
require_once '../app/Mage.php';
Mage::app(3);
$product = Mage::getModel('catalog/product')->load(1);
$product->setData('name', false); # as used in ProductController.php
$product->save();
Using
$product->setData('name', 'anything');
correctly sets the 'name' attribute to 'anything' but false does not set it to 'use default value'
'Use Default Value' is not stored anywhere in the database so within the controller for the admin interface there must be another procedure that deletes the attribute row?
Related Links here -> http://pastebin.com/raw.php?i=j7fwu9H6
(not allowed to post links yet either)
This doesn't work because you need the current store being the admin store for this kind of operation.
To make a specific store view use the default value for a given attribute:
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$product = Mage::getModel('catalog/product')
->load($product_id) // in your case: 1
->setStoreId($store_id) // in your case: 3
->setData($attr, false) // in your case: 'name'
->save();

Magento extra role field

I have added an extra field in the admin_role table in magento called limit_products. I have also added an extra field into the magento backend, and using the admin_permissions_role_prepare_save event I set this field to either 1 or 0, using the function below. However, it doesn't seem to want to save this field at all. Any ideas what I am doing wrong? I even tried setting the field in RoleController.php (where the other fields are set), but no luck. Anyone know what I'm doing wrong?
public function adminPermissionsRolePrepareSave(Varien_Event_Observer $observer) {
$role = $observer->getEvent()->getObject();
$request = $observer->getEvent()->getRequest();
//fb($request);
$role->setLimitProducts((bool)$request->getPost('limit_products', false));
return $this;
}
EDIT: I just realised I forgot to mention that $request->getPost('limit_products', false); does return the right value, it's just the $role->setLimitProducts(); isn't saving it. Also when I do $role->getLimitProducts(); it does return the right value.

Magento - add field to sales_flat_quote

I have created a module which requires an additional field to be added to the sales_flat_quote table / model.
Everything appears to work fine in my install script and the new field can be seen in the database.
When retrieving a quote object and storing a value against my new field the value never gets recorded to the database. The save method doesnt product an error or exception but the value never sticks.
If it makes a difference, I am trying to save the value to the quote from an observer, during the checkout process.
Here is the code I am using in my install script:
$setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
$setup->getConnection()->addColumn(
$setup->getTable('sales_flat_quote'),
'test_attribute',
'text NULL DEFAULT NULL'
);
$setup->addAttribute('quote', 'test_attribute', array('type' => 'text', 'visible' => false));
Am I missing something obvious here?
Don't know why you create this object $setup = new Mage_Sales_Model_Mysql4_Setup('sales_setup');
If you look for example into \app\code\core\Mage\Sales\sql\sales_setup\mysql4-upgrade-1.3.99-1.4.0.0.php, you will see:
/* #var $installer Mage_Sales_Model_Entity_Setup */
$installer = $this;
$installer->startSetup();
/* Include code from mysql4-upgrade-0.9.38-0.9.39.php */
$installer->getConnection()->addColumn($installer->getTable('sales_flat_quote_item'),
'store_id', 'smallint(5) unsigned default null AFTER `product_id`');
And of course you should delete cache, change your module version in config.xml to number bigger than you have for you module in core_resource table.

Resources