Skip to content

2.3.4: Update "Custom Layout Update" doesn't work #27942

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

Closed
Krapulat opened this issue Apr 22, 2020 · 52 comments
Closed

2.3.4: Update "Custom Layout Update" doesn't work #27942

Krapulat opened this issue Apr 22, 2020 · 52 comments
Assignees
Labels
Issue: needs update Additional information is require, waiting for response not-confirmed Use for Issue that was closed during confirmation Reported on 2.3.4 Indicates original Magento version for the Issue report.

Comments

@Krapulat
Copy link

Krapulat commented Apr 22, 2020

Preconditions (*)

Magento 2.3.4

Steps to reproduce (*)

Add the file: app/design/frontend/VENDOR/THEME/Magento_Catalog/layout/catalog_category_view_selectable_[ID]_name.xml

Edit the category in the backend to use the Specifc Layout (Catalog->Categories->Design> Custom Layout Update->select "name" )
Save. I get the message "You saved the category."
Clear cache
Refresh category frontend and category backend

Expected result (*)

Specific layout changes from the file should be applied

Actual result (*)

Changes have no effect.
Also in the category backend, Custom Layout Update appears as "No update". So the change is not saved without any error.

@m2-assistant
Copy link

m2-assistant bot commented Apr 22, 2020

Hi @Krapulat. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@Krapulat do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Apr 22, 2020
@Krapulat
Copy link
Author

@magento give me 2.4-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @Krapulat. Thank you for your request. I'm working on Magento 2.4-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @Krapulat, here is your Magento instance.
Admin access: https://i-27942-2-4-develop.instances.magento-community.engineering/admin_bfb0
Login: 280cabec Password: 1c814b467a41
Instance will be terminated in up to 3 hours.

@Krapulat
Copy link
Author

The instance can't help because I need to create the file app/design/frontend/VENDOR/THEME/Magento_Catalog/layout/catalog_category_view_selectable_[ID]_name.xml

@msyhr
Copy link

msyhr commented Apr 27, 2020

I can confirm this is occurring as well. It looks like the data is just not being stored on save.

See catalog_category_entity_varchar

@Krapulat

FYI you can manually add the data into the table and the logic will work on the frontend.

I did it with a data patch

` $table = $this->moduleDataSetup->getTable('catalog_category_entity_varchar');

    $connection = $this->moduleDataSetup->getConnection();

    $data = [
        'attribute_id' => YOUR_EAV_ATTRIBUTE_ID,
        'store_id' => 0,
        'row_id' => CATEGORY_ID,
        'value' => 'XmlFileName'

    ];

    $connection->insert($table, $data);

`

hacky but it worked for the time being.

@Krapulat
Copy link
Author

@msyhr I haven't been able to obtain the attribute_id for "Custom Layout Update"

@msyhr
Copy link

msyhr commented Apr 29, 2020

@msyhr I haven't been able to obtain the attribute_id for "Custom Layout Update"

@Krapulat The attribute is called custom_layout_update_file There are two (one for product pages, one for category pages). You can get the ID's from the actual table (eav_attribute).

SELECT * FROM eav_attribute WHERE attribute_code = 'custom_layout_update_file'

You want the ID of the one that has the source model of Magento\Catalog\Model\Category\Attribute\Source\LayoutUpdate

@silversil
Copy link

I can override succesfully a layout for CMS page,

---> but for CATEGORY it don't works:

  1. Created file "catalog_category_view_selectable_495_uomo.xml" (where "495" is the category ID and "uomo" is the name of the file)
  2. located here app/design/frontend/VENDOR/THEME/Magento_Catalog/layout/
  3. on backend I can't see any choice on Custom Layout Update, no way.. tryed to switch to production, developer, flushed caches.

@Krapulat
Copy link
Author

@msyhr I've tried but it doesn't work. I inserted directly to the database.

@msyhr
Copy link

msyhr commented Apr 30, 2020

@msyhr I've tried but it doesn't work. I inserted directly to the database.

