How I take the shipping method output in totals frame in Magento - magento

The Magento checkout has a line that show the totals in the file:
frontend/base/default/template/checkout/onepage/review/info.phtml
<?php echo $this->getChildHtml('totals'); ?>
But this line shows also the shipping method if customer choose a freight method and I didn't find this to take it of my total page, I know that I can't delete it from the database because this information is used in the freight choice.

For removing this data from the total you need to override the following classes:
To hide it in shopping cart page:
Mage_Sales_Model_Quote_Address_Total_Shipping::fetch() method needs to be overridden via custom module:
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
$originalShippingDescription = $address->getShippingDescription(); // Keep old description value
$address->unsShippingDescription(); // Removes description of shipping method
parent::fetch($address);
$address->setShippingDescription($originalShippingDescription); // Sets back original description of shipping method
return $this;
}
To hide it on order overview pages in the user account, you need to perform another customization of Mage_Sales_Block_Order_Totals class. For this purpose you need to create a new block extended from Mage_Core_Block_Abstract
Create block in some your custom module
<?php
class Custom_Module_Block_Shipping_Total extents Mage_Core_Block_Abstract
{
public function initTotals()
{
if ($this->getParentBlock() && $this->getParentBlock()->getTotal('shipping')) {
$this->getParentBlock()->getTotal('shipping')->setLabel($this->__('Shipping & Handling'));
}
}
}
Add layout updates to include you block into order view.
<layout>
<!-- Your custom total on invoices view -->
<custom_invoice_totals>
<reference name="invoice_totals">
<block name="custom_total" type="custom_module/shipping_total" />
</reference>
</custom_invoice_totals>
<!-- Your custom total on shipments view -->
<custom_shipment_totals>
<reference name="shipment_totals">
<block name="custom_total" type="custom_module/shipping_total" />
</reference>
</custom_shipment_totals>
<!-- Your custom total on creditmemos view -->
<custom_creditmemo_totals>
<reference name="creditmemo_items">
<block name="custom_total" type="custom_module/shipping_total" />
</reference>
</custom_creditmemo_totals>
<!-- Applying your handles to particular pages in customer account -->
<sales_order_view>
<update handle="custom_order_totals" />
</sales_order_view>
<sales_order_print>
<update handle="custom_order_totals" />
</sales_order_print>
<sales_email_order_items>
<update handle="custom_order_totals" />
</sales_email_order_items>
<!-- applies your total in email -->
<sales_email_order_items>
<update handle="custom_order_totals" />
</sales_email_order_items>
<sales_guest_view>
<update handle="custom_order_totals" />
</sales_guest_view>
<!-- invoice pages -->
<sales_order_invoice>
<update handle="custom_invoice_totals" />
</sales_order_invoice>
<sales_order_printinvoice>
<update handle="custom_invoice_totals" />
</sales_order_printinvoice>
<sales_email_order_invoice_items>
<update handle="custom_invoice_totals" />
</sales_email_order_invoice_items>
<sales_guest_invoice>
<update handle="custom_invoice_totals" />
</sales_guest_invoice>
<!-- shipment pages -->
<sales_order_shipment>
<update handle="custom_shipment_totals" />
</sales_order_shipment>
<sales_order_printshipment>
<update handle="custom_shipment_totals" />
</sales_order_printshipment>
<sales_email_order_shipment_items>
<update handle="custom_shipment_totals" />
</sales_email_order_shipment_items>
<sales_guest_shipment>
<update handle="custom_shipment_totals" />
</sales_guest_shipment>
<!-- creditmemo pages -->
<sales_order_creditmemo>
<update handle="custom_creditmemo_totals" />
</sales_order_creditmemo>
<sales_order_printcreditmemo>
<update handle="custom_creditmemo_totals" />
</sales_order_printcreditmemo>
<sales_email_order_creditmemo_items>
<update handle="custom_creditmemo_totals" />
</sales_email_order_creditmemo_items>
<sales_guest_creditmemo>
<update handle="custom_creditmemo_totals" />
</sales_guest_creditmemo>
</layout>
After such customization on all pages on the frontend your shipping total will be without information about shipping method...

