Magento: how to include a .phtml from one module in another - magento

I have two modules installed.
One module (module1) that was developed for onepage checkout and it is working fine. It replaces available.phtml with some new shipping methods etc.
I want to include this available in a new cashier (module2) that is not based on the onepage checkout. So I tried doing this:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>
It successfully includes the available.phtml. However, available.phtml does not behave as it should.
The first line in available.phtml is:
<?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
<p><?php echo Mage::helper('unifaun')->__('No shipping methods that suit your order were found. Please contact customer service.') ?></p>
<?php else: ?>
etc...
The problem is that I don't get any shipping rates etc as I do in onepage checkout. I have also manually entered the following:
<?php
$country = Mage::getStoreConfig('shipping/origin/country_id');
$postcode = Mage::getStoreConfig('shipping/origin/postcode');
$city = Mage::getStoreConfig('shipping/origin/city');
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setCollectShippingRates(true);
?>
So my question is what I need to do to make the following line work correctly so that the code actually gets the availaable shipping methods etc..., as it does when the module is included in onepage checkout.
$_shippingRateGroups = $this->getShippingRates()
I'm not sure if this is enough information to solve this problem, but I thought I make it a try and post it and see if anyone know what I'm doing wrong. :)
Cheers!

You are including a basic block of type core/template, all blocks are based of that.
So in your context there is no method getShippingRates for it to find.
So change the following to something like:
<?php echo $this->getLayout()->createBlock('unifaun_onepage/the_block_name')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>
Where the_block_name is the folder in the modules block, eg /Block/The/Block/Name.php

Related

Magento product overview and detail separated view

I want to handle the product overivew separataly to the product detail view. I want to add additional text right behind the price in the product deatil view.
I tried to edit the view.phtml in path app/design/frontend/mytheme/default/template/catalog/product/view.phtml, refreshed caches and so on, but nothing changed.
In catalog.xml view.phtml will be load. So its seems correct.
But even when I try to echo "test" it doesnt show anything.
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<div class="std"><h2><?php echo $this->__('Details:') ?></h2>
</div>
</div>
<?php echo "test";
endif;?>
Do you have any hint?
Regards
Matt
You should enable template path hints in the backend to check which template file is used to render product page. Make sure that the cache is also disabled.

Can I have more than one success (onepage) page in magento

Can I have more than one success (onepage) page in magento. One for Cash on delivery and another for Online Bank transfer.
thanks in advance.....
Just modify the template file for checkout success page (checkout/success.phtml) to display what you want it to for each method used. You have access to the order object in the template and can do everything there. If you need additional functionality just extend the checkout success block and use the new functions in the template. Absolutely no need to create a new success page and if you did you would need to extend the checkout controller which could cause you problems down the line with upgrades etc.
<?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId()); ?>
<?php if ($order->getPayment()->getMethod() == "checkmo"): ?>
<p>Check or Money Order HTML</p>
<?php else if ($order->getPayment()->getMethod() == "bank_transfer"): ?>
<p>Bank Transfer HTML</p>
<?php endif; ?>
See this article by fontis for more information: http://www.fontis.com.au/blog/magento/customise-magento-checkout-success-page-based-payment-type

How do I manually theme Views in Drupal 7?

