Building a custom extension and need to load a new popup.phtml file so we can place our own code into it.
Ive already tried adding it as a package, but I want to avoid this so wondering if theres a way to add this/link to this using an xml layout file for example?
So in short, when a user clicks on the "Track Shipment" link in either the end user account, or the admin clicks the link from Sales > Shipments > View it will load my popup.phtml file and not the default one.
I've managed to solve this so here's how I managed to to it just in case it helps anyone else out :)
First of all in the app/etc/modules you'll need to create a file, lets call it Vendor_Module.xml and in there, we'll put the code;
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Vendor_Module>
<active>true</active>
<codePool>community</codePool>
</Vendor_Module>
</modules>
</config>
Then in app/community/Vendor/Module/etc/config.xml I added the following;
<?xml version="1.0"?>
<config>
<modules>
<Vendor_Module>
<version>1.0.0</version>
</Vendor_Module>
</modules>
<frontend>
<layout>
<updates>
<Vendor_Module_layout module="Vendor_Module">
<file>vendor_module.xml</file>
</Vendor_Module_layout>
</updates>
</layout>
</frontend>
</config>
In app/design/admin/default/default/layout I created vendor_module.xml and added the following code;
<?xml version="1.0"?>
<shipping_tracking_popup translate="label">
<label>Shipment Tracking Popup</label>
<reference name="root">
<action method="setTemplate"><template>page/popuper.phtml</template></action>
</reference>
<reference name="content">
<block type="shipping/tracking_popup" name="shipping.tracking.popup" template="shipping/tracking/popuper.phtml" />
</reference>
</shipping_tracking_popup>
In app/design/frontend/base/default/layout I created another vendor_module.xml file and added the code;
<?xml version="1.0"?>
<layout>
<shipping_tracking_popup>
<reference name="content">
<block type="shipping/tracking_popup" name="shipping.tracking.popup" template="Vendor/shipping/tracking/popup.phtml" />
</reference>
</shipping_tracking_popup>
</layout>
Finally, in app/design/frontend/base/default/template/Vendor/shipping/tracking I created a new file called popup.phtml and then added my own required code that I wanted displayed here. The following code is just example code that will add some text and a close button.
<div class="page-title title-buttons">
<h1><?php echo $this->__('Tracking Information'); ?></h1>
<button class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
<!-- Add Your Stuff Here -->
<div class="buttons-set">
<button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Close Window')) ?>" class="button" onclick="window.close(); window.opener.focus();"><span><span><?php echo $this->__('Close Window') ?></span></span></button>
</div>
Thats it, hope it helps!
Related
Hi I need to implement a multiple product chooser widget in magento. For this I am using the below code. With this a I can put a multiple sku for the products in the field in admin. But I need to implement a product chooser with a checkboxes so that I can check those and submit. Please check the screenshot here http://www.awesomescreenshot.com/0035hy791a
app/code/community/Speroteck/SelectedProductsBlock/etc/config.xml
<config>
<modules>
<Speroteck_SelectedProductsBlock>
<version>0.1.0</version>
</Speroteck_SelectedProductsBlock>
</modules>
<global>
<helpers>
<speroteck_selectedproductsblock>
<class>Speroteck_SelectedProductsBlock_Helper</class>
</speroteck_selectedproductsblock>
</helpers>
<blocks>
<speroteck_selectedproductsblock>
<class>Speroteck_SelectedProductsBlock_Block</class>
</speroteck_selectedproductsblock>
</blocks>
</global>
<frontend>
<layout>
<updates>
<speroteck_selectedproductsblock>
<file>speroteck/selectedproductsblock.xml</file>
</speroteck_selectedproductsblock>
</updates>
</layout>
</frontend>
</config>
app/code/community/Speroteck/SelectedProductsBlock/etc/widget.xml
<?xml version="1.0"?>
<widgets>
<Speroteck_SelectedProductsBlock type="speroteck_selectedproductsblock/list" module="speroteck_selectedproductsblock">
<name>Display selected products</name>
<description>Display list of selected products</description>
<parameters>
<block_name translate="label">
<label>Block Name</label>
<type>text</type>
<required>1</required>
<visible >1</visible>
</block_name>
<template translate="label">
<label>Frontend Template</label>
<visible>1</visible>
<required>1</required>
<type>select</type>
<values>
<grid translate="label">
<value>speroteck/selectedproductsblock/default.phtml</value>
<label>Default template</label>
</grid>
</values>
</template>
<products_limit translate="label">
<label>Products Limit</label>
<type>text</type>
<required>1</required>
<visible >1</visible>
<value>4</value>
</products_limit>
<selected_products>
<label>Product sku's</label>
<description>Product sku's separated by comma</description>
<type>textarea</type>
<required>1</required>
<visible >1</visible>
</selected_products>
</parameters>
</Speroteck_SelectedProductsBlock>
</widgets>
app/code/community/Speroteck/SelectedProductsBlock/Helper/Data.php
<?php
class Speroteck_SelectedProductsBlock_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Please suggest me how can I implement a multiple product chooser in my plugin.
Thanks
I'm a Magento newbie, and I'm trying to separate my cart link from the other links in the navigation bar.
I did these steps:
1)Configured a new module under etc/modules
<?xml version="1.0"?>
<config>
<modules>
<Marco_TopRightLinks>
<active>true</active>
<codePool>local</codePool>
</Marco_TopRightLinks>
</modules>
</config>
2)added in app/code/local/Marco/TopRightLinks/Block
the Links.php file, with these contents:
class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links
{
protected function _construct()
{
$this->setTemplate('page/template/logged-links.phtml');
}
}
3)added in app/code/local/Marco/TopRightLinks/etc
the config.xml file, with these contents:
<config>
<modules>
<Marco_TopRightLinks>
<version>0.1.0</version>
</Marco_TopRightLinks>
</modules>
<global>
<blocks>
<topright>
<class>Marco_TopRightLinks_Block</class>
</topright>
</blocks>
</global>
</config>
4)Changed page.xml from this:
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
to this:
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="topright/links" name="top.right_links" as="topRightLinks"/>
5) changed checkout.xml from this:
to this:
<!-- Mage_Checkout -->
<reference name="top.right_links">
<block type="topright/links" name="checkout_cart_link">
<action method="addCartLink"></action>
<!--<action method="addCheckoutLink"></action>-->
</block>
</reference>
added under [my_template]/page/template
the right-links.phtml file
This results in a Magento exception:
Invalid method Marco_TopRightLinks_Block_Links::removeLinkByUrl(Array
(
[0] => http://mysitecom/checkout/cart/
)
Can you help me in understanding what's happening and what i could do? (i don't want to touch any innter magento methods, I'm sure the addCartLink works very well as it is :D) my goal is simply to move the cart link in another place into my html
EDIT:
if, instead of extending Mage_Checkout_Block_Links
class Marco_TopRightLinks_Block_Links extends Mage_Checkout_Block_Links
I extend Mage_Page_Block_Template_Links
class Marco_TopRightLinks_Block_Links extends Mage_Page_Block_Template_Links
the exception changes in
Invalid method Marco_TopRightLinks_Block_Links::addCartLink
Try replacing topright to toprightlinks in the cinnfig .xml
<config>
<modules>
<Marco_TopRightLinks>
<version>0.1.0</version>
</Marco_TopRightLinks>
</modules>
<global>
<blocks>
<toprightlinks>
<class>Marco_TopRightLinks_Block</class>
</toprightlinks>
</blocks>
</global>
</config>
here i am giving you idea to change template from one to another with your custom block also
you can add your block via the layout system (which is how the normal content is added as well)?
Define a layout XML file for your module if you haven't already:
<frontend>
<layout>
<updates>
<your_module module="Your_Module">
<file>your/module.xml</file>
</your_module>
</updates>
</layout>
</frontend>
Use your layout file (app/design/frontend/base/default/layout/your/module.xml) to add a block to the and layout update handles. Example:
<?xml version="1.0"?>
<layout>
<a_handle_for_you>
<reference name="content">
<block type="core/text" name="yourblock">
<action method="setText">
<arg>You should see this text.</arg>
</action>
</block>
</reference>
</a_handle_for_you>
<checkout_onepage_success>
<update handle="a_handle_for_you" />
</checkout_onepage_success>
<checkout_multishipping_success>
<update handle="a_handle_for_you" />
</checkout_multishipping_success>
</layout>
you can also refer Magento Knowledge Base. to get deep idea to solve your problem
The error was that in checkout.xml I shouldn't replace the block type. Magento should use its own. I should only change the block type in page.xml, so the container is changing, while the content is remaining the same
I don't know why my block isn't showing up. It's not showing up on any page, and I cleared the cache. Can someone help me figure out what I missed? However, the var_dump('test') shows up!
app/design/frontend/default/default/template/justin/head.phtml
testing this block
Justin/Bieber/Block/Sings.php
class Justin_Bieber_Block_Sings extends Mage_Core_Block_Template
{
protected function _construct()
{
parent::_construct();
var_dump("test");
}
}
config.xml
<frontend>
...
<layout>
<updates>
<bieber>
<file>justin.xml</file>
</bieber>
</updates>
</layout>
</frontend>
<global>
<blocks>
<bieber>
<class>Justin_Bieber_Block</class>
</bieber>
</blocks>
...
</global>
app/design/frontend/default/default/layout/justin.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/bieber" name="justin_bieber">
<action method="setTemplate">
<template>justin/head.phtml</template>
</action>
</block>
</reference>
</default>
</layout>
In your justin.xml block type should be
<block type="bieber/sings" name="justin_bieber">
In this case "bieber" is your module alias name and "sings" is class name.
Your code seems fine to me.
Regarding justin.xml try to change it to the following:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="head">
<block type="bieber/sings" name="justin_bieber" as="justin_bieber" template="justin/head.phtml" />
</reference>
</default>
</layout>
Let me know if that works!
Symlinks were the problem. Magento won't be able to grab the file if it is in a symlinked directory.
Turn it on!
Magento/Zend not allowing symbolic links
Another thing is to turn on template hints!
Ok so I've setup a new module to override the Contacts controller so that I can add a newsletter sign up option to it. My setup is as follows:
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_Contacts_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
error_log('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<mynamespace_ContactsPlus>
<version>0.1.0</version>
</mynamespace_ContactsPlus>
</modules>
<global>
<rewrite>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/index/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
<mynamespace_contactsplus_contacts_index>
<from><![CDATA[#^/contacts/#]]></from>
<to>/contactsplus/contacts_index/</to>
</mynamespace_contactsplus_contacts_index>
</rewrite>
</global>
<frontend>
<routers>
<mynamespace_contactsplus>
<use>standard</use>
<args>
<module>mynamespace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</mynamespace_contactsplus>
</routers>
</frontend>
</config>
/app/etc/modules/MyNamespace_All.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNamespace_ContactsPlus>
</modules>
</config>
THe module appears in the admin modules list and it has produced the following error on my /contacts/ page:
Fatal error: Call to a member function setFormAction() on a non-object in /srv/www/foo.com/app/code/core/Mage/Contacts/controllers/IndexController.php on line 54
That's this line:
$this->getLayout()->getBlock('contactForm')->setFormAction( Mage::getUrl('*/*/post') );
I'm not sure where to go from here though, a guess is that it can't set the form action on whatever is being returned from Mage::getUrl('//post') but I'm clutching at straws tbh.
Any help of advice would be greatly appreciated!
Ok after much research, help and general frustration here is how I got it working:
First up, my module directory is set out as follows (note the caps on the directories):
/app/code/local/MyNamespace/ContactsPlus/etc/
config.xml
/app/code/local/MyNamespace/ContactsPlus/controllers/
IndexController.php
/app/code/local/MyNamespace/ContactsPlus/Helper/
Data.php
Now for the config files:
/app/code/local/MyNamespace/ContactsPlus/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<version>0.1.0</version>
</MyNameSpace_ContactsPlus>
</modules>
<frontend>
<routers>
<!-- Creates route to my module via /contactsplus/ - I used this for testing -->
<contactsplus>
<use>standard</use>
<args>
<module>MyNameSpace_ContactsPlus</module>
<frontName>contactsplus</frontName>
</args>
</contactsplus>
<!-- Sets Mage_Contacts route to MyNameSpace_ContactsPlus -->
<contacts>
<args>
<modules>
<MyNameSpace_ContactsPlus before="Mage_Contacts">MyNameSpace_ContactsPlus</MyNameSpace_ContactsPlus>
</modules>
</args>
</contacts>
</routers>
<!-- Sets layout config file (essential for this to work) -->
<layout>
<updates>
<contactsplus>
<file>contactsplus.xml</file>
</contactsplus>
</updates>
</layout>
</frontend>
<global>
<!-- Sets a helper class for the module, when overriding contacts this is also essential. -->
<helpers>
<contactsplus>
<class>MyNameSpace_ContactsPlus_Helper</class>
</contactsplus>
</helpers>
</global>
</config>
/app/code/local/MyNamespace/ContactsPlus/controllers/Contacts/IndexController.php:
<?php
# Controllers are not autoloaded so we will have to do it manually:
require_once 'Mage/Contacts/controllers/IndexController.php';
class MyNameSpace_ContactsPlus_IndexController extends Mage_Contacts_IndexController
{
# Overloaded indexAction
public function indexAction() {
# Just to make sure
//die('Yes, I did it!');
parent::indexAction();
}
}
/app/code/local/MyNamespace/ContactsPlus/Helper/Data.php:
<?php
class MyNameSpace_ContactsPlus_Helper_Data extends Mage_Core_Helper_Abstract
{
}
/app/etc/modules/MyNamespace_ContactsPlus.xml:
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_ContactsPlus>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_ContactsPlus>
</modules>
</config>
/app/design/frontend/mythemepackage/mytheme/layout/contacts.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contacts_index_index translate="label">
<!-- had to comment this out in order to prevent a duplicate form issue, if anyone has a better method for this then I'd love to here it :)
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contacts"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contacts/form.phtml"/>
</reference>
-->
</contacts_index_index>
<!-- added this to rewrite contacts handle to the new modules handle -->
<contacts_index_index>
<update handle="contactsplus_index_index"/>
</contacts_index_index>
</layout>
/app/design/frontend/mythemepackage/mytheme/layout/contactsplus.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="footer_links">
<!-- <action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled"><label>Contact Us</label><url>contacts</url><title>Contact Us</title><prepare>true</prepare></action>
--></reference>
</default>
<contactsplus_index_index translate="label">
<label>Contact Us Form</label>
<reference name="head">
<action method="setTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/2columns-right.phtml</template></action>
<action method="setHeaderTitle" translate="title" module="contactsplus"><title>Contact Us</title></action>
</reference>
<reference name="content">
<block type="core/template" name="contactForm" template="contactsplus/custom_form.phtml"/>
</reference>
</contactsplus_index_index>
</layout>
I also made a copy of /app/design/frontend/mythemepackage/mytheme/template/contacts/form.phtml and placed it in /app/design/frontend/mythemepackage/mytheme/template/contactsplus/ and then modified it to suit my requirements.
Resources I found particularly useful during this process were google, IRC #magento and
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table
http://alanstorm.com
Hope this helps someone else at some point.
Now it's onto adding a newsletter sign up option to my new form!
I'm having a problem with a custom module. The layout update doesn't work.
Here is the module's config.xml file:
<?xml version="1.0"?>
<config>
<modules>
<Pesach_Categories>
<version>1.0.0</version>
</Pesach_Categories>
</modules>
<frontend>
<layout>
<updates>
<categories>
<file>footer.xml</file>
</categories>
</updates>
</layout>
</frontend>
</config>
Here is the code in the app/design/frontend/default/MyTheme/layout/footer.xml file:
<?xml version="1.0"?>
<layout version="0.0.1">
<default>
<reference name="footer">
<block type="catalog/navigation" name="catList" template="catalog/categories/cat.phtml"/>
</reference>
</default>
</layout>
And here is the code for app/design/frontend/default/MyTheme/template/catalog/categories/cat.phtml:
<?php foreach ($this->getStoreCategories() as $_category): ?>
<div class="Cen_Wrapper1">
<span class="BreadCrumbsred">
<?php echo $_category->getName(); ?></span><br/>
<?php $_children = $_category->getChildren(); ?>
<?php if($_children->count()) : ?>
<?php foreach($_children as $_child) : ?>
<?php echo $_child->getName(); ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php endforeach ?>
The layout updates seem to be coming in (they show up in CommerceBug page layout XML) but they don't seem to do anything.
Here is the following things that i checked:
The file permissions to the app/design/.../MyTheme/template is rwx r-x r-x
The file permissions to the app/design/.../base/default is rwx r-x r-x
The issue is not limited to the custom module...there is another module (FME_Shop_by_manufacturers) that tries to make layout updates to the head and it also doesn't work.
Try to put your phtml to base/default.
The thing is that you should your template in the same theme what is currently set for you shop. You can check your current theme in
System-Configuration-Design-Theme tab.
UPDATE 1
If module is enabled?
Check magento log file.
Try to install your module on clean magento installation. Perhaps core is corrupted.
Check if some modules doesn't overwrite catalog/navigation
Also try in this way:
<?xml version="1.0"?>
<layout version="0.0.1">
<default>
<reference name="footer">
<block type="catalog/navigation" name="catList" output="toHtml" template="catalog/categories/cat.phtml"/>
</reference>
</default>
</layout>
OR in footer.phtml insert
$this->getChildHtml('catList');