Magento add javascript before default javascript - magento

I'm currently developing a custom module for admin and I would like to add a custom javascript before default ones.
I tried to use :
<action method="addItem"><type>skin_css</type><name>path/to/javascript.js</name><params/><if/></action>
But this line add javascript after default like prototype.js, window.js...
Is there a way to add mine before ?
Thanks !

If you want to re-order of the JavaScript files loaded in the admin, then in your layout xml handle, you will need to remove all of the script files, then add yours and then re-add them again. Please note that your js file should be in the js folder, not the skin one.
<!-- Remove the added ones -->
<action method="removeItem"><type>js</type><name>prototype/window.js</name></action>
<action method="removeItem"><type>js</type><name>scriptaculous/builder.js</name></action>
...
<!-- Add yours -->
<action method="addJs"><script>path/to/javascript.js</script></action>
<!-- Add the removed ones after -->
<action method="addJs"><script>prototype/window.js</script></action>
<action method="addJs"><script>scriptaculous/builder.js</script></action>
...

go to app\design\frontend\rwd\default\layout page.xml (if you are using default theme otherwise go to yourtheme\default\layout) and you js here
<block type="page/html_head" name="head" as="head">
<action method="addJs">
<script>yourjs/yourjs.js</script>
</action>
<action method="addJs">
<script>prototype/prototype.js</script>
</action>

Related

Magento - how to remove "addLinkRel"

I've created a child theme, with 'rwd' as the parent theme. The parent theme has this code in the 'head' block in page.xml:
<action method="addLinkRel"><rel>stylesheet</rel><href>//fonts.googleapis.com/css?family=Raleway:300,400,500,700,600</href></action>
is there a way of removing it in the child theme in local.xml?
Add this code in your local.xml file
<default>
<reference name="head">
<action method="removeItem"><type>link_rel</type><name>//fonts.googleapis.com/css?family=Raleway:300,400,500,700,600</name></action>
</reference>
</default>
This is not obvious but it is quite easy.
<action method="removeItem"><type>link_rel</type><href>//fonts.googleapis.com/css?family=Raleway:300,400,500,700,600</href></action>

Magento WYSIWYG Editor not working

I installed magento 1.8.1.0 and when I click on the Show/Hide Editor button in CMS Pages or anywhere, it does nothing. I looked up in the browser's console and found out the following error.
Failed to load resource: the server responded with a status of 404 (Not Found) http://magento_address/js/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentotypo/editor_plugin.js
I looked in the magento installation folder but could not find a folder called magentotypo. I also looked in all my extensions and theme's files. How can I make it work or where can I get the referenced file?
Any help is highly appreciated.
I also faced same problem the only way i found a solution for this is I have opened my Chrome Inspector to the Console tab. I can see a the editorjs/mage/adminhtml/wysiwyg/tiny_mce/plugins/magentotypo/editor_plugin.js was missing to load. I created a folder named as magentotypo in the same path and uploaded the file to that path
Finally after long exploring a found a solution for this.
actually these errors occur because js is not loading properly, so update your layout by a local.xml and add the following code.
<?xml version="1.0"?>
<layout>
<frontname_adminhtml_index_edit>
<update handle="editor"/>
<reference name="head">
<action method="setCanLoadTinyMce">
<load>1</load>
</action>
<action method="setCanLoadExtJs">
<flag>1</flag>
</action>
<action method="addJs">
<script>mage/adminhtml/variables.js</script>
</action>
<action method="addJs">
<script>mage/adminhtml/wysiwyg/widget.js</script>
</action>
<action method="addJs">
<script>lib/flex.js</script>
</action>
<action method="addJs">
<script>lib/FABridge.js</script>
</action>
<action method="addJs">
<script>mage/adminhtml/flexuploader.js</script>
</action>
<action method="addJs">
<script>mage/adminhtml/browser.js</script>
</action>
<action method="addJs">
<script>prototype/window.js</script>
</action>
<action method="addItem">
<type>js_css</type>
<name>prototype/windows/themes/default.css</name>
</action>
<!-- <action method="addItem">
<type>js_css</type>
<name>prototype/windows/themes/magento.css</name>
</action>-->
<action method="addCss">
<stylesheet>lib/prototype/windows/themes/magento.css</stylesheet>
</action>
</reference>
</frontname_adminhtml_index_edit>
</layout>
After this view the code by pressing ctrl+u and find if these are loaded properly or not. And if not try changing
</frontname_adminhtml_index_edit>
properly.
Hope this will resolve!
It might be because of the jquery conflicts.
Try removing the recently added JS and check WYSIWYG is working not.
The solution is (using filezilla):
Go to: / js / mage / adminhtml / wysiwyg / tiny_mce / plugins / magentowidget
Copy the file to the desktop: editor_plugin.js
Go to: / js / mage / adminhtml / wysiwyg / tiny_mce / plugins /
Create a directory called: magentotypo
Paste the file into the directory magentotypo: editor_plugin.js