@Krapulat make sure you're using the correct value for the DB entry (not the entire filename)

For instance, my file catalog_category_view_selectable_1869_OverstockNote.xml

Ends up looking like this in the DB (catalog_category_entity_varchar).

image

@Krapulat
Copy link
Author

Krapulat commented May 1, 2020

@msyhr

SELECT * FROM eav_attribute WHERE attribute_code = 'custom_layout_update_file'; => attribute_id=815 for "Magento\Catalog\Model\Category\Attribute\Backend\LayoutUpdate"

I have the file catalog_category_view_selectable_26_sub.xml and I see "sub" in the category backend for option "Custom Layout Update". So the file is ok.

And this is the result for "select * from catalog_category_entity_varchar where attribute_id='815';":
+----------+--------------+----------+-----------+-------+
| value_id | attribute_id | store_id | entity_id | value |
+----------+--------------+----------+-----------+-------+
| 13185 | 815 | 0 | 26 | sub |
+----------+--------------+----------+-----------+-------+

But still doesn't work...

@snowgy920
Copy link

@Krapulat I have same problem. Did you get any chance to solve this issue?

@silversil
Copy link

Me too.. Anyone found a solution for this BUG?

How it's possible all these bugs on a platform?!

@john-dhm
Copy link

john-dhm commented May 26, 2020

I'm facing the same issue and I can't find the answer. This seems like a big deal and it would be nice if someone had the time to look further into this issue.

Summary of the issue
Custom Layout Update dropdown in backend doesn't show custom layout.

Information on your environment
Magento v2.3.5-p1
PHP 7.3.18

Steps to reproduce
Created a file called "catalog_category_view_selectable_20_WomenCategoryRemoveTitle.xml" under Magento_Catalog in child theme directory with the following content:
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="page.wrapper"> <referenceBlock name="breadcrumbs" remove="true"/> <referenceBlock name="page.main.title" remove="true"/> </referenceContainer> </body> </page>

Expected and actual results
Expected to be able to select the layout in the Custom Layout Update dropdown for category Women (ID:20).

@kestraly
Copy link

+1 on this issue fresh install

@ghost
Copy link

ghost commented Jul 12, 2020

Same issue.

If I place a cms_page_view_selectable_home_LayeredNavigation.xml file under /vendor/magento/theme-frontend-luma/Magento_Catalog/layout/ -- the Custom Layout Update works. But if I place it under my custom theme (with luma as the parent theme), then it doesn't show up in Magento admin.

The select dropdown remains empty. Only "No update" visible. The file isn't recognized when I put it only in my custom theme based on parent theme Luma. I can only get it to work by putting the file in the /vendor/ folder ...

@AndrewJGriff
Copy link

I have exactly the same issue. @john-dhm are you using the Athlete 2 theme?
My setup is exactly the same as @john-dhm and I have been trying everything to get it to work.

@john-dhm
Copy link

@AndrewJGriff It's not theme related.

@AndrewJGriff
Copy link

@john-dhm Did you find a solution? I found that if I set 'Enable single-store mode' to NO, then the Custom Layout Update works, but if i switch this to 'YES' so I have single store mode enabled, then I cannot select the file name in the admin screen.

@Blatant
Copy link

Blatant commented Aug 6, 2020

I am having the same problem, for me with CMS pages.
I'm trying to update alyout of the home CMS Page, I created file :
\[VENDOR]\[THEME]\Magento_Cms\layout\\cms_page_view_selectable_home_NewTest.xml
Flushed the Cache
Edited the "Homepage" home CMS Page, I can see "NewTest" in the selector and when I select it and Save it does save (revisiting CMS page editor later shows the value as saved) however no layout update is being performed, cleared and flushed cache.
Pretty Straight forward proof of concept :

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="main.content">
            <block name="mytest"
                   template="Magento_Theme::test.phtml"
                   before="-" />
        </referenceContainer>
    </body>
</page>