in your local cart.phtml, use following snippet:
<div class="cart-totals-wrapper">
<div class="cart-totals">
<div class="cart-totals-container">
<!-- <?php echo $this->getChildHtml('totals'); ?> -->
<?php
$_quote = Mage::getSingleton('checkout/session')->getQuote();
$_cartValue = 0;
$_items = $_quote->getAllItems();
foreach ($_items as $_item) {
$_cartValue += $_item->getRowTotalInclTax();
}
?>
<table id="shopping-cart-totals-table">
<colgroup>
<col>
<col width="1">
</colgroup>
<tbody>
<tr>
<td class="a-right" colspan="1" style=""><?php echo $this->__('Subtotal'); ?></td>
<td class="a-right" style="">
<span class="price"><?php echo $_quote->getStore()->formatPrice($_cartValue); ?></span>
</td>
</tr>
</table>
<p class="message"><?php echo $this->__('Shipping will be calculated at checkout'); ?></p>
</div>

Related

Magento Call custom block inside another custom block

I am new to magento, so please forgive me if I have asked anything wrong. I have created a custom module for instagram Login, I just want to call a particular block from that instagram module to another layout file. I have called that block printed in my view page using
<?php echo $this->getChildHtml('media_new'); ?>
My block got called but functionalities are working and form is not submitting.
My custom module layout file. Instagram.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<instagram_index_instagram_signup>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<reference name="content">
<block type="core/template" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block>
</reference>
</instagram_index_instagram_signup>
</layout>
I want to call the above block to another module layout file:
My another module layout page:
<marketplace_vendor_login>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<remove name="right"/>
<remove name="left"/>
<reference name="before_body_end">
<block type="facebookfree/init" name="belvg_facebookfree_block">
<action method="setTemplate" ifconfig="facebookfree/settings/enabled" ifvalue="1">
<template>belvg/facebookfree/block.phtml</template>
</action>
</block>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="marketplace/vendor_login" name="customer_form_login" template="nbmpmarketplace/login.phtml" >
<block type="facebookfree/links_button" name="belvg_facebookfree_button" template="belvg/facebookfree/form/button.phtml" />
<block type="core/template" name="instagram.signup" as="media_new" template="instagramlogin/Instagram_signup.phtml"></block>
</block>
</reference>
</marketplace_vendor_login>
Here I have called my custom block, then printed in my view page as:
<?php echo $this->getChildHtml('media_new'); ?>
My controller code for instagram:
class Blazedream_Instagram_IndexController extends Mage_Core_Controller_Front_Action
{
public function instagram_signupAction()
{
if ($this->getRequest()->isPost()){
if($this->getRequest()->getPost('instagram-email')){
$instagram_email = $this->getRequest()->getPost('instagram-email');
$customer_model = Mage::getModel('instagram/instagram');
$site_customer = $customer_model->checkCustomer($instagram_email);
if($site_customer){
$instagram_customer = Mage::getModel('instagram/instagram')->getCollection()
->addFieldToFilter('customer_id', array('eq' => $site_customer));
if(count($instagram_customer)==1){
Mage::getSingleton('core/session')->setInstagramEmail($instagram_email);
$this->_redirect('instagram/index');
}else{
Mage::getSingleton('customer/session')->addError('Email Id Already Registered.');
$this->_redirect('sellerlogin');
}
}else{
Mage::getSingleton('core/session')->setInstagramEmail($instagram_email);
$this->_redirect('instagram/index');
}
}
}
$this->loadLayout();
$this->getLayout()->getBlock('instagram.signup');
$this->renderLayout();
}
}
It is not coming into this controller function, That i have used for instagram module.
My view page: instagramlogin.phtml
<div style="display: none">
<style type="text/css">
#cboxContent.newsletterbox {
<?php if($backgroundImage){?> background-image: url(<?php echo Mage::getBaseUrl('media').'/wysiwyg/magenthemes/newsletter/'.$backgroundImage;?>);
<?php }?> background-position: left top;
background-repeat: no-repeat;
background-color: <?php echo $backgroundColor;?>;
}
</style>
<div id="mt_instagram" class="block block-subscribe">
<div class="row">
<div class="left-newletters col-lg-8 col-md-8 col-sm-8 col-xs-8">
<div class="block-title">
<strong><span><?php echo $this->__('Join our Mail List Through Instagram!') ?></span></strong>
</div>
<div class="row-none">
<div class="popup_message">
<div class="intro">
<?php echo $desc; ?>
</div>
<form action="<?php echo Mage::getBaseUrl().'instagram/index/instagram_signup'; ?>" method="post" id="instagram-validate-detail">
<div class="block-content">
<div class="input-box">
<input name="instagram-email" type="text" id="mt-newsletter" placeholder="Enter your email id"
value="" class="input-text required-entry validate-email"/>
<div class="actions">
<button type="submit" title="<?php echo $this->__('Subscribe') ?>"
class="button">
<span><span><?php echo $this->__('Subscribe') ?></span></span></button>
</div>
</div>
</div>
</form>
</div>
</div>
I am getting my custom form also..But the controller is not getting called and functionalists are not working, only I am getting the form.
Can anyone help Me?
This is my first ever answer on stackoverflow, I will try my best to explain.
To start with, let me brief you about the block calls in Magento; any particular type of Block(.php files in Block folder) has a corresponding content/template (.phtml in template folder) file to render the data fetched from Model (.php in Model folder).
In your layout (.xml for your module in layout folder), you have added a block that is of type (core/template) so it will call the file Mage_Core_Block_Template.php and can access all its methods. However, if you want to create a custom block you can update layout (instagram module) file like this.
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<instagram_index_instagram_signup>
<reference name="head">
<action method="addJs"><script>magenthemes/jquery/plugins/jquery.cookie.js</script></action>
</reference>
<reference name="content">
<block type="instagram/instagram" name="instagram.signup" template="instagramlogin/Instagram_signup.phtml"></block>
</reference>
</instagram_index_instagram_signup>
</layout>
And create a file in Block folder with name Blazedream_Instagram_Block_Instagram.php and then you will be able to call custom methods to the block template.
Ex.-
class Blazedream_Instagram_Block_Instagram extends Mage_Core_Block_Template
{
public function customMethod()
{
$response = array('a', 'b', 'c');
$this->getResponse()->setHeader('Content-type','application/json', true);
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
return;
}
}
Update you controller action call to
$this->loadLayout();
$this->renderLayout();
Now, to add this block inside another custom module, update its layout like
<fname_controller_action>
//path controller path on which you want to add/update the block
<update handle="my_custom_handle" />
</fname_controller_action>
<my_custom_handle>
<reference name="content">
<reference name="where_you_want_to_add">
<block type="instagram/instagram" name="my.custom.block" as="instagram.signup" template="template_path/instagram.phtml"/>
</reference>
</reference>
</my_custom_handle>
or add a constructor inside the block file Blazedream_Instagram_Block_Instagram.php like -
public function __construct()
{
parent::__construct();
$this->setTemplate('template/instagram.phtml');
}
and call the block in any template file with the below code
echo $this->getLayout()->createBlock('instagram/instagram')->toHtml();
You might need to update your layout file in this case.
If you do everything correctly, you should be able to call $this->customMethod() in the template file instagram.phtml
Thanks! Pardon me if I could not explained it properly.