Add javascript code in payment.phtml in the Magento

I have the following layout xml
<reference name="content">
<block type="gate/paycheckout" name="payair.gate.paycheckout" before="-" template="gate/checkout.phtml"/>
<block type="gate/paymentjs" name="payair.gate.paymentjs" />
</reference>
I have a block by which i am calling the javascript on the payment.phtml and its working but i want to call the Magento addJs action method to add the javascript dynamically on the payment.phtml page not by calling the block. How can i do this?
You should add the script to head:
layout xml file:
<layout>
<name_of_the_handle>
<reference name="head">
<action method="addJs"><script>gate/payment.js</script></action>
</reference>
</name_of_the_handle>
...
</layout>
payment.js file should in this case be located in js/gate/payment.js

Removing links from top menu using local.xml

Does anyone know how I can remove links from the top menu using local.xml.
In the default checkout.xml there is:
<reference name="top.links">
<block type="checkout/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<action method="addCheckoutLink"></action>
</block>
</reference>
And I would like to remove the addCartLink from the top menu. One way would be just edit the checkout.xml file, but it think it would be a much better solution just to add the remove to my local.xml file, but I can't seem to get the right name to remove. If I do a
<layout>
<default>
<remove name="top.links" />
</default>
</layout>
That does remove the entire menu, but how do I remove just a single item from the menu using locale.xml?
I am using Magento 1.6
You can do this in local.xml:
<default>
<reference name="top.links">
<action method="removeLinkByUrl">
<url helper="checkout/url/getCartUrl" />
</action>
</reference>
</default>
It was also my question How can i get the full path in local.xml file
<default>
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link"/>
<action method="removeLinkBlock"><blockName>wishlist_link</blockName></action>
</reference>
</default>
Add this part to your local.xml. Writing this under default will remove it from every page. So adjust it accordingly. I hope this will help you.
It should be:
<layout>
<default>
<reference name="top.links">
<reference name="checkout_cart_link">
<remove name="top-link-cart" />
</reference>
</reference>
</default>
</layout>
But you can always copy the checkout.xml in your local theme and edit it.
<default>
<reference name="top.links">
<remove name="wishlist_link"/>
</reference>
</default>
Add this part to your local.xml. That works for me. Just use "remove". That's it.
You can remove a link via layout update either
by its name | calling removeLinkBlock($blockName)
by its url | calling removeLinkByUrl($url)
overwriting the file were it was added
The functions live in Mage_Page_Block_Template_Links
Option 1
The removeLinkByUrl() function needs an url as parameter which will usually provided by a helper function in the respective extension. Just grab it there and you can use something like
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="customer/getRegisterUrl"/></action>
</reference>
In above case customer is the extensions name while getRegisterUrl is the function in the helper class.
If your extension isn't providing any function which is returning a link you can try following
<reference name="top.links">
<action method="removeLinkByUrl"><url>ADD_THE_DYNAMIC_LINK_HERE</url></action>
</reference>
Option 2
If the link was added with a name, like
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link" />
<action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
</reference>
you can just use
<reference name="top.links">
<remove name="wishlist_link"/>
</reference>
or
<default>
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link"/>
<action method="removeLinkBlock"><blockName>wishlist_link</blockName></action>
</reference>
</default>
Option 3
If your link wasn't added with a name and a hardcoded url doesn't work for some reason you can just go ahead and copy the modules layout.xml to your custom theme folder and remove the lines where the link was added.
Hi This removes both the cart and checkout links from top.links in 1.9.3
<reference name="top.links">
<action method="removeLinkByUrl">
<url helper="checkout/url/getCartUrl" />
</action>
<action method="removeLinkByUrl">
<url helper="checkout/url/getCheckoutUrl" />
</action>
</reference>
based on the best accepted answer above but just in case anyone wants to remove both

Magento :Password reset link is not working

i am trying to reset my test customer account password for my store, when i click on forgot password link it is asking me for a email address when i enter a valid email address it says the password reset link is sent to your mail & it is forwarding me a link in email when i click on the link it is displaying an error Fatal error: Call to a member function setCustomerId() on a non-object in /var/www/websites/jivity/app/code/core/Mage/Customer/controllers/AccountController.php on line 587 , How can i fix this error?? & Thanx in advance.
Just fixed the same problem on an upgraded 1.6.1.0 site - You are using an out of date customers.xml, diff your copy and app/design/frontend/base/default/layout/customer.xml to find the changes that need doing
If anyone is wondering, in the new version (1.6++) of the customer.xml file the following bit has been added:
<customer_account_resetpassword translate="label">
<label>Reset a Password</label>
<remove name="right"/>
<remove name="left"/>
<reference name="head">
<action method="setTitle" translate="title" module="customer">
<title>Reset a Password</title>
</action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/1column.phtml</template>
</action>
<action method="setHeaderTitle" translate="title" module="customer">
<title>Reset a Password</title>
</action>
</reference>
<reference name="content">
<block type="customer/account_resetpassword" name="resetPassword" template="customer/form/resetforgottenpassword.phtml"/>
</reference>
</customer_account_resetpassword>
If you are in Magento 1.9.1 Here is a solution which worked for me.
If your theme doesn’t include any specific custom config or layout settings you can safely delete your customer.xml (or just rename to customer1.xml) file located at /app/design/frontend/default/<your_theme_package>/<your_theme_name>/layout/customer.xml
If you delete this file magento will load the default config options
(with the updates) from the factory default magento theme.
/app/design/frontend/base/default/layout/customer.xml
Remember to flush / refresh your magento config via administration area, this will force the customer.xml file to be reloaded.
please add below code in your costomer.xml[app/design/frontend///layout/customer.xml] file.
<customer_account_resetpassword translate="label">
<label>Reset a Password</label>
<remove name="right"/>
<remove name="left"/>
<reference name="head">
<action method="setTitle" translate="title" module="customer">
<title>Reset a Password</title>
</action>
</reference>
<reference name="root">
<action method="setTemplate">
<template>page/1column.phtml</template>
</action>
<action method="setHeaderTitle" translate="title" module="customer">
<title>Reset a Password</title>
</action>
</reference>
<reference name="content">
<block type="customer/account_resetpassword" name="resetPassword" template="customer/form/resetforgottenpassword.phtml"/>
</reference>
</customer_account_resetpassword>
It's Working
I tried the above, but didn't work. From another tip I saw, I added the same code above to the 'mageb2bextensionscustomer.xml' in the same layout folder, cleared all the cache and it works now. :-)
Always back up your files!
I found a fast way to solve the issue: I replaced the custom customer.xml used by my theme in app/design/frontend/your_theme_package/your_theme_name/layout/ with the file in app/design/frontend/base/default/layout/customer.xml.
Now it works just fine.

Resources