Can we disable magento extension for particular page - magento

how to disable a extension for particular page for example i want to disable extension for homepage only in magento
<config>
<modules>
<first_module>
<active>false</active>
<codepool>local</codepool>
</first_module>
</modules>
</config>

I haven't confronted this kinda disabling feature that way. What we usually do is, we remove the module on the page from local.xml under the page responsible layout handle taking responsible reference.
For eg. if i don't one particular module for eg.newsletter on homepage then,
<cms_index_index> <!--/ Homepage -->
<reference name="footer"> <!--/ Reference where the module appearing -->
<remove name="newsletter"/> <!--/ Remove -->
</reference>
</cms_index_index>

That is not possible in Magento 1.x
You can only enable/disable a module per store view or website.

Related

Magento 1.9 - modifying layout

What is the best way of modifying a layout for Magento 1.9? I've been updating layouts using the admin backend but now need to do this programatically. Several articles have mentioned using layout.xml but for some reason, my system isn't picking up the layout updates.
Specifically, this is what I'm trying to modify:
Original layout
<block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
<action method="addOptionRenderer">
<type>text</type>
<block>catalog/product_view_options_type_text</block>
<template>catalog/product/view/options/type/text.phtml</template>
</action>
...
</block>
Modified layout
<block type="catalog/product_view_options" name="product.info.options" as="product_options" template="catalog/product/view/options.phtml">
<action method="addOptionRenderer">
<type>text</type>
<block>catalog/product_view_options_type_text</block>
<template>catalog/product/view/options/type/newfile.phtml</template>
</action>
...
</block>
My modified layout is located in:app/design/frontend/default/(company name)/(module name)/layout/layout.xml
layout.xml (just checking to see if it will add the block, "test"):
<layout>
<default>
<block type="core/text_list" name="test"/>
</default>
</layout>
app/code/local/(company name)/(module name)/etc/config.xml:
<config>
<modules>
...
</modules>
<frontend>
<layout>
<updates>
<(module name)>
<file>local.xml</file>
</(module name)>
</updates>
</layout>
</frontend>
</config>
Can somebody point me in the right direction? Thanks!
Here are two things I notice which should be changed:
Your layout update file should have a unique name that won’t conflict with existing modules. In your config.xml you have specified <file>local.xml</file>. The problem with this is, local.xml will already be loaded automatically by Magento. So you should not use that filename for your layout update file if you are trying to add a new one specific to your module, however you may add miscellaneous updates to that file and they will get picked up automatically and applied last to the final merged layout.
Behind the scenes there’s an <updates /> section of the global config that contain nodes with all the file names to load. Once the files listed in the config have been combined, Magento will merge in one last xml file, local.xml.
Your layout update file app/design/frontend/default/(company name)/(module name)/layout/layout.xml does not appear to be in the right location. You should create your new layout update file at: app/design/frontend/base/default/layout/(company name)/(module_name).xml. Then, you need to update your config.xml to point to this file: <file>(company name)/(module name).xml</file>.
Because of the ability to use different themes in Magento and its fallback mechanism, all extension related theme files are placed in “base/default” package for frontend...

How do I add javascript tracking code to all magento pages?

I need to add java script tracking code to all pages of my magento store just before the closing "body" tag. Does anyone know what file I need to put this in? And do I have to modify the JavaScript at all for Magento or just paste it in?
To answer your question: How do I add javascript to every page
Within the template, typically you load a footer block on every page, so go and find the phtml file here;
app/design/frontend/XXX/YYY/template/page/html/footer.phtml
Where xxx/yyy is your theme directory. Add the tracking code here and it will load on every page.
Regarding whether it needs modification - that really depends what you expect to do. If you need to insert variables such as basket values, customer number (if present) etc, then yes you will need to add those php variables to it, and here is where you could run into trouble. If you are using caching, then the footer may not be the best place as you could end up with cached variable values in the snippet. If it dynamically pulls it values for things such as page url, then you'll be ok.
The other problem is that this will load in your checkout pages - so if it calls a js file from an http:// location, your page will fail SSL validation.
You can do this by adding a layout file to your module configuration:
<config>
...
<frontend>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
...
</config>
Add the mymodule.xml file into the app/design/frontend/base/default/layout/ folder and put the following content in there:
<layout version="1.0.0">
<default>
<reference name="before_body_end">
<block type="core/template" name="mytracking.block" after="-" template="mynamespace/mymodule/tracking.phtml">
<action method="setCacheLifetime"><s>0</s></action>
</block>
</reference>
</default>
</layout>
Now you can add your tracking javascript code in this template file app/design/frontend/base/default/template/mynamespace/mymodule/tracking.phtml. It will be printed in all Magento pages.
EDIT
I've added a piece of code that disables the cache for your tracking block, thanks to #PixieMedia for letting me know.
Easiest way - via the backend, there is a config section specifically for this need.
System -> Configuration -> General -> Design Section -> Footer Tab -> Miscellaneous HTML
It relies on your theme calling the getAbsoluteFooter() method in your main template files right before the closing body tag, just be aware of that.
<?php echo $this->getAbsoluteFooter() ?>
</body>

