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 cannot save Category/Custom Design on store level #4032

Closed
wants to merge 1 commit into from

Conversation

forfin
Copy link

@forfin forfin commented Jun 6, 2024

Description (*)

When I debug why some data I just save didn't show on Catalog -> Manage Categories -> (Choose non-default Store View) -> Custom Design -> (Some custom EAV attrs)

I found that the text actually save on db. But when it query back, it query for both default store (store_id is 0) and target store and later cause issue.

Magento logic seems to rely on order of values query from db, like first match item will be a value for default store while second item will be a value for target store.

Here is example table catalog_category_entity_text produce by query of _getLoadAttributesSelect function

value_id entity_type_id attribute_id store_id entity_id value
76494 3 244 1 837 targetStoreValueIJustSave
76549 3 244 0 837 NULL <- It show this value instead of targetStoreValueIJustSave
* 3 * * 837 *

Then on Magento admin page, It just show nothing on field I just save.

This PR will make sure if value_id mixed up, Magento still can show a correct value for the store.

Related Pull Requests

Manual testing scenarios (*)

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)
  • Add yourself to contributors list

@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Jun 6, 2024
@kiatng
Copy link
Contributor

kiatng commented Jun 7, 2024

I'm not sure how to replicate this bug. My steps:

  1. Multi-store backend > Catalog > Manage Categories > Choose Store View (any store) > select a subcategory > Custom Design tab > Custom Layout Update
  2. In the text area, input <!-- test -->
  3. Click button Save Category
  4. After it's save, I can see the saved value <!-- test --> in the Custom Layout Update.
  5. Choose Store View to another store, the value in the Custom Layout Update is correct for the store.

With the steps above, the saving and rendering of category attribute works as expected in a multi-store setting.

Please provide your detail steps to show the bug. Including how your custom attributes are added and rendered in backend.

@forfin
Copy link
Author

forfin commented Jun 7, 2024

Custom attribute create by this script

$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$installer->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'bestseller_top_section', [
    'group' => 'Custom Design',
    'label' => 'Best Seller & Top Section',
    'input' => 'textarea',
    'type' => 'text',
    'default' => '',
    'required' => 0,
    'visible_on_front' => 1,
    'filterable' => 0,
    'searchable' => 0,
    'comparable' => 0,
    'user_defined' => 0,
    'is_configurable' => 1,
    'is_visible' => 1,
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'note' => '',
]);
$installer->endSetup();

To reproduce issue value_id of table catalog_category_entity_text for store 0 must greater than value_id of target store.

You can go to db and change value_id directly.
Or in theory after you add new attr, Try to save value on store level first than save value on default store later.

@kiatng
Copy link
Contributor

kiatng commented Jun 7, 2024

I added your custom attribute, I cannot replicate the bug:

  1. I added the custom attribute with the script
  2. I saved the custom attribute Best Seller & Top Section at store level first:
    image
  3. I saved the custom attribute at default:
    image
  4. I go back to api store, I can see value store api best #27
  5. I go to another store, I see the default value: all store best #27
    image

I deleted the custom attribute, repeated the above with same result. Conclusion is that everything works as expected. If I miss something, please elaborate.

@luigifab
Copy link
Contributor

luigifab commented Jun 7, 2024

Perhaps it's #2964?

@forfin
Copy link
Author

forfin commented Jun 8, 2024

Here video how to reproduce: https://streamable.com/lej637

  1. clone https://github.com/OpenMage/magento-lts
  2. git checkout v19.5.3
  3. ddev config
  4. ddev start
  5. ddev exec php n98-magerun.phar admin:user:create admin test@email.com admin first last Administrators
  6. go to http://magento-lts.ddev.site/admin login with admin:admin
  7. create new store view
  8. go to Manage Categories
  9. change to newly created store
  10. change Custom Layout Update to store value, It show store value as expected
  11. change to default store
  12. change Custom Layout Update to default value, It show default value as expected
  13. change to newly created store again
  14. Custom Layout Update now showing default value. It should be store value
  15. And now default value cannot be change from this store

@forfin
Copy link
Author

forfin commented Jun 9, 2024

Hey, I just have a time to look it more closely.

It seems it happen only v19
And it already have a same fix in #2966

So I could just add patch manually to my v19 variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Relates to Mage_Catalog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants