Add JS to head in Cart
I have problem when I want to put JS into head when PHP condition is met, but I'm getting Mage_Core_Exception: Invalid block type excetion no idea why. I have read all the possible issues I have found but looks like there is ton of places I could go wrong and right now Im out of ideas.
I have config.xml where is my module declared. This is only part of it as rest of module is working, also JS and CSS I have in module_name.xml is working properly.
</frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
Then I have module_name.xml I understand that I say here "on checkout/cart page load this template/modulename/prependca.phtml into of page.
<checkout_cart_index translate="label">
<reference name="head">
<block type="namespace_moduleName/cart" name="prependca" template="modulename/prependca.phtml"/>
</reference>
</checkout_cart_index>
Last, but not least, I have this Class of mine:
class Namespace_ModuleName_Block_Cart extends Mage_Checkout_Block_Cart_Abstract {
public function prependCa() {
$_quote = Mage::getSingleton('checkout/session')->getQuote();
if (get_class($_quote) == Mage_Sales_Model_Quote) {
$head = $this->getLayout()->getBlock('head');
$head->addJs('namespace/modulenameTotals.js');
$head->addItem('js', 'namespace/modulenameTotals.js');
}
}
}
From what I have read, I did all I had to do, however I still don't get results and only respond I get is Mage_Core_Exception: Invalid block type
magento-1.9 javascript blocks head
bumped to the homepage by Community♦ 7 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I have problem when I want to put JS into head when PHP condition is met, but I'm getting Mage_Core_Exception: Invalid block type excetion no idea why. I have read all the possible issues I have found but looks like there is ton of places I could go wrong and right now Im out of ideas.
I have config.xml where is my module declared. This is only part of it as rest of module is working, also JS and CSS I have in module_name.xml is working properly.
</frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
Then I have module_name.xml I understand that I say here "on checkout/cart page load this template/modulename/prependca.phtml into of page.
<checkout_cart_index translate="label">
<reference name="head">
<block type="namespace_moduleName/cart" name="prependca" template="modulename/prependca.phtml"/>
</reference>
</checkout_cart_index>
Last, but not least, I have this Class of mine:
class Namespace_ModuleName_Block_Cart extends Mage_Checkout_Block_Cart_Abstract {
public function prependCa() {
$_quote = Mage::getSingleton('checkout/session')->getQuote();
if (get_class($_quote) == Mage_Sales_Model_Quote) {
$head = $this->getLayout()->getBlock('head');
$head->addJs('namespace/modulenameTotals.js');
$head->addItem('js', 'namespace/modulenameTotals.js');
}
}
}
From what I have read, I did all I had to do, however I still don't get results and only respond I get is Mage_Core_Exception: Invalid block type
magento-1.9 javascript blocks head
bumped to the homepage by Community♦ 7 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
did you try usingcore/template
block?
– Jaimin Sutariya
Sep 24 '17 at 18:27
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13
add a comment |
I have problem when I want to put JS into head when PHP condition is met, but I'm getting Mage_Core_Exception: Invalid block type excetion no idea why. I have read all the possible issues I have found but looks like there is ton of places I could go wrong and right now Im out of ideas.
I have config.xml where is my module declared. This is only part of it as rest of module is working, also JS and CSS I have in module_name.xml is working properly.
</frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
Then I have module_name.xml I understand that I say here "on checkout/cart page load this template/modulename/prependca.phtml into of page.
<checkout_cart_index translate="label">
<reference name="head">
<block type="namespace_moduleName/cart" name="prependca" template="modulename/prependca.phtml"/>
</reference>
</checkout_cart_index>
Last, but not least, I have this Class of mine:
class Namespace_ModuleName_Block_Cart extends Mage_Checkout_Block_Cart_Abstract {
public function prependCa() {
$_quote = Mage::getSingleton('checkout/session')->getQuote();
if (get_class($_quote) == Mage_Sales_Model_Quote) {
$head = $this->getLayout()->getBlock('head');
$head->addJs('namespace/modulenameTotals.js');
$head->addItem('js', 'namespace/modulenameTotals.js');
}
}
}
From what I have read, I did all I had to do, however I still don't get results and only respond I get is Mage_Core_Exception: Invalid block type
magento-1.9 javascript blocks head
I have problem when I want to put JS into head when PHP condition is met, but I'm getting Mage_Core_Exception: Invalid block type excetion no idea why. I have read all the possible issues I have found but looks like there is ton of places I could go wrong and right now Im out of ideas.
I have config.xml where is my module declared. This is only part of it as rest of module is working, also JS and CSS I have in module_name.xml is working properly.
</frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
Then I have module_name.xml I understand that I say here "on checkout/cart page load this template/modulename/prependca.phtml into of page.
<checkout_cart_index translate="label">
<reference name="head">
<block type="namespace_moduleName/cart" name="prependca" template="modulename/prependca.phtml"/>
</reference>
</checkout_cart_index>
Last, but not least, I have this Class of mine:
class Namespace_ModuleName_Block_Cart extends Mage_Checkout_Block_Cart_Abstract {
public function prependCa() {
$_quote = Mage::getSingleton('checkout/session')->getQuote();
if (get_class($_quote) == Mage_Sales_Model_Quote) {
$head = $this->getLayout()->getBlock('head');
$head->addJs('namespace/modulenameTotals.js');
$head->addItem('js', 'namespace/modulenameTotals.js');
}
}
}
From what I have read, I did all I had to do, however I still don't get results and only respond I get is Mage_Core_Exception: Invalid block type
magento-1.9 javascript blocks head
magento-1.9 javascript blocks head
asked Sep 24 '17 at 17:44
RailBalcoRailBalco
51
51
bumped to the homepage by Community♦ 7 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 7 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
did you try usingcore/template
block?
– Jaimin Sutariya
Sep 24 '17 at 18:27
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13
add a comment |
did you try usingcore/template
block?
– Jaimin Sutariya
Sep 24 '17 at 18:27
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13
did you try using
core/template
block?– Jaimin Sutariya
Sep 24 '17 at 18:27
did you try using
core/template
block?– Jaimin Sutariya
Sep 24 '17 at 18:27
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13
add a comment |
1 Answer
1
active
oldest
votes
Go to
app/design/frontend/{package}/{theme}/layout/local.xml
then add this :
<checkout_cart_index>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
</reference>
</checkout_cart_index>
Create your new js file in:
skin/frontend/{package}/{theme}/js/my-custom.js
then put your code inside.Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.
NB: I see some errors in your code:
1)
<frontend> // not </frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
2)
You can't load this type of block in a head ! but you can do it content
, root
etc...
If you need is to add a js file, follow my solution.
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f194509%2fadd-js-to-head-in-cart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Go to
app/design/frontend/{package}/{theme}/layout/local.xml
then add this :
<checkout_cart_index>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
</reference>
</checkout_cart_index>
Create your new js file in:
skin/frontend/{package}/{theme}/js/my-custom.js
then put your code inside.Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.
NB: I see some errors in your code:
1)
<frontend> // not </frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
2)
You can't load this type of block in a head ! but you can do it content
, root
etc...
If you need is to add a js file, follow my solution.
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
add a comment |
Go to
app/design/frontend/{package}/{theme}/layout/local.xml
then add this :
<checkout_cart_index>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
</reference>
</checkout_cart_index>
Create your new js file in:
skin/frontend/{package}/{theme}/js/my-custom.js
then put your code inside.Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.
NB: I see some errors in your code:
1)
<frontend> // not </frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
2)
You can't load this type of block in a head ! but you can do it content
, root
etc...
If you need is to add a js file, follow my solution.
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
add a comment |
Go to
app/design/frontend/{package}/{theme}/layout/local.xml
then add this :
<checkout_cart_index>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
</reference>
</checkout_cart_index>
Create your new js file in:
skin/frontend/{package}/{theme}/js/my-custom.js
then put your code inside.Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.
NB: I see some errors in your code:
1)
<frontend> // not </frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
2)
You can't load this type of block in a head ! but you can do it content
, root
etc...
If you need is to add a js file, follow my solution.
Go to
app/design/frontend/{package}/{theme}/layout/local.xml
then add this :
<checkout_cart_index>
<reference name="head">
<action method="addItem"><type>skin_js</type><name>js/my-custom.js</name></action>
</reference>
</checkout_cart_index>
Create your new js file in:
skin/frontend/{package}/{theme}/js/my-custom.js
then put your code inside.Now your js file will be just loaded in checkout/cart. Don't forget to clear the cache.
NB: I see some errors in your code:
1)
<frontend> // not </frontend>
<layout>
<updates>
<module_name>
<file>module_name.xml</file>
</module_name>
</updates>
</layout>
</frontend>
2)
You can't load this type of block in a head ! but you can do it content
, root
etc...
If you need is to add a js file, follow my solution.
edited Sep 24 '17 at 20:49
answered Sep 24 '17 at 20:23
PЯINCƏPЯINCƏ
8,34631143
8,34631143
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
add a comment |
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
i tried changing from head to content or root, but still doesnt work. My main problem is that I cant use theme...
– RailBalco
Sep 25 '17 at 8:01
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
What kind of block do you want to add ?, it's a Js file ?
– PЯINCƏ
Sep 25 '17 at 8:02
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f194509%2fadd-js-to-head-in-cart%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did you try using
core/template
block?– Jaimin Sutariya
Sep 24 '17 at 18:27
tried now, surprisingly still same...
– RailBalco
Sep 24 '17 at 19:13