Magento Google Analytics Content Experiments

What is the simplest way to implement Google Analytics Content Experiment into Magento CE?
I want to test home page content.
Adding the Testing Code to CMS pages does not work. Testing Tag is after Analytics Tag.
Does Magento support adding the Testing Tag via admin Interface?
Or is there a simple way to add the tag via XML Layout Update?
Would it be possible to use Google Tag Manager to add the codes we need?
Tags could be installed after body like:
Add to local.xml in your layout folder following code:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Last loaded layout file
-->
<layout>
<default>
<reference name="after_body_start">
<block type="cms/block" name="tags-first-in-body" before="-">
<action method="setBlockId"><block_id>tags-first-in-body</block_id></action>
</block>
</reference>
</default>
</layout>
and add a static block called tags-first-in-body.
Insert code to this block.

How do I override the review tab on OnePage Checkout

I am writing a custom module to change the display of the table on checkout/onepage/onepage.phtml I can see in checkout.xml how it gets declared with
<block type="checkout/onepage_review" name="checkout.onepage.review" as="review" template="checkout/onepage/review.phtml">
<block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/>
</block>
What I can not figure out is how to set up the /app/design/frontend/{location}/{theme}/layout/{module}.xml file to override the current review.phtml template with the new one. My thought would be to remove the current one and reload with the new one but that doesn't seem to be working.
The first thing i can see is the directory you are using is incorrect.
it should be
app/design/frontend/{location}/{theme}/layout/{module}.xml
instead of
app/layout/frontend/{location}/{theme}/layout/{module}.xml
Also, i'm not sure exactly what you want to do with regards to overriding the review layout table, but the following will replace the review template with your own:
<checkout_onepage_review>
<reference name="root">
<action method="setTemplate"><template>checkout/onepage/your_template.phtml</template></action>
</reference>
</checkout_onepage_review>
Secondly, if you are creating a custom module and want your layout file to be loaded, you have to declare the layout update in your modules config.xml. have you done this?
It would look something similar to this:
<?xml version="1.0"?>
<config>
<modules>
<Your_Company_Your_Module>
<version>1.0.0</version>
</Your_Company_Your_Module>
</modules>
<frontend>
<layout>
<updates>
<yourmodule>
<file>yourmodule.xml</file>
</yourmodule>
</updates>
</layout>
</frontend>
</config>
Finaly, depending on what you are trying to achieve, you may not require a module just to override the checkout review table.
If the sole purpose of the module is simple to override the checkout layout, then it would probably be sufficient to just override the layout by using one of the following methods:
Use local.xml
Create a local.xml file in your themes layout directory:
/app/design/frontend/{location}/{theme}/layout/{module}.xml
and use this for all core layout overrides. There are lots of benefits to this.
Copy the base checkout.xml layout file to your theme
Copy app/design/frontend/base/default/layout/checkout.xml
To app/design/frontend/{location}/{theme}/layout/checkout.xml

Is it possible to define Magento layout updates on a per-store basis

I have a single Magento install running two different websites. One sells ebooks and the other not and so the business team would like to see the "My Downloads" link removed from the customer navigation block in the My Account area of the application.
I can see the link defined in design/frontend/base/layout/downloadable.xml but cannot see any way defined that would let me disable the link on just one of the websites. Obviously, I could override this XML to turn off globally but I need the change to be limited in scope.
How do you define layout overrides on a single website or store in a multi site Magento installation?
Based on the responses below, I have done the following:
Created app/local/Mage/Customer/Block/Account/Navigation.php and added a method removeLink() which is not in the core code.
If I make the following change in local.xml, the download link is removed:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<remove name="catalog.compare.sidebar"/>
</default>
<customer_account>
<reference name="customer_account_navigation">
<action method="removeLink" translate="label" module="downloadable"> <name>downloadable_products</name></action>
</reference>
</customer_account>
</layout>
But, if try to target a specific store, it is not. E.g.
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<remove name="catalog.compare.sidebar"/>
</default>
<STORE_mm>
<customer_account>
<reference name="customer_account_navigation">
<action method="removeLink" translate="label" module="downloadable"> <name>downloadable_products</name></action>
</reference>
</customer_account>
</STORE_mm>
</layout>
As Anton suggested, set a new layout theme for your store. Another approach for anything site-wide + store-scoped would be to use the store layout handle - it's like a <default> handle which is applied each store. If your store code (under Manage Stores > Store View) is 'foo' the store layout handle would be <STORE_foo>.
Ref. Mage_Core_Controller_Varien_Action::addActionLayoutHandles()
Create different themes for this websites.
Create app/design/frontend/default/website1/layout/local.xml
and app/design/frontend/default/website2/layout/local.xml
Where you can make changes needed for downloadable layout.
This is described in magento feature.

Resources