@Appmerce Try placing the xml file in Magento_Cms or Magento_Theme. I placed test files in botrh locations nad after Flush they did appear in Admin.
@silversil Can you elaborate On how you got it to work for CMS page?
I.m running 2.3.5-p1 BTW.

@Chris-ISN
Copy link

If you have the "Custom Layout Update" not showing in the dropdown issue, try changing your scope in the admin panel to the store view (eg change scope from "All Store Views" to your store view.

We just had this issue and changing the scope to store view made the missing custom layout update appear in the dropdown (for category updates).

@Blatant
Copy link

Blatant commented Aug 7, 2020

Hi @Chris-ISN , thanks forthe reply! I don't have that issue (indeed the CM Page was already assigned to a specific view). I am working on CMS Pages not categories (test to follow!) and got the item to appear in the dropdown no problem, it just does not get applied. #28750 describes my issue better (though its not unrelated) so I cross-posted there too.

I spotted @silversil mention "I can override succesfully a layout for CMS page," so I thought I'd ask here too.

FYI, I'm going to have a crack at debugging this, this morning. feels like it's something like presenting the update handle properly. Like the update is there in the layout but the handle that is called does not match the one in the xml/database or summin. Gonna see if the update XML is actually in the layout first and work from there... Of course will share in both posts what/if I find

@Blatant
Copy link

Blatant commented Aug 7, 2020

Ok, I have debugged and actually solved my issue. I redact my vote on this issue as "not related" now to Layout Updates appearing in admin pertaining to Categories.

FYI, Just in case it's relevant my solution was that it was all to do with an omission on my part inthe xml file.
Once I debugged what update Handles where being called I was able to correct my XML and it worked fine....
\Vendor\Theme\Magento_Cms\layout\cms_page_view_selectable_home_NewTest.xml :

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <update handle="cms_page_view_selectable_home_NewTest"/>
    <referenceContainer name="main.content">
            <block name="mytest"
                   template="Magento_Theme::test.phtml"
                   before="-" />
    </referenceContainer>
</page>

I was basically missing the update declaration with the right handle name. FYI the handle name is the full name of your file!

@amorr
Copy link

amorr commented Aug 11, 2020

same problem,i want to custom home page layout,but failed. I can only write data directly to the database. custom_layout_update_xml or layout_update_xml field.

@Blatant
Copy link

Blatant commented Aug 11, 2020

I think what I realized in debugging is that it does not parse the layout XML in the file when the page is loaded (after a cache flush) but rather, when you save the page it checks if the file exists, parses the layout then and if it's good saves it to the database, it then, on parsing the page on the frontend loads the XML from the database.

Not sure if I'm correct in that, there were alot of hoops while I was debugging a few days ago, I'll be doing some more custom page layouts today so I'll take care to debug it, I think the key is to resave the page if you change the selectable xml file.

Did you have examples @amorr ? It will help the guys above....

@amorr
Copy link

amorr commented Aug 11, 2020

my environment
Magento v2.3.5-p1
PHP 7.2.24

i can find my custom layout name in Custom Layout Update, but after save page. nothing changed. I confirmed that my code in xml file is available when in the default.xml.

None of the above is working for me.

For now, my solution is write to cms_page table custom_layout_update_xml or layout_update_xml field like

<referenceContainer name="main.content"> <block name="mytest" template="Magento_Theme::test.phtml" before="-" /> </referenceContainer>

I think this was the working mechanism prior to version 2.3.4

@Blatant
Copy link

Blatant commented Aug 11, 2020

Strange, that's exactly the same Magento version as me, I'm on php 7.3. Actually running it on Ubuntu 18 and Windows 10 (dev machines) and it works ok for me.

On review it seems XML is not saved to the database at all on my working version. just layout_update_selected so I guess the XML isn't transported to the DB on Page save (it might still be getting validated?).

I assume your layout file contains the prerequisite <?xml />and` elements?

Did you add the update handle declaration as well?

You're correct prior to 2.3.4 the Custom XML field would save xml as text into this column in the database. I would not rely on injecting XML into that field however as it appears they've simply forgotten to delete it (or not deleted it for compatibility).

Still injecting the XML into the DB works for you so happy days! But I can confirm I was able to get the "new method" working with a well formed xml file and an update handle (with the file in the Magento_Cms theme sub folder)

@Blatant
Copy link

Blatant commented Aug 16, 2020

Hey @amorr,

I had the exact same thing, specifically overriding the homepage! Like exactly the same (the layout worked on /home but not on the homepage proper). I have a fix/workaround for that!

I did quite a deep debug of the Layout system, starting at the controllers and logging what happens when the updates are loaded in layout. WHat I found is that the controller in the CMS module for the homepage is not the same as any CMS page, it's not cms_page_view but cms_index_index. you'll note that the controller path is part of the file name. (I'm not that happy that I had to debug to this conclusion from the layout up, it seems obvious in retrospect but I just skipped the fact that the files all begin with module_controller_action)

The workaround is to duplicate your file cms_page_view_selectable_home_customHome.xml file in the same folder with the name cms_index_index_selectable_home_customHome.xml and it'll start working.

It's a real kludgy workaround but basically on the admin your selecting the option cozz of the existence of the cms_page_view file. and when you goto /home it uses that file by looking for :
<module>_<controller>_<action>_selectable_<pageuri>_<OptionName>.xml
When you hit the homepage that pattern above maps to `cms_index_index_selectable__.xml and thats what Magento looks for. everything else about the page object is the same, the CMS Page URI, the options saved in the DB thats loaded and all that, but becasue the homepage proper uses a different controller id doesn't find the "actual" XML file, but it will find your craftily placed and named duplicate!

SO in summary, copy your layout.xml file for your home page, and rename it replacing _page_view with _index_index, remember to update BOTH files! and you will still need to obvs select the right option in the admin.

I've yet to report this bug to Magento, but will do next wek after go live!

@amorr
Copy link

amorr commented Aug 17, 2020

@Blatant you're right, It's work!

@BreezeMaxWeb-NS
Copy link

BreezeMaxWeb-NS commented Aug 21, 2020

Magento 2.3.5-p2

Trying to set a custom layout on a CMS page but it's not working because I have 2 themes, one global and one for a specific website. Anything I add to the theme for the specific website gets ignored but it shows up if I add it in the theme set to global.

There's no way to switch store views on the CMS Pages controller either.

Note: This still doesn't work since it only loads the current theme on page load, so you need an empty XML in the default theme and the actual implementation in the website theme.

@Blatant
Copy link

Blatant commented Aug 28, 2020

Yea it's a bit fiddly, the blank parent theme xml and the actual override would work. I think when I looked at the code the dropdown to set it on the CMS page is theme aware, so if you assign your page to Store 2 which is using "ChildTheme" and save when it reloads it will load your child theme specific XML for setting it, but then you have 2 identical CMS pages, one for the stores using the child and one for the stores using the parent.

Worth noting though, apart from the "getting options from file names and loading xml from file on layout it functions just like the old "Layout Update XML" box on the CMS page. That too is not settable by child theme, you would need to dupe your page to have 2 different (one blank) layout update XML fields.

Defo needs some improvement, including allowing the layout on the CMS page that is being used for the homepage without duping files, and as you mention more concise method of applying update at theme/store level.

@snowgy920
Copy link

@john-dhm Did you get any chance to solve the issue? Would you share your solution please?

@kestraly
Copy link

Still having to add these to the database for categories. Even if these are added to the database, they do not show in the dropdown menu as selected. Standard M2 install on 2.3.5-p2

@ghost ghost added Issue: ready for confirmation and removed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed labels Oct 21, 2020
@magento-engcom-team magento-engcom-team added the Reported on 2.3.4 Indicates original Magento version for the Issue report. label Nov 13, 2020
@abdulmalik422
Copy link

What about Category page. its not working also on category? Any workaround for this.

@Blatant
Copy link

Blatant commented Dec 2, 2020

I got it working for Category Pages...

I've implemented a custom layout on the parent/default theme in the directory [theme_dir]/Magento_Catalog/layout/, with the filename catalog_category_view_selectable_28_OverrideCat28.xml, "OverrideCat28" appears in the override dropdown and it obviously affects Category ID 28.

The xml file is complex but the crucial elements are :

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

    <update handle="catalog_category_view"/>

    <!-- head, refernceBlock, referenceContainer, container, block, ect --> 

</page>

If I recall its not to FPC friendly either so hit the caches after applying or editing

M2.3.4-p1

@m2-assistant
Copy link

m2-assistant bot commented Feb 8, 2021

Hi @engcom-Alfa. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Alfa
Copy link
Contributor

Hi @Krapulat . Thank you for your report!

Unfortunately, we are not able to reproduce the issue on fresh 2.4-develop. Everything works as expected.

Manual testing scenario:

  1. Add the file: app/design/frontend/VENDOR/THEME/Magento_Catalog/layout/catalog_category_view_selectable_[ID]_name.xml
    For example: delete breadcrumbs from category page;
<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="breadcrumbs" remove="true" />
    </body>
</page>
  1. Create a category in admin;
  2. Go to Storefront -> category;

Actual Result: ✔️ Breadcrumb is displayed
2021-02-08_16-33

  1. Go to Admin -> Catalog -> Categories and choose created before category;
  2. Go to the Design tab and select name from the Custom Layout Update dropdown;
  3. Save settings;
  4. Clear cache;
  5. Go to Storefront -> category;

Actual Result: ✔️ Specific layout changes are applied (Breadcrumb is removed)
2021-02-08_16-36

@Krapulat Are you able to reproduce this issue on clean 2.4-develop?
Thanks!

@engcom-Alfa engcom-Alfa added the Issue: needs update Additional information is require, waiting for response label Feb 8, 2021
@pixel-paul
Copy link

I do not understand why, when it is clear this issue is related to Magento 2.3.4, you are trying reproduce this issue using the 2.4-develop branch. Perhaps try and reproduce using 2.3.6?

@pixel-paul
Copy link

@engcom-Alfa thanks. So how do you make a pull request for the 2.3.7 branch to be released in Q2 of this year? (Ref:https://devdocs.magento.com/guides/v2.3/release-notes/open-source-2-3-6.html)

@engcom-Alfa
Copy link
Contributor

@pixel-paul Information from Magentp-DevBlog.
The latest Magento version as of now is 2.4.1 and moving forward we will be focusing on the 2.4 and 2.5 release lines. As a result of such an approach, we will be parking the delivery of bug fixes or features for the 2.3 line and only delivering security fixes to it.

@pixel-paul
Copy link

@engcom-Alfa thank you for this additional information, I can see that there has been a major shift in the way Magento 2 is now released. Is there a plan to create an LTS version of Magento 2?

@engcom-Alfa
Copy link
Contributor

@pixel-paul I'm sorry, but I don't have this information.

@engcom-Alfa
Copy link
Contributor

Hi @Krapulat we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@engcom-Alfa engcom-Alfa added the not-confirmed Use for Issue that was closed during confirmation label Feb 24, 2021
@CenterSites
Copy link

Check if you don't have a space after the extension .xml this fixed it for me
catalog_category_view_selectable_4_SpecialPriceOnly.xml[space]

@DegrizNet
Copy link

DegrizNet commented Mar 16, 2021 via email

@roemerdlr
Copy link

Magento 2.3.3
The Custom Layout Update is being added in: vendor/magento/module-catalog/Controller/Category/View.php line 293
In my case was wrong date saved in catalog_category_entity_datetime
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: needs update Additional information is require, waiting for response not-confirmed Use for Issue that was closed during confirmation Reported on 2.3.4 Indicates original Magento version for the Issue report.
Projects
None yet
Development

No branches or pull requests