Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed setting of source_model when adding new attribute and for multiselect. #1293

Merged
merged 4 commits into from
Nov 24, 2022

Conversation

kiatng
Copy link
Contributor

@kiatng kiatng commented Oct 31, 2020

Description (*)

This PR addresses 2 issues.

Custom source_model

When adding a new attribute in which the input type is select, the source model is always set to eav/entity_attribute_source_table irregardless if source_model has a value or not.

Partially fix issue #1096

This PR will set source_model when the attribute model is saved, but it cannot do anything for attributes which were updated directly in the database.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Fix the issue with empty source_models for (multi-)selects #1096, on attribute save, will set the source_model to eav/entity_attribute_source_table if it's empty.

Manual testing scenarios (*)

To replicate custom source_model

  1. Add a new customer attribute called Nationality:
/** @var Mage_Customer_Model_Attribute $attribute */
$attribute = Mage::getModel('customer/attribute');
$attribute->addData([
    'entity_type_id' => 1,
    'attribute_code' => 'nationality',
    'backend_type' => 'varchar',
    'frontend_input' => 'select',
    'frontend_label' => 'Nationality',
    'source_model' => 'customer/entity_address_attribute_source_country',
    'is_user_defined' => 1,
    'is_system' => 0,
    'data_model'  => 'customer/attribute_data_select'
]);
$attribute->save();
  1. Now load the attribute:
$attribute = Mage::getModel('customer/attribute')->loadByCode(1, 'nationality');
echo $attribute->getSourceModel(); // output is "eav/entity_attribute_source_table"

The output is eav/entity_attribute_source_table but we expect customer/entity_address_attribute_source_country.

Partially fix issue #1096

  1. Reference https://magento.stackexchange.com/questions/58377, we can replicate the error
$manufacturerAttribute = Mage::getModel('catalog/entity_attribute')
    ->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'manufacturer');
$values = $manufacturerAttribute->getSource()->getAllOptions();

Source model "" not found for attribute "manufacturer"

#0 /home/web/public_html/magento/ccs/dev/app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php(494): Mage::exception('Mage_Eav', 'Source model ""...')

  1. Apply this PR, then save the attribute in backend > Catalog > Attributes > Manage Attributes > select "manufacturer" > click Save Attribute button. $values is now;
 array(1) {
  [0] => array(2) {
    ["label"] => string(0) ""
    ["value"] => string(0) ""
  }
}

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

luigifab
luigifab previously approved these changes May 4, 2021
Co-authored-by: sv3n <github-sr@hotmail.com>
@fballiano fballiano merged commit 73b970d into OpenMage:1.9.4.x Nov 24, 2022
@github-actions
Copy link
Contributor

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 73b970d. ± Comparison against base commit c4c2102.

@kiatng kiatng deleted the eav_custom_source_model branch February 27, 2023 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Eav Relates to Mage_Eav
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix the issue with empty source_models for (multi-)selects
4 participants