سؤال

I want to add a custom field in Attribute option in Manage Attribute Options menu in admin. Like value column beside the position column in admin. I have attached an image.

What I have done ... (Magento 1.8)

  1. created a new field in eav_attribute_option table named value after sort_order filed.

  2. changed magento\app\design\adminhtml\default\default\template\eav\attribute\options.phtml this file to show the Value column beside the Position column.

  3. changed getOptionValues() method in this file magento\app\code\core\Mage\Eav\Block\Adminhtml\Attribute\Edit\Options\Abstract.php to get data for my custom value column from database and show in admin side. It shows the default value of db in admin form.

    But when I want to save from admin panel the data doesn’t save in db.

I've been trying to find the model or controller that actually handles writing into the database to make sure my new field saves too.

Any help would be appreciated.

(I'd post an image to make you understand, but I can't since I need 10 points to be able to do it.)

هل كانت مفيدة؟

المحلول

Got it!

Update: Mage/Eav/Model/Resource/Entity/Attribute.php

in function: _saveOption(Mage_Core_Model_Abstract $object)

change:

$sortOrder = !empty($option[’order’][$optionId]) ? $option[’order’][$optionId] : 0; 
if (!$intOptionId) { 
$data = array( 
‘attribute_id’ => $object->getId(), 
‘sort_order’ => $sortOrder, 
); 
$adapter->insert($optionTable, $data); 
$intOptionId = $adapter->lastInsertId($optionTable); 
} else { 
$data = array(’sort_order’ => $sortOrder); 
$where = array(’option_id =?’ => $intOptionId); 
$adapter->update($optionTable, $data, $where); 
}

for this:

$sortOrder = !empty($option[’order’][$optionId]) ? $option[’order’][$optionId] : 0; 
$yourAttribute = (isset($option[’your_attr_field’]) && !empty($option[’your_attr_field’][$optionId])) ? $option[’your_attr_field’][$optionId] : ‘’; 
if (!$intOptionId) { 
$data = array( 
‘attribute_id’ => $object->getId(), 
‘sort_order’ => $sortOrder, 
‘your_attr_field’ => $yourAttribute 
); 
$adapter->insert($optionTable, $data); 
$intOptionId = $adapter->lastInsertId($optionTable); 
} else { 
$data = array(’sort_order’ => $sortOrder, ‘your_attr_field’ => $yourAttribute); 
$where = array(’option_id =?’ => $intOptionId); 
$adapter->update($optionTable, $data, $where); 
}

I could use some help in making all this changes 'the Magento way'

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top