OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
863 stars 438 forks source link

Fixed cannot save Category/Custom Design on store level #4032

Closed forfin closed 3 weeks ago

forfin commented 3 weeks ago

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 (*)

kiatng commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

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 commented 3 weeks ago

Perhaps it's #2964?

forfin commented 3 weeks ago

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 commented 3 weeks ago

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 https://github.com/OpenMage/magento-lts/pull/2966

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