Custom currency switcher in Magento header vanished?

I built a custom currency switcher for my header yesterday, all working well. Today I came to setup the catalog pages and found myself needing to remove the standard currency switcher in the left column, I opened up my local.xml and add a remove to currency. Silly choice perhaps, I managed after fiddleing to get the left.currency to be removed when i suddenly noticed something I had done in one of my files had stopped my header custom currency switcher from displaying.
local.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<!-- Remove callouts and rarely used stuff -->
<remove name="right.poll"/>
<remove name="right.permanent.callout"/>
<remove name="left.permanent.callout"/>
<remove name="paypal.partner.right.logo"/>
<remove name="catalog.compare.list" />
<!-- add the local stylesheet -->
<reference name="head">
<action method="addCss"><stylesheet>css/smoothness/jquery-ui-1.10.1.custom.css</stylesheet></action>
<action method="addJs"><script>ahoy/jquery-1.9.1.js</script></action>
<action method="addJs"><script>ahoy/jquery-ui-1.10.1.custom.js</script></action>
<action method="addJs"><script>ahoy/script.js</script></action>
<action method="addCss"><stylesheet>css/1140.css</stylesheet></action>
<action method="addCss"><stylesheet>css/ahoy.css</stylesheet></action>
</reference>
<reference name="header">
<block type="template/currency" name="custom_currency_selector" template="currency/currency.phtml"/>
</reference>
</default>
<catalog_category_view>
<reference name="root">
<action method="setTemplate"><template>page/2columns-left.phtml</template></action>
</reference>
</catalog_category_view>
First part of header.phtml
<div class="header">
<div class="row">
<div class="row">
<div class="sixcol">
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('custom_currency_selector') ?>
</div>
<div class="sixcol last">
<div class="row">
test/default/template/currency/currency.phtml
<?php if($this->getCurrencyCount() > 1): ?>
<div class="currency-block">
<ul>
<?php foreach ($this->getCurrencies() as $_code => $_name): ?>
<?php $active = ($_code==$this->getCurrentCurrencyCode()) ? "active":""; ?>
<li>
<a class="<?php echo $active; ?>" href="<?php echo $this->getSwitchCurrencyUrl() . "currency/" . $_code; ?>" title="Set <?php echo $_code; ?> as your chosen currency">
<?php echo Mage::app()->getLocale()->currency($_code)->getSymbol(); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
From what I remember this is all I need to create the block, assign its position and call it out. I've been clearing the cache constantly while fiddeling, I reloaded in the currency conversion data, removed and retested the "remove" in local that removed the left bars currency, that one has now come back after i removed the remove for left.currency but the top one never came back.
These are my current files, so no removes at all for currency now, I'm not sure when this vanished but I've only been playing with the left sidebar stuff, after css struggles i tried to remove the currency and as i did not know how to reference it tried killing off all currency i could find and when i twigged i was no longer sure when i removed the top currency.
Try changing type="template/currency" to type="directory/currency"

