Custom block in magento - magento

I have added this block in checkout.xml:
<block type="checkout/cart_shipping" name="checkout.cart.shipping" as="shipping" template="checkout/cart/shipping.phtml"/>
Then, I have shown this in cart.phtml:
echo $this->getChildHtml('shipping');
Then, I have made a page as shipping.phtml file in cart folder. This is working on my local PC, but when I follow this path on the server no block is showing. There is one difference between the two environments: on local I am doing all this step in the base folder, but on the server there is a customized theme folder in the default folder.
Can anyone tell me where I am wrong?
Thanks in advance.

Check design's configuration on server, is this theme really loaded.

Make sure that you added the XML correctly (without any typos). A typo in the XML would probably cause Magento to load the default checkout.xml instead of your custom one, losing your block changes.

Related

Incorrect Magento 2 layouts override behavior

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

Static block not showing up in CMS page

I just started working on magento/admin. I am trying to show my static block in one of my CMS pages, but it is not working. I tried to find out answer in google and stack exchange but no luck! Can anyone please help.Thanks.
Below are details:
This is my static block
This is my CMS page: I am able to see the text "Yes!" though.
Final output: That blue box is my CSS. (jfyi).
If you use the latest Magento version 1.9.2.2 that includes the latest patches, then you need to add first the block to Magento white list in teh backend: System->Permissions->Block.
See this article: http://www.dudesquare.nl/blog/2015/10/31/static-block-shortcodes-not-working-1-9-2-2/
Please set different identifier in static block than CMS page. I think CMS page and block identifier same so may be block not display on CMS page.
Also select all store views in static block may be your store is wrong.
And finally remove all cache and refresh all index.
Please check following:
Whether you had editor enabled, while calling static block. If yes, please click on Show/Hide Editor button and check what code is there in text area while editor mode off.
If above does not work, then go to System >> Configuration >> Advanced (Developer) and under Log Settings, Enable Logs. Then refresh cms page in frontend.
I hope this will help you resolve your issue. Please let me know if you find any problem.
Try to add static blocks through Layout Update XML in CMS Pages use something like this code. Add this code in your CMS page design tab.
<reference name="content">
<block type="cms/block" name="block.name">
<action method="setBlockId">
<block_id>block_id</block_id>
</action>
</block>
</reference>
Solution:
Step 1)Go to admin.
Step 2)Open Top menu System->Permissions->Blocks.
Step 3)click "Add New Block".
write your "Block Name" and Is Allowed "Yes".
Note: Block Name is type of your block for example "cms/block"
after Save Block.
Step 4)Clear cache and refresh front page. Now Block is showing.
Done.

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.

Changing Core data for Magento programmatically

I am currently working on a live website, but the trouble is they would like to switch theme so what I would like to install the new theme and only make it viewable by my ip address.
The trouble is I do not know how to change the Magento theme and skin values programmatically.
Could any of you help me out here?
So this is not a direct answer. Best practices are going to be to back up your database, and system, and restore to a development environment files and database.
Edit the two entries for each store in the core_config_data table to change the url from the live site to the dev site url.
Then develop your new or modified theme on the dev site and deploy the files to the live server when you are ready to push your changes.
There could be an alternative way to do this. You could make a new store in on your Magento install See How to Make Multiple Stores and then copy the theme folder to your development them name directory. And finally configure the new/dev store to use your dev theme.
Both of these are viable options. Trying to trick Magento to serve one theme to your IP and another to everyone else seems like asking for trouble.
This can be done with no modifications to the Magento core.
It involves Chrome and setting your user agent as something custom.
First off, create an exception in Magento - we'll set the matched expression as dev and set the package to new-theme. This will set your package as new-theme if your user-agent matches dev (will serve the theme located in app/design/frontend/new-theme:
Then the second and final step is to open your Developer Toolbar in Chrome and set your user-agent as dev:
Take these 2 easy steps and you can programatically set your theme package only for yourself without affecting others.
You can do it with
Mage::getSingleton('core/design_package')->setTheme('default');
For the implementation just create a block that loads on all pages and add it to the constructor.
XML would be something like that:
<layout version="0.1.0">
<default>
<reference name="content">
<block type="kervin/theme" name="kervin.theme"/>
</reference>
</default>
</layout>
and theme.php, the block would be:
class My_Kervin_Block_Theme extends Mage_Core_Block_Template
{
public function __construct()
{
if ($_SERVER["REMOTE_ADDR"] == 'xxx') {
Mage::getSingleton('core/design_package')->setTheme('default');
}
}
}

Magento: Incorrect template design for login and register page due to Persistent Shopping Cart

I am using Magento 1.7.0.2 and my login and register page design has problem. It is not taking the template path from my custom theme. Instead, it is taking the template path from base persistent folder.
For example, the login template path is taken from
frontend/base/default/template/persistent/customer/form/login.phtml instead of
frontend/default/MY_THEME/template/customer/form/login.phtml
It’s strange how this persistent folder come into action.
I try below things also
1) Copy the persistent folder from design base directory to your custom theme directory. And then modify the design on the files you copied.
2)Disable the persistent shopping cart feature. You can do this from :
System -> Configuration -> CUSTOMERS -> Persistent Shopping Cart -> General Options -> Enable Persistence = No
3)directly disable the module by editing the file: app/etc/modules/Mage_Persistent.xml by setting active = false.
Also did Refresh my Magento cache and also browser cache!
Is there any other solution or suggestion that i have to applied other then this?
Waiting for your kind response.
Copy login.phtml from frontend/base/default/template/persistent/customer/form/ to frontend/default/MY_THEME/template/persistent/customer/form/ (You have already done this)
Clear the Magento CACHE. Even your browser cache.
If still doesn't shows up, then check the folder path. If you have placed it correctly, it should show the Theme Template path in the hints. There is no bug in Magento which causes this kinda problem.
Make sure the Theme where you have copied the persistent login.phtml is the Theme that you are using in design settings.
Copy your template from frontend/default/MY_THEME/template/customer/form/login.phtml to frontend/default/MY_THEME/template/persistent/customer/form/Login.phtml, then refresh your Cache. Now the changes you did to the Login.phtml should be loaded.
Sometimes a module can overwrite the template used for the login form. And maybe you are missing the template files. You should check for layout xml handles like:
<customer_account_login>
<reference name="customer_form_login">
<action method="setTemplate"><template>template/name.phtml</template></action>
</reference>
</customer_account_login>
Another thing you should check is if the block used for the login is the core one because again a template override may happen from a module.

Resources