Incorrect Magento 2 layouts override behavior - magento

Installed clear magento 2.3.2
Created simple custom theme which contain (theme.xml, registration.php and CustomTheme/Magento_Customer/layout/customer_account_create.xml).
Also I created a simple extension which add a custom field to customer accout create form (This extension also use customer_account_create.xml).
<body>
<referenceContainer name="form.additional.info">
<block class="CompanyName\ModuleName\Block\Test" name="test"
template="CompanyName_ModuleName::form/test.phtml"/>
</referenceContainer>
</body>
After that I got strange behavior:
If my CustomTheme/Magento_Customer/layout/customer_account_create.xml as is like original file from core, non-standard field is added to the form without problems from my custom extension.
But if I will modify my file CustomTheme/Magento_Customer/layout/customer_account_create.xml (for example I just added this string to remove minicart: `).
My non-standard field does not apply to the form
Everything looks as if I modify the layout for my needs in custom theme (delete some elements from the registration page), then all other custom extension that use this layout or reference to this layout will stop working.

https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html
I think you need to read a little more the concepts and process of development of your own custom theme before doing any big modifications, at the end you will have a really bad outcome and not sustainable code.

I figured out this issue.
Me helped this sections of the documentation
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-extend.html
https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/layouts/layout-override.html

Related

magento 2 custom phtml page

Having just got myself acquainted (enough) with Magento 1.9, and able to make the customisations required, I've been told that once it's out, we're moving to Magento v2.0.
Having found the differences in the file structure, I believe I can see where to place my code for the custom pages we use, but how can I add this page from my project to a static block for later use?
Previously, the method used was as follows (I realise this may not follow the best practise, but it worked):
Create element folder within theme or core templates directory.
eg. /app/design/frontend/<theme>/default/template/myelement/mypage.phtml
Add this page/element to a static block using the following in the content editor:
{{block type="<theme>/default" template="myelement/mypage.phtml"}}
This block can then be added to the category pages as required.
In Magento 2, I have tried what I believe to be required, which is replicating the file structure and adding phtml files to this, so the template file now resides in:
/app/code/<supplier>/<module>/view/frontend/templates/mypage.phtml
Adding to the content editor the following:
{{block type="<supplier>/<module>" template="mypage.phtml"}}
Unfortunately, this does not display the intended page (element). It doesn't display the calling "{{block" entry either, which usually happens when the line is invalid, so I can only assume that I'm missing something with the link to this template.
If anyone can offer some assistance with this, I would be most grateful.
EDIT:
Continued research on this has led me to the following assumptions:
Magento 2 requires more than just a new .phtml page, even for simple customizations.
I'm still missing something.....
Having gone through 3 different tutorials on creating new modules for Magento 2, each providing slightly different methods, but fundamentally being the same thing, I now have what I believe should be all the code elements to make a new .phtml template for display in a static block.
This has led to an additional problem though.
While I have the required code, I cannot add the module. Adding the module to etc/config.php, as suggested in 2 out of the 3 tutorials, simply crashed M2, both admin and frontend when you try to clear the cache. This is the case after manually clearing cache folders in the var directory.
Also, still unable to add the .phtml template file to a static block or page using content editor.
Not much hair left to pull out here, so looking for help! Thanks in advance
There are a few samples on GitHub, including https://github.com/magento/magento2-samples/tree/master/sample-module-newpage which shows a module adding a new page with a very simple PHTML template file. This example does not use CMS content editing however - it is a sample based on using layout files.
You mentioned you were getting crashes. Would need more details to help on that one. If you got it solved, could you update this question and accept a response to close it out? Thx!
You Should try "class" instead of "type". So your code should look like.
{{block class="<package>\<module>\Block\MyBlock" template="mypage.phtml"}}
You Should try "VenderName_Modulename::myelement/mypage.phtml" instead of "myelement/mypage.phtml". So your code should look like.
{{block class="VenderNameModulename\Block\MyBlock" template="VenderName_Modulename::myelement/mypage.phtml"}}

Magento merge javascript omit files

I've found that prototype.js messes up some things whenever I merge javascript on my store. Is there a way to have Magento omit prototype.js when it merges javascript files? I assume I could rewrite whatever function does this, but I'm not sure how to find where this happens. Is there a good way to find what is happening and where in Magento?
You can omit a file from being combined by adding a param. For example, in your page.xml you could change the following line:
<action method="addJs"><script>prototype/prototype.js</script></action>
to:
<action method="addJs"><script>prototype/prototype.js</script><params>prototype</params></action>
All files with the same param are combined together.
The magento merging system does n't work well in a lot of cases. I think for better understanding u should check Here
There is not an option to exclude a file from admin panel but i guess u can separate them by using grouping technology mentioned in the above blog.
Instead of using the default merging system i suggest u sld try FooMan Speedster
install mod_pagespeed by google on server zero configuration for your magento.
Try to load prototype.js link in head.phtml file. This way don't merge your file, and you don't need to add it via xml.
It is not the best practice anyway, but it works perfectly.

Payment fields missing from Authorize.net checkout method

This is a pretty strange issue. If I enable the Authorize.net payment method, the input fields to enter your CC details is missing from HTML. This is a pretty much out of the box installation with just some theme work having been done, and I didn't touch the opc templates.
If I enable Saved CC payment method, the fields appear correctly.
I did not make any changes to the OOTB Authorize.net files in Magneto and even tried disabling my entire theme and it doesn't have any impact.
Screenshot of code:
http://cl.ly/image/3g1n2x021N2s
After looking into this more, it looks like this line in templates/checkout/payments/method.phtml is not returning any HTML:
$this->getPaymentMethodFormHtml($_method)
I found this method and it in-turn is trying to load a child.
public function getPaymentMethodFormHtml(Mage_Payment_Model_Method_Abstract $method)
{
return $this->getChildHtml('payment.method.' . $method->getCode());
}
That is about how far I have gotten.
I would try the following steps:
Check your exception log under /var/log/exception.log
Check your PHP error log
Disable your current theme by renaming your theme folder eg: /app/design/frontend/default/themename >> /app/design/frontend/default/_themename - this rules out the possibility of invalid theme/layout XML issues. Make sure it falls back to an untouched base default theme!
Disable your non-standard extensions by setting <active>false</active> in the XMLs found under /app/etc/modules one by one.
Try see if there is a difference in value $method->getCode() when saved CC is turned on & off.
If possible, update the Authorize.net extension. If not, at least check if your /app/etc/modules/Mage_Authorizenet.xml is as follows:
<config>
<modules>
<Mage_Authorizenet>
<active>true</active>
<codePool>core</codePool>
<depends>
<Mage_Paygate/>
<Mage_Sales/>
<Mage_Checkout/>
</depends>
</Mage_Authorizenet>
</modules>
</config>
This is a workaround if you don't find any solution for your problem.
You can create your own payment form for authorize.net
Authorize.net form used cc.phtml file for display Authorize.net fields so you can copy this file and set this form from xml.
Go to your checkout.xmland in <checkout_onepage_index translate="label"> tag find checkout.payment.methods which display all methods put action methods something like this
<action method="setMethodFormTemplate"><method>authorizenet</method><template>payment/form/authorizenet.phtml(which is copy of your cc.phtml)</template></action>
I have not test it.
Authorize.net use this block for display form fields so further you can look into this file
app\code\core\Mage\Paygate\Block\Authorizenet\Form\Cc.php
You can also check if Mage_Authorizenet or Mage_Paygate module are disabled in your Magento admin.
System -> ADVANCED -> Advanced
Make sure that they are enabled there.

PyroCMS Custom Module Layout

I created a custom module called Drawings. I wanted to give it its own theme layout on the frontend, so I followed the advice I found HERE - I put a layout file titled Drawings.html in my theme.
This had the correct effect on the frontend, but caused other problems and questions that I've been struggling to sort out:
The backend admin section for my module now uses the Drawings.html layout, which breaks its functionality completely. How can I set a specific layout for my module front end, but keep the standard admin backend layout (same backend implementation as in the sample module tutorial)?
I read the following in the Template Library: "When using Public_Controller and Admin_Controller, the layout is already set." Perhaps the solution involves using the set_layout function in these controllers somehow? All my attempts failed so far though.
I feel I am doing something incorrectly because now my module is not modular. For example, after creating the Drawings.html layout file in the theme, a statement like {{ theme:css file="drawings.css"}} in that layout file searches for those resources in my theme. So I have to put those JS and CSS resources in my theme, instead of in my module's CSS and JS folders. How do I keep and access my resources in the module's JS and CSS folders?
I don't know how this is supposed to work.
When you are using front end controller use a layout there using philsturgeon template library like this
function index(){
$this->template->set_layout('drawing')
->build('yourview');
}
This way you can load a custom layout for your application.

Calling a Static Custom Module Block in a CMS page

In my CMS contact-us page, I have the following code:
{{block type="core/template" name="contactForm" form_action="/contacts/index/post" template="contacts/form.phtml"}}
Which pulls in Magento's standard Contact Form. I have installed a new module from Fontis called recaptcha to prevent spam. This is located my_theme/default/template/fontis/recaptcha/contacts.phtml.
Is anyone able to tell me how I correctly modify the above code to use the new form please?
I have tried changing: template="contacts/form.phtml" to template="fontis/recaptcha/contacts.phtml" but this doesnt seem to work, not sure if I need to alter the block type to make it work.
Thanks in advance for any help
John
Your modification is generally correct to change a template path. Specifically, what do you mean when you say it "doesn't" work? Without more information on what you're seeing, it's difficult to help you debug this issue.
Thanks!
Joe
Sounds like a caching issue to me, or that you're changing the template on the wrong declaration. First, turn off all caching on your site and try again. If that doesn't work, turn on template path hints and make sure that you are editing what you think you are.

Resources