Moving Magento Advanced Search Link From Footer To Beneath Search Bar

I'm trying to move magentos advanced search link from the footer links right beneath the search bar.
I know that the origins of the link are in layout/catalogsearch.xml under
reference name="footer_links" and appear in the footer because of getChildHtml('footer_links') in footer.phtml
And i know that the search bar originates from template/catalogsearch/form.mini.phtml and appears though catalogsearch.xml under reference name="top.menu"
Any ideas on how to proceed here?
thank you for the quick answer!
But it is not exactly what I was looking for as it would display the entire footer links block beneath the searchbar.
Nevertheless thank you for showing me the method you used for that!
Anyways, I figured out a solution on my own:
I modified catalogsearch.xml:
<default>
<reference name="top.menu">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
<!-- add a new reference to top.search including my new adv.search block -->
<reference name="top.search">
<block type="page/template_links" name="adv.search" as="adv.search" >
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</block>
</reference>
<!-- the reference to the footer i commented out as its not longer needed; it includes advanced search and popular search terms-->
</default>
In form.mini.phtml I added a new div that calls adv.search:
</script>
<div class="adv-search"> <?php echo $this->getChildHtml('adv.search') ?> </div>
</div>
And last, in styles.css, I added some code to controll the looks of that div:
.adv-search {width:100px; height:15px; margin-top:24px; margin-left: 120px;}
.adv-search a { color:#fff; font-weight:bold; }
any additional advice is more than welcome
Cheers!
In order for this to work, you must:
1) Update your app/design/frontend/[yourtheme]/default/layout/local.xml file
2) Call the new blocks in app/design/frontend/[yourtheme]/default/template/page/html/header.phtml - this is needed because header.phtml is not a "core/text_list" block type which automatically renders its nested blocks. So we must explicitly tell Magento to render those child blocks
Your app/design/frontend/[yourtheme]/default/layout/local.xml should contain this:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<!-- Insert cms links. No need to use <action method="insert"> as this block is not used elsewhere in layout -->
<block type="cms/block" name="top_links_cms" as="top_links_cms" before="top_links_other">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
<!-- Insert former footer links. -->
<action method="insert">
<!-- We must keep block name "footer_links" as it is used as a reference for adding links by other modules -->
<blockName>footer_links</blockName>
<!-- Name of the block we want to have as sibling (in order to get its position and place our block after it. See next node <after> -->
<siblingName>topSearch</siblingName>
<!-- $after param from Mage_Core_Block_Abstract::insert() is a boolean type, so its value in the XML node is [empty], 0 or 1 -->
<after>1</after>
<alias>top_links_other</alias>
</action>
</reference>
<reference name="footer">
<action method="unsetChild"><name>footer_links</name></action>
<action method="unsetChild"><name>cms_footer_links</name></action>
</reference>
</default>
</layout>
This is an updated header.phtml you can get inspiration from for your app/design/frontend/[yourtheme]/default/template/page/html/header.phtml file:
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></h1>
<?php else:?>
<strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
<?php endif?>
<div class="quick-access">
<?php echo $this->getChildHtml('topSearch') ?>
<?php
/**
* Add other top links (footer and cms links)
*/
?>
<?php echo $this->getChildHtml('top_links_cms') ?>
<?php echo $this->getChildHtml('top_links_other') ?>
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>

magento - remove recently added items

I want to remove "Recently added item" in cart sidebar on the front page of Magento. I can remove the following lines from checkout/cart/sidebar.phtml, but is there a less destructive way to do this, in case we want to quickly restore this in the future?
<?php // if(count($_items)): ?>
<!-- <p class="block-subtitle"><?php //echo $this->__('Recently added item(s)') ?></p> -->
<!-- <ol id="cart-sidebar" class="mini-products-list"> -->
<?php // foreach($_items as $_item): ?>
<?php // echo $this->getItemHtml($_item) ?>
<?php // endforeach; ?>
<!-- </ol> -->
<!-- <script type="text/javascript">decorateList('cart-sidebar', 'none-recursive')</script> -->
<?php // else: ?>
<!-- <p class="empty"><?php //echo $this->__('You have no items in your shopping cart.') ?></p> -->
<?php //endif ?>
You simply use following xml layout update in local.xml:
<remove name="cart_sidebar" />
OR
<action method="unsetChild"><name>cart_sidebar</name></action>
Cheers!
You could create a new template file with the new layout you require...
app/design/frontend/your_package/your_theme/template/checkout/cart/sidebar-updated.phtml
Then in your layout xml, you can change swap the sidebar template to the new version...
<default>
<reference name="cart_sidebar">
<action method="setTemplate"><template>checkout/cart/sidebar-updated.phtml</template></action>
</reference>
</default>
Then to revert back at any point, simply remove/comment out this layout xml
Better still, add this to your local.xml
<remove name="left.reports.product.viewed"/>
<remove name="right.reports.product.viewed"/>
To be more explicit it's in /app/design/frontent/default/[[your-theme-name]]/layout/local.xml.
Less intrusive for an easier upgrade path and this answer is an adaptation of the more intrusive solution I saw here.

how to display toplinks at footer in magento?

How can i display below toplinks in footer,
i used below code in Footer.phtml file,
<?php echo $this->getChildHtml('topLinks'); ?>
but the links are not displayed?. How can i do this?
Thanks in advance
footer.phtml
<div class="footer-container">
<div class="footer">
<?php echo $this->getChildHtml() ?>
<?php echo $this->getChildHtml('newsletter') ?>
<?php //echo $this->getLayout()->createBlock('cms/block')->setBlockId('sample_links')->toHtml() ?>
<?php echo $this->getChildHtml('samplelinks') ?>
<?php echo $this->getChildHtml('top.links'); ?>
<p class="bugs"><?php echo $this->__('Help Us to Keep Magento Healthy') ?> - <strong><?php echo $this->__('Report All Bugs') ?></strong> <?php echo $this->__('(ver. %s)', Mage::getVersion()) ?></p>
<address><?php echo $this->getCopyright() ?></address>
</div>
</div>
</div>
Classic learning-to-theme-Magento question!
The relationship of one block to another is most evident in templates (as your current effort demonstrates). The ability for a parent (footer, in your case) to trigger rendering of another block requires that a parent-child relationship be established. This typically happens in layout update XML.
If this relationship were core, it is likely that you would see the following in the base/default theme's layout/page.xml file:
<block type="page/html_footer" name="footer" ...>
<!-- other child block directives -->
<block type="page/template_links" name="top.links" as="topLinks"/>
</block>
In your case, because you are adding a relationship between two existing blocks, you can set up a relationship between block instances in a special end-user layout xml file named local.xml which you should place in your custom theme's layout folder. Here is what it should look like:
<?xml version="1.0"?>
<layout>
<default><!-- effectively: "do this on all pages" -->
<reference name="footer"><!-- parent block -->
<action method="insert"><!-- this PHP class method sets the relationship -->
<block_name_to_insert>top.links</block_name_to_insert><!--use the block name in the layout, not the alias. See Mage_Core_Block_Abstract::insert() -->
<sort_relative_to_other_childname/><!-- empty val is fine here -->
<sort_before_or_after/><!-- not relevant -->
<alias>topLinks</alias><!-- because you are using the original alias, need to re-specify that here -->
</action>
</reference>
</default>
</layout>

Resources