I am new to drupal and I am trying to figure out how to theme Views. I currently have a content type called Category with the following fields:Title, Image and Body. I created a view for the above mentioned content type so that I would list view of all the categories I have created.
To custom theme the view I created a folder called views in my theme folder, and created the following view files:
views-view-fields--plugin-categories.tpl.php
views-view--plugin-categories.tpl.php
views-view-unformatted--plugin-categories.tpl.php
This is what I currently have in my first file:
<div class="<?php print $classes; ?>">
<?php if ($rows): ?>
<div class="view-content">
<?php print $rows; ?>
</div>
<?php elseif ($empty): ?>
<div class="view-empty">
<?php print $empty; ?>
</div>
<?php endif; ?>
<?php if ($more): ?>
<?php print $more; ?>
<?php endif; ?>
</div><?php /* class view */ ?>
Instead of $rows, I tired to use print $field['image'] and print $field['body'] but this method does seem to work. Could you kindly advise on how I could theme the three fields, within categories, displayed using view?
You should name your template like this
views-view-fields--<machine-name-of-your-view>.tpl.php
So I'm assuming from the above that your view is called 'plugin-categories'. An easy way to check is to go to edit the view and look at the URL while you're on the edit page. It should have the format /admin/structure/views/view/YOUR-VIEW'S-MACHINE-NAME/edit, so you can get it from there.
Once you're sure it has the right name, clear your cache to make sure Drupal is picking up your new template. You just need the one above, not all three to modify the output of the three fields in question.
Once you've cleared cache, Drupal should be picking up the new template. You didn't mention exactly what isn't working, just that it's not working, so I wanted to cover the naming and caching, just in case. Now, to output particular fields in this view template, call them like this:
$fields['your-field-machine-name']
So $fields['body'] (I think you're missing an 's')
You should have nothing about $rows in this template! If you have anything about $rows, you haven't copied and pasted from the correct views template. Simply output the fields as you want them to appear in your view, in whatever order you want with the syntax above and put in whatever css classes, etc you want.
Let us know if that works!

How to not have the Welcome Message cached in Magento

I'm trying to not have my "Welcome Message" on Magento Cart header cached by my full page cache module. Everything I've tried has led to complete failure. There has to be a way.
I'm using Magentos persistent cart option and I've discovered there is some difference in the welcome message with this option that the module developers may not have accounted for. Don't know really.
It's kind of like the "welcome message is it own module but in another way it's not, It's kind of a php one line on the header page.
Now my fpc module has an option in administration to exclude modules from being cached but you have to give the modules "name" You know i.e. name="some_name". The welcome message isn't like the rest of the other modules that I can tell. Here is the php in the header:
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
There is nothing in the parentheses, so I've been trying to give this welcome message a name. I don't know how else to do it.
So I created a static block in adminisration with this in it:
{{block type="core/template" name"header.welcome" as="welcome" template="page/html/welcome.phtml"}}
Then I created a phtml file called welcome.phtml with this in it:
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
Then in the header I added this:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('welcome')->toHTML(); ?>
That usually works with about anything. But not this time. Nothing. So under the block page/html_header I added this to page.xml:
<block type="core/template" name="header.welcome" as="welcome"/>
This is mt latest attempt. Does anyone have any ideas about how to go about this? I like the welcome message being dynamic.
thanks
The welcome message is just a function of the header block. Lesti_Fpc needs the welcome message in a seperated block. In Magento 1.8 this is solved and the name of the block is welcome. In Magento 1.7 there is a semi-solution in core...
This issue is solved here: (source)
https://gordonlesti.com/lestifpc-magento-1-7-and-the-welcome-message/
I think I have made some progress for this problem. However I am not getting the solution. What I have done is created a new block in the app/design/frontend/default/layout/page.xml file.
I have added this:
<block type="page/html_welcome" name="testwelcome" as="testwelcome"/>
There seems to be a built in core function called "welcome". It can be viewed at app/code/core/Mage/Page/Block/Html/Welcome.php. So That is the reference in the page.xml file.
Then in the header.phtml file in app/design/frontend/default/template/page.html I placed a call for:
<?php echo $this->getChildHtml('testwelcome') ?>
And finally I created a new template file called testwelcome.phtml in app/design/frontend/default/template with the following code:
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
I can get the welcome message to display, but I can't seem to get it to render any changes.

Magento - showing review links & add-to-compare links on custom pages

I have a custom page as my magento homepage. It's content is hardcoded on the default CMS page (which shows if a CMS homepage isn't enabled in the CMS pages section of the admin).
I have a list of products showing there (pulled from best-selling/highest rated etc). However, the review links and the add-to-compare links don't show on this page. The list of products is displayed using the same code as the default template/catalog/product/list.phtml, and everything else works except for these 2 things.
It seems that both the following code snippets have no effect on pages other than the default category listing page:
<?php $_compareUrl=$this->getAddToCompareUrl($_product); ?>
&
<?php echo $this->getReviewsUrl() ?>
I'm guessing that there's something else that needs to be called in order for these to work, but can't figure out what it is. Everything else from the product collection is available.
I load my product collection using the following code:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
$_productCollection->load();
Any ideas?
OK, so after a while digging around, I found that you can use the following to get the compare url working:
<?php $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ?>
<span class="addto">
<?php echo $this->__('Add to Compare') ?>
</span>
Still not sure about the review urls, but I've made an acceptable workaround for that so I'm gonna mark this as answered.
If anyone comes up with an answer though please do still post it!
I'm guessing it's because the Block that is serving up your product list may not be correct. I believe it should be Mage_Catalog_Block_Catalog_Product_List. How exactly are you loading in the list of products